File tree 3 files changed +37
-2
lines changed 3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -264,6 +264,13 @@ def reset_hard(commitish = nil, opts = {})
264
264
self . lib . reset ( commitish , opts )
265
265
end
266
266
267
+ # reverts the working directory to the provided commitish.
268
+ # Accepts a range, such as comittish..HEAD
269
+ # Note: automatically adds --no-edit flag.
270
+ def revert ( commitish = nil , opts = { } )
271
+ self . lib . revert ( commitish , opts )
272
+ end
273
+
267
274
# commits all pending changes in the index file to the git repository
268
275
#
269
276
# options:
Original file line number Diff line number Diff line change @@ -429,7 +429,13 @@ def reset(commit, opts = {})
429
429
arr_opts << commit if commit
430
430
command ( 'reset' , arr_opts )
431
431
end
432
-
432
+
433
+ def revert ( commit_or_range , opts = { } )
434
+ arr_opts = [ "--no-edit" ]
435
+ arr_opts << commit_or_range if commit_or_range
436
+ command ( 'revert' , arr_opts )
437
+ end
438
+
433
439
def apply ( patch_file )
434
440
arr_opts = [ ]
435
441
arr_opts << '--' << patch_file if patch_file
Original file line number Diff line number Diff line change @@ -37,7 +37,29 @@ def test_add
37
37
end
38
38
end
39
39
end
40
-
40
+
41
+ def test_revert
42
+ in_temp_dir do |path |
43
+ g = Git . clone ( @wbare , 'new' )
44
+ Dir . chdir ( 'new' ) do
45
+ new_file ( 'test-file' , 'blahblahbal' )
46
+ g . add
47
+ g . commit ( "first commit" )
48
+ first_commit = g . gcommit ( 'HEAD' )
49
+
50
+ new_file ( 'test-file2' , 'blablahbla' )
51
+ g . add
52
+ g . commit ( "second-commit" )
53
+ second_commit = g . gcommit ( 'HEAD' )
54
+
55
+ commits = g . log ( 1e4 ) . count
56
+ g . revert ( first_commit . sha )
57
+ assert_equal ( commits + 1 , g . log ( 1e4 ) . count )
58
+ assert ( !File . exists? ( 'test-file2' ) )
59
+ end
60
+ end
61
+ end
62
+
41
63
def test_add_array
42
64
in_temp_dir do |path |
43
65
g = Git . clone ( @wbare , 'new' )
You can’t perform that action at this time.
0 commit comments