From fb0a828ede6736ac63cd6320ead3061617fc02d9 Mon Sep 17 00:00:00 2001 From: mgarciaisaia Date: Fri, 2 Dec 2016 10:07:54 -0300 Subject: [PATCH] commit with custom author date --- lib/git/lib.rb | 1 + tests/units/test_commit.rb | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/units/test_commit.rb diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 777e42ea..51f12086 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -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 diff --git a/tests/units/test_commit.rb b/tests/units/test_commit.rb new file mode 100644 index 00000000..f6b713be --- /dev/null +++ b/tests/units/test_commit.rb @@ -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