Skip to content

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

Merged
pszymkowiak merged 1 commit intortk-ai:masterfrom
polaminggkub-debug:fix/git-exit-code-propagation
Mar 2, 2026
Merged

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

Conversation

@polaminggkub-debug
Copy link
Copy Markdown
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>
@pszymkowiak
Copy link
Copy Markdown
Collaborator

Hi,

Thanks for the fix!

LGTM

@pszymkowiak pszymkowiak merged commit 5cfaecc into rtk-ai:master Mar 2, 2026
2 of 3 checks passed
maxkulish added a commit to maxkulish/rtk that referenced this pull request Mar 18, 2026
…og limits

Port 5 critical bug fixes from upstream rtk-ai/rtk (v0.29.0):

**P1.1a: Exit code propagation (rtk-ai#234)**
- Add std::process::exit(code) to push/pull/fetch/stash/worktree/commit
- Fixes CI/CD pipelines that rely on exit code semantics
- Pattern: eprintln error, then exit with git's actual exit code

**P1.1b: git commit -am, --amend support (rtk-ai#327/rtk-ai#360)**
- Change Commit enum from {messages: Vec<String>} to unit variant
- Update main.rs GitCommands::Commit to use trailing_var_arg
- Update build_commit_command() to accept all args, not just -m messages
- Now supports: -a, -am, --amend, --no-edit, --allow-empty, etc.
- Add tests for --amend, -am flags

**P1.1c: git branch creation fix (rtk-ai#194)**
- Already implemented in our fork (lines 961-1019)
- Detects positional args without list flags → routes to passthrough
- Prevents `rtk git branch newbranch` from silently becoming a list

**P1.1d: git log limit injection fix (rtk-ai#461/rtk-ai#478)**
- Add parse_user_limit() to parse -N, -n N, --max-count=N/N formats
- Update has_limit_flag detection to handle all limit formats
- Fix: don't inject -10 when user provides their own limit
- Fix: when user provides --oneline without limit, use -50 not -10
- Add 7 tests for parse_user_limit() edge cases

**P1.1e: Multiple -m flags (#c18553a)**
- Already supported by new trailing_var_arg implementation
- Tests verify `git commit -m "title" -m "body"` works

All tests pass (510 passed, 2 ignored). Zero clippy warnings.

Upstream commits ported:
- 5cfaecc (exit codes)
- 409aed6 (commit flags)
- 88dc752 (branch creation - already had)
- c18553a (multiple -m - already had)
- Related: rtk-ai#461, rtk-ai#478 (log limit)
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