diff --git a/lib/git_client.rb b/lib/git_client.rb index ab11115..31614a2 100644 --- a/lib/git_client.rb +++ b/lib/git_client.rb @@ -37,8 +37,10 @@ def checkout_fresh_branch(branch:, base:) # Returns true iff a commit was actually created; false when # bin/importmap pin was a no-op and there is nothing to commit. def commit_changes(message:) + @repo.config("user.name", @author_name) + @repo.config("user.email", @author_email) @repo.add(["config/importmap.rb", "vendor/javascript"]) - @repo.commit(message, author: "#{@author_name} <#{@author_email}>") + @repo.commit(message) true rescue Git::FailedError => e return false if e.result.stderr.to_s.include?("nothing to commit") diff --git a/test/git_client_test.rb b/test/git_client_test.rb index af4ff01..181a710 100644 --- a/test/git_client_test.rb +++ b/test/git_client_test.rb @@ -10,7 +10,6 @@ class GitClientTest < Minitest::Test AUTHOR_NAME = "Test Bot" AUTHOR_EMAIL = "bot@example.com" - AUTHOR_STRING = "Test Bot " def setup @repo = Minitest::Mock.new @@ -44,14 +43,17 @@ def test_checkout_fresh_branch_resets_existing_branch_to_base def test_commit_changes_stages_and_commits_returning_true @repo.expect(:add, nil, [["config/importmap.rb", "vendor/javascript"]]) - @repo.expect(:commit, nil, ["Bump lodash from 4.17.20 to 4.17.21"], - author: AUTHOR_STRING) + @repo.expect(:config, nil, ["user.name", AUTHOR_NAME]) + @repo.expect(:config, nil, ["user.email", AUTHOR_EMAIL]) + @repo.expect(:commit, nil, ["Bump lodash from 4.17.20 to 4.17.21"]) assert_equal true, @client.commit_changes(message: "Bump lodash from 4.17.20 to 4.17.21") end def test_commit_changes_returns_false_when_nothing_to_commit @repo.expect(:add, nil, [["config/importmap.rb", "vendor/javascript"]]) + @repo.expect(:config, nil, ["user.name", AUTHOR_NAME]) + @repo.expect(:config, nil, ["user.email", AUTHOR_EMAIL]) @repo.expect(:commit, nil) do |_msg, **_opts| raise git_failed_error("nothing to commit, working tree clean") end @@ -61,6 +63,8 @@ def test_commit_changes_returns_false_when_nothing_to_commit def test_commit_changes_re_raises_unexpected_git_errors @repo.expect(:add, nil, [["config/importmap.rb", "vendor/javascript"]]) + @repo.expect(:config, nil, ["user.name", AUTHOR_NAME]) + @repo.expect(:config, nil, ["user.email", AUTHOR_EMAIL]) @repo.expect(:commit, nil) do |_msg, **_opts| raise git_failed_error("lock file exists") end