Skip to content

Commit 6f48fdb

Browse files
committed
commit with custom author date
Signed-off-by: Matias Garcia Isaia <mgarciaisaia+github@gmail.com>
1 parent d5b0ec0 commit 6f48fdb

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
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_commit.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env ruby
2+
3+
require File.dirname(__FILE__) + '/../test_helper'
4+
5+
class TestCommit < Test::Unit::TestCase
6+
7+
def setup
8+
set_file_paths
9+
end
10+
11+
def test_add
12+
in_temp_dir do |path|
13+
git = Git.clone(@wdir, 'test_commit')
14+
15+
create_file('test_commit/test_file_1', 'content tets_file_1')
16+
git.add('test_file_1')
17+
18+
git.commit('test_add commit #1')
19+
20+
head = git.log[0]
21+
assert(head.message == 'test_add commit #1')
22+
assert(head.author.name == head.committer.name)
23+
assert(head.author.email == head.committer.email)
24+
assert(head.author.date == head.committer.date)
25+
26+
update_file('test_commit/test_file_1', 'new content')
27+
git.commit('commit #2', all: true)
28+
29+
previous = head
30+
head = git.log[0]
31+
32+
assert(head.message == 'commit #2')
33+
assert(head.parent.sha == previous.sha)
34+
35+
update_file('test_commit/test_file_1', 'other content')
36+
git.add('test_file_1')
37+
38+
author_date = Time.new(2016, 8, 3, 17, 37, 0, "-03:00")
39+
new_author = "#{head.author.name} Other <#{head.author.email}.tld>"
40+
41+
git.commit('commit #3', date: author_date.strftime('%Y-%m-%dT%H:%M:%S %z'), author: new_author)
42+
43+
previous = head
44+
head = git.log[0]
45+
46+
assert(head.author.name != head.committer.name)
47+
assert(head.author.email != head.committer.email)
48+
assert(head.author.date != head.committer.date)
49+
assert(head.author.date == author_date)
50+
end
51+
end
52+
53+
end

0 commit comments

Comments
 (0)