Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ def commit(message, opts = {})
arr_opts << '--all' if opts[:add_all] || opts[:all]
arr_opts << '--allow-empty' if opts[:allow_empty]
arr_opts << "--author=#{opts[:author]}" if opts[:author]
arr_opts << "--date=#{opts[:date]}" if opts[:date].is_a? String

command('commit', arr_opts)
end
Expand Down
53 changes: 53 additions & 0 deletions tests/units/test_commit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../test_helper'

class TestCommit < Test::Unit::TestCase

def setup
set_file_paths
end

def test_add
in_temp_dir do |path|
git = Git.clone(@wdir, 'test_commit')

create_file('test_commit/test_file_1', 'content tets_file_1')
git.add('test_file_1')

git.commit('test_add commit #1')

head = git.log[0]
assert(head.message == 'test_add commit #1')
assert(head.author.name == head.committer.name)
assert(head.author.email == head.committer.email)
assert(head.author.date == head.committer.date)

update_file('test_commit/test_file_1', 'new content')
git.commit('commit #2', all: true)

previous = head
head = git.log[0]

assert(head.message == 'commit #2')
assert(head.parent.sha == previous.sha)

update_file('test_commit/test_file_1', 'other content')
git.add('test_file_1')

author_date = Time.new(2016, 8, 3, 17, 37, 0, "-03:00")
new_author = "#{head.author.name} Other <#{head.author.email}.tld>"

git.commit('commit #3', date: author_date.strftime('%Y-%m-%dT%H:%M:%S %z'), author: new_author)

previous = head
head = git.log[0]

assert(head.author.name != head.committer.name)
assert(head.author.email != head.committer.email)
assert(head.author.date != head.committer.date)
assert(head.author.date == author_date)
end
end

end