Skip to content

Comments

fix(git): propagate exit codes in push/pull/fetch/stash/worktree#234

Open
polaminggkub-debug wants to merge 1 commit intortk-ai:masterfrom
polaminggkub-debug:fix/git-exit-code-propagation
Open

fix(git): propagate exit codes in push/pull/fetch/stash/worktree#234
polaminggkub-debug wants to merge 1 commit intortk-ai:masterfrom
polaminggkub-debug:fix/git-exit-code-propagation

Conversation

@polaminggkub-debug
Copy link
Contributor

Problem

`rtk git push`, `rtk git pull`, `rtk git fetch`, `rtk git stash` (pop/apply/drop/push/default), and `rtk git worktree` all print a `FAILED:` message on error but return exit code 0 to the caller.

This breaks CI/CD pipelines and shell scripts that rely on exit code semantics:

```bash
rtk git push || handle_error # handle_error never called
rtk git pull && deploy # deploy runs even on pull failure
```

Root cause

The failure branches in these functions print the error but fall through to `Ok(())` instead of propagating git's exit code via `std::process::exit()`.

Fix

Add `std::process::exit(output.status.code().unwrap_or(1))` in each failure branch, matching the pattern already used correctly in `run_log`, `run_diff`, `run_add`, and `run_branch`.

Per the Rust docs, `status.code()` returns `Option` — `None` when the process was killed by a signal (Unix). The `.unwrap_or(1)` fallback handles that case correctly.

Functions fixed

Function Issue
`run_push` Falls through to `Ok(())` on failure
`run_pull` Falls through to `Ok(())` on failure
`run_fetch` Explicit `return Ok(())` on failure
`run_stash` (pop/apply/drop/push) Falls through to `Ok(())` after timer
`run_stash` (default) Falls through to `Ok(())` after timer
`run_worktree` `return Ok(())` on both success and failure

Testing

All 412 existing tests pass. No new behavior on the success path.

🤖 Generated with Claude Code

run_push, run_pull, run_fetch, run_stash (pop/apply/drop/push and
default), and run_worktree all printed FAILED messages on error but
returned Ok(()) instead of propagating git's exit code.

This breaks CI/CD pipelines and shell scripts that rely on exit code
semantics (e.g. `git push || handle_error`).

Fix: call std::process::exit(output.status.code().unwrap_or(1)) in
each failure branch, matching the pattern already used in run_log,
run_diff, run_add, and run_branch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant