File tree 3 files changed +39
-1
lines changed 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -280,7 +280,6 @@ def reset_hard(commitish = nil, opts = {})
280
280
self . lib . reset ( commitish , opts )
281
281
end
282
282
283
-
284
283
# cleans the working directory
285
284
#
286
285
# options:
@@ -291,6 +290,16 @@ def clean(opts = {})
291
290
self . lib . clean ( opts )
292
291
end
293
292
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
+
294
303
# commits all pending changes in the index file to the git repository
295
304
#
296
305
# options:
Original file line number Diff line number Diff line change @@ -428,6 +428,13 @@ def clean(opts = {})
428
428
429
429
command ( 'clean' , arr_opts )
430
430
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
431
438
432
439
def apply ( patch_file )
433
440
arr_opts = [ ]
Original file line number Diff line number Diff line change @@ -70,6 +70,28 @@ def test_clean
70
70
end
71
71
end
72
72
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
73
95
74
96
def test_add_array
75
97
in_temp_dir do |path |
You can’t perform that action at this time.
0 commit comments