Skip to content

Commit 9cfe491

Browse files
committed
commit with custom author date
Signed-off-by: mgarciaisaia <mgarciaisaia+github@gmail.com>
1 parent d5b0ec0 commit 9cfe491

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/git/lib.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ def commit(message, opts = {})
553553
arr_opts << '--all' if opts[:add_all] || opts[:all]
554554
arr_opts << '--allow-empty' if opts[:allow_empty]
555555
arr_opts << "--author=#{opts[:author]}" if opts[:author]
556+
arr_opts << "--date=#{opts[:date]}" if opts[:date].is_a? String
556557

557558
command('commit', arr_opts)
558559
end

tests/units/test_lib.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,22 @@ def test_commit_data
2121
assert_equal("test\n", data['message'])
2222
assert_equal(["546bec6f8872efa41d5d97a369f669165ecda0de"], data['parent'])
2323
end
24-
24+
25+
def test_commit_with_date
26+
create_file("#{@wdir}/test_file_1", 'content tets_file_1')
27+
@lib.add('test_file_1')
28+
29+
author_date = Time.new(2016, 8, 3, 17, 37, 0, "-03:00")
30+
31+
previous = @lib.commit_data('HEAD')
32+
33+
@lib.commit('commit with date', date: author_date.strftime('%Y-%m-%dT%H:%M:%S %z'))
34+
35+
data = @lib.commit_data('HEAD')
36+
37+
assert_equal("Scott Chacon <schacon@gmail.com> #{author_date.strftime("%s %z")}", data['author'])
38+
end
39+
2540
def test_checkout
2641
assert(@lib.checkout('test_checkout_b',{:new_branch=>true}))
2742
assert(@lib.checkout('master'))

0 commit comments

Comments
 (0)