Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/git_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 13 additions & 2 deletions test/git_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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