Skip to content

fix(git): propagate exit code on git worktree list failure - #2499

Merged
aeppling merged 3 commits into
rtk-ai:developfrom
hgunduzoglu:fix/git-worktree-list-exit-code
Jun 26, 2026
Merged

aeppling merged 3 commits into
rtk-ai:developfrom
hgunduzoglu:fix/git-worktree-list-exit-code

Conversation

@hgunduzoglu

Copy link
Copy Markdown
Contributor

Part of #2497 (2/3).

Problem

rtk git worktree (list mode) never checked result.success() — a failed git worktree list (e.g. run outside a repository) was flattened to empty output + exit 0. The has_action branch right above it (add/remove/prune/…) already guards on success and returns the real exit code; only list mode was missing the guard.

$ cd /non-git-dir
$ git worktree list     # native → exit 128 (fatal: not a git repository)
$ rtk git worktree      # before this PR
                        # empty output, exit 0  ✗

Fix

Add if !result.success() before the format/print/Ok(0) fall-through: surface git's stderr (with a FAILED: git worktree list header, matching the sibling handlers) and return result.exit_code.

$ rtk git worktree      # after
FAILED: git worktree list
fatal: not a git repository (or any of the parent directories): .git
                        # exit 128  ✓

Testing

  • New test test_run_worktree_list_propagates_failure: runs run_worktree against a non-git temp dir via git -C, asserts a non-zero exit (!= 0, exit-code-agnostic / cross-platform).
  • cargo fmt --all --check && cargo clippy --all-targets && cargo test — clean, 2200 passed.
  • Manual verification: non-git dir → exit 128 (was 0); real repo → worktree list + exit 0 (no regression).

Same masking-failure class as #1581 / #1535 / #2446 / #2494. run_status is #2498; run_stash PR follows.

run_worktree list mode never checked result.success() — a failed
`git worktree list` (e.g. run outside a repo) was flattened to empty
output + exit 0. The has_action branch already guards on success; apply
the same guard to list mode and surface git's error with its exit code.

Part of rtk-ai#2497
Per review (rtk-ai#2498): self-explanatory guard; remove comment to avoid noise.
@aeppling

aeppling commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

@hgunduzoglu Same problem on #2500 , otherwise LGTM :)

@aeppling

Copy link
Copy Markdown
Contributor

Thanks for contributing to RTK !

Comment thread src/cmds/git/git.rs Outdated
let result = exec_capture(&mut cmd).context("Failed to run git worktree list")?;

if !result.success() {
eprintln!("FAILED: git worktree list");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result should already contain the git error and if not we should just be transparent, writing our own error message like this is not a good idea

@aeppling
aeppling merged commit 9a52647 into rtk-ai:develop Jun 26, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants