File tree 4 files changed +42
-4
lines changed 4 files changed +42
-4
lines changed Original file line number Diff line number Diff line change @@ -303,9 +303,11 @@ def revert(commitish = nil, opts = {})
303
303
# commits all pending changes in the index file to the git repository
304
304
#
305
305
# options:
306
- # :add_all
306
+ # :all
307
307
# :allow_empty
308
+ # :amend
308
309
# :author
310
+ #
309
311
def commit ( message , opts = { } )
310
312
self . lib . commit ( message , opts )
311
313
end
Original file line number Diff line number Diff line change @@ -407,10 +407,13 @@ def remove(path = '.', opts = {})
407
407
end
408
408
409
409
def commit ( message , opts = { } )
410
- arr_opts = [ '-m' , message ]
411
- arr_opts << '-a' if opts [ :add_all ]
410
+ arr_opts = [ ]
411
+ arr_opts << "--message=#{ message } " if message
412
+ arr_opts << '--amend' << '--no-edit' if opts [ :amend ]
413
+ arr_opts << '--all' if opts [ :add_all ] || opts [ :all ]
412
414
arr_opts << '--allow-empty' if opts [ :allow_empty ]
413
- arr_opts << "--author" << opts [ :author ] if opts [ :author ]
415
+ arr_opts << "--author=#{ opts [ :author ] } " if opts [ :author ]
416
+
414
417
command ( 'commit' , arr_opts )
415
418
end
416
419
Original file line number Diff line number Diff line change @@ -94,6 +94,12 @@ def last
94
94
check_log
95
95
@commits . last rescue nil
96
96
end
97
+
98
+ def []( index )
99
+ check_log
100
+ @commits [ index ] rescue nil
101
+ end
102
+
97
103
98
104
private
99
105
Original file line number Diff line number Diff line change @@ -78,4 +78,31 @@ def test_add
78
78
end
79
79
end
80
80
81
+ def test_commit
82
+ in_temp_dir do |path |
83
+ git = Git . clone ( @wdir , 'test_commit' )
84
+
85
+ create_file ( 'test_commit/test_file_1' , 'content tets_file_1' )
86
+ create_file ( 'test_commit/test_file_2' , 'content test_file_2' )
87
+
88
+ git . add ( 'test_file_1' )
89
+ git . add ( 'test_file_2' )
90
+
91
+ base_commit_id = git . log [ 0 ] . objectish
92
+
93
+ git . commit ( "Test Commit" )
94
+
95
+ original_commit_id = git . log [ 0 ] . objectish
96
+
97
+ create_file ( 'test_commit/test_file_3' , 'content test_file_3' )
98
+
99
+ git . add ( 'test_file_3' )
100
+
101
+ git . commit ( nil , :amend => true )
102
+
103
+ assert ( git . log [ 0 ] . objectish != original_commit_id )
104
+ assert ( git . log [ 1 ] . objectish == base_commit_id )
105
+ end
106
+ end
107
+
81
108
end
You can’t perform that action at this time.
0 commit comments