From 73882d5b2dfb421124f840dc4c6f830d13fa88fd Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 3 Aug 2026 17:10:54 +0200 Subject: [PATCH] fix: Handle "nothing to commit" message from stdout in commit_changes --- lib/git_client.rb | 4 +++- test/git_client_test.rb | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/git_client.rb b/lib/git_client.rb index 31614a2..0c1f74e 100644 --- a/lib/git_client.rb +++ b/lib/git_client.rb @@ -43,7 +43,9 @@ def commit_changes(message:) @repo.commit(message) true rescue Git::FailedError => e - return false if e.result.stderr.to_s.include?("nothing to commit") + # git prints "nothing to commit" to stdout; check both streams so a + # no-op pin is treated as a skip rather than a hard failure. + return false if "#{e.result.stdout} #{e.result.stderr}".include?("nothing to commit") raise end diff --git a/test/git_client_test.rb b/test/git_client_test.rb index 181a710..359a334 100644 --- a/test/git_client_test.rb +++ b/test/git_client_test.rb @@ -61,6 +61,17 @@ def test_commit_changes_returns_false_when_nothing_to_commit assert_equal false, @client.commit_changes(message: "irrelevant") end + def test_commit_changes_returns_false_when_nothing_to_commit_on_stdout + @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 + + assert_equal false, @client.commit_changes(message: "irrelevant") + end + 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]) @@ -90,9 +101,9 @@ def test_push_with_force # Git::FailedError wraps a Git::CommandLineResult which needs a status # object. We build the minimum required for e.result.stderr to work. - def git_failed_error(stderr) + def git_failed_error(stderr, stdout = "") fake_status = Struct.new(:exitstatus, :pid) { def to_s = "pid #{pid} exit #{exitstatus}" }.new(1, 0) - result = Git::CommandLineResult.new(["git", "commit"], fake_status, "", stderr) + result = Git::CommandLineResult.new(["git", "commit"], fake_status, stdout, stderr) Git::FailedError.new(result) end end