From edf04be8d5833817ed3c8d7585e422b9fad7bd00 Mon Sep 17 00:00:00 2001 From: polamin Date: Sat, 21 Feb 2026 04:08:48 +0700 Subject: [PATCH] fix(git): propagate exit codes in push/pull/fetch/stash/worktree 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 --- src/git.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/git.rs b/src/git.rs index 3709e79f..ae32044d 100644 --- a/src/git.rs +++ b/src/git.rs @@ -787,6 +787,7 @@ fn run_push(args: &[String], verbose: u8) -> Result<()> { if !stdout.trim().is_empty() { eprintln!("{}", stdout); } + std::process::exit(output.status.code().unwrap_or(1)); } Ok(()) @@ -872,6 +873,7 @@ fn run_pull(args: &[String], verbose: u8) -> Result<()> { if !stdout.trim().is_empty() { eprintln!("{}", stdout); } + std::process::exit(output.status.code().unwrap_or(1)); } Ok(()) @@ -1050,7 +1052,7 @@ fn run_fetch(args: &[String], verbose: u8) -> Result<()> { if !stderr.trim().is_empty() { eprintln!("{}", stderr); } - return Ok(()); + std::process::exit(output.status.code().unwrap_or(1)); } // Count new refs from stderr (git fetch outputs to stderr) @@ -1150,6 +1152,10 @@ fn run_stash(subcommand: Option<&str>, args: &[String], verbose: u8) -> Result<( &combined, &msg, ); + + if !output.status.success() { + std::process::exit(output.status.code().unwrap_or(1)); + } } _ => { // Default: git stash (push) @@ -1182,6 +1188,10 @@ fn run_stash(subcommand: Option<&str>, args: &[String], verbose: u8) -> Result<( }; timer.track("git stash", "rtk git stash", &combined, &msg); + + if !output.status.success() { + std::process::exit(output.status.code().unwrap_or(1)); + } } } @@ -1252,6 +1262,7 @@ fn run_worktree(args: &[String], verbose: u8) -> Result<()> { if !stderr.trim().is_empty() { eprintln!("{}", stderr); } + std::process::exit(output.status.code().unwrap_or(1)); } return Ok(()); }