Skip to content

Stop git.latest logging a spurious rev-parse error on first clone#69697

Open
ggiesen wants to merge 3 commits into
saltstack:3006.xfrom
ggiesen:fix-51157-git-latest-error-msg
Open

Stop git.latest logging a spurious rev-parse error on first clone#69697
ggiesen wants to merge 3 commits into
saltstack:3006.xfrom
ggiesen:fix-51157-git-latest-error-msg

Conversation

@ggiesen

@ggiesen ggiesen commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

git.is_worktree probes a directory with 'git rev-parse --show-toplevel' and expects retcode 128 for non-repos (already caught and handled), but _get_toplevel ran the probe without ignore_retcode so cmd.run_all logged the expected failure at ERROR level, producing the noisy "failed with return code: 128" messages reported in #51157. The fix adds an ignore_retcode parameter to _get_toplevel (default False, so the other caller at line ~2798 keeps failing loudly) and passes ignore_retcode=True from is_worktree's probe. Verified the fix works and that the test pins the bug: with the fix, is_worktree returns False and cmd.run_all is called with ignore_retcode=True; after stashing the source change, ignore_retcode is False, so the test assertion fails. Note: the pytest runner itself times out during salt's conftest/plugin collection in this shared venv even with --noconftest, so I validated the test's exact assertions by importing salt.modules.git directly with the identical mocks (fast, passes with fix / fails without).

What issues does this PR fix or reference?

Fixes #51157

Previous Behavior

See #51157.

New Behavior

Stop git.latest logging a spurious rev-parse error on first clone. Validated by a unit test proven to fail on unpatched 3006.x and pass with the fix (confirmed by adversarial review).

Merge requirements satisfied?

  • Tests written/updated
  • Changelog

Commits signed with GPG?

No

is_worktree() probes cwd with 'git rev-parse --show-toplevel' and expects
that command to fail (retcode 128) when cwd is not a git repository, which
it already handles by catching CommandExecutionError and returning False.
However _get_toplevel() ran the probe without ignore_retcode, so cmd.run_all
logged the expected failure at ERROR level, producing noise such as:

  [ERROR   ] Command 'git rev-parse --show-toplevel' failed with return code: 128

Add an ignore_retcode parameter to _get_toplevel (default False, preserving
behaviour for other callers) and pass ignore_retcode=True from is_worktree's
probe so the expected failure no longer logs at ERROR level.

Fixes saltstack#51157
… probe

The direct test calls _get_toplevel itself with ignore_retcode=True, the
exact flag its production caller is_worktree passes when probing a path
that may not be a repo, and asserts the flag is forwarded to cmd.run_all
so the expected failure is not logged at ERROR level. The inverse test
guards against overcorrection: callers like list_worktrees invoke
_get_toplevel without the flag, and a genuine rev-parse failure there
must still reach cmd.run_all with ignore_retcode=False and raise
CommandExecutionError.
@dwoz dwoz added the test:full Run the full test suite label Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants