Skip to content

Commit b8f719d

Browse files
Merge branch 'revert-support' of git://github.com/fasttracktool-dev/ruby-git into fasttracktool-dev-revert-support
Conflicts: lib/git/base.rb lib/git/lib.rb tests/units/test_index_ops.rb
2 parents 70a8689 + dcb44d2 commit b8f719d

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

lib/git/base.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ def reset_hard(commitish = nil, opts = {})
280280
self.lib.reset(commitish, opts)
281281
end
282282

283-
284283
# cleans the working directory
285284
#
286285
# options:
@@ -291,6 +290,16 @@ def clean(opts = {})
291290
self.lib.clean(opts)
292291
end
293292

293+
# reverts the working directory to the provided commitish.
294+
# Accepts a range, such as comittish..HEAD
295+
#
296+
# options:
297+
# :no_edit
298+
#
299+
def revert(commitish = nil, opts = {})
300+
self.lib.revert(commitish, opts)
301+
end
302+
294303
# commits all pending changes in the index file to the git repository
295304
#
296305
# options:

lib/git/lib.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,13 @@ def clean(opts = {})
428428

429429
command('clean', arr_opts)
430430
end
431+
432+
def revert(commitish, opts = {})
433+
arr_opts = []
434+
arr_opts << '--no-edit' if opts[:no_edit] || opts[:'no-edit']
435+
arr_opts << commitish
436+
command('revert', arr_opts)
437+
end
431438

432439
def apply(patch_file)
433440
arr_opts = []

tests/units/test_index_ops.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,28 @@ def test_clean
7070
end
7171
end
7272
end
73+
74+
def test_revert
75+
in_temp_dir do |path|
76+
g = Git.clone(@wbare, 'new')
77+
Dir.chdir('new') do
78+
new_file('test-file', 'blahblahbal')
79+
g.add
80+
g.commit("first commit")
81+
first_commit = g.gcommit('HEAD')
82+
83+
new_file('test-file2', 'blablahbla')
84+
g.add
85+
g.commit("second-commit")
86+
second_commit = g.gcommit('HEAD')
87+
88+
commits = g.log(1e4).count
89+
g.revert(first_commit.sha)
90+
assert_equal(commits + 1, g.log(1e4).count)
91+
assert(!File.exists?('test-file2'))
92+
end
93+
end
94+
end
7395

7496
def test_add_array
7597
in_temp_dir do |path|

0 commit comments

Comments
 (0)