Skip to content

Commit 0d0e055

Browse files
git.commit - Supporting :amend and :all (instead of :add_all)
git.log - Supporting [] to access logs by index Closes ruby-git#87
1 parent ed6b3e2 commit 0d0e055

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

lib/git/base.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,11 @@ def revert(commitish = nil, opts = {})
303303
# commits all pending changes in the index file to the git repository
304304
#
305305
# options:
306-
# :add_all
306+
# :all
307307
# :allow_empty
308+
# :amend
308309
# :author
310+
#
309311
def commit(message, opts = {})
310312
self.lib.commit(message, opts)
311313
end

lib/git/lib.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,13 @@ def remove(path = '.', opts = {})
407407
end
408408

409409
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]
412414
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+
414417
command('commit', arr_opts)
415418
end
416419

lib/git/log.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ def last
9494
check_log
9595
@commits.last rescue nil
9696
end
97+
98+
def [](index)
99+
check_log
100+
@commits[index] rescue nil
101+
end
102+
97103

98104
private
99105

tests/units/test_base.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,31 @@ def test_add
7878
end
7979
end
8080

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+
81108
end

0 commit comments

Comments
 (0)