diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 8f05f9b0..834511f8 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -556,6 +556,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 diff --git a/tests/units/test_lib.rb b/tests/units/test_lib.rb index 403a2877..ff5446f1 100644 --- a/tests/units/test_lib.rb +++ b/tests/units/test_lib.rb @@ -21,7 +21,20 @@ def test_commit_data assert_equal("test\n", data['message']) assert_equal(["546bec6f8872efa41d5d97a369f669165ecda0de"], data['parent']) end - + + def test_commit_with_date + create_file("#{@wdir}/test_file_1", 'content tets_file_1') + @lib.add('test_file_1') + + author_date = Time.new(2016, 8, 3, 17, 37, 0, "-03:00") + + @lib.commit('commit with date', date: author_date.strftime('%Y-%m-%dT%H:%M:%S %z')) + + data = @lib.commit_data('HEAD') + + assert_equal("Scott Chacon #{author_date.strftime("%s %z")}", data['author']) + end + def test_checkout assert(@lib.checkout('test_checkout_b',{:new_branch=>true})) assert(@lib.checkout('master'))