Skip to content

Commit 5cfaecc

Browse files
fix(git): propagate exit codes in push/pull/fetch/stash/worktree (#234)
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>
1 parent 44cb9ec commit 5cfaecc

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/git.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,7 @@ fn run_push(args: &[String], verbose: u8) -> Result<()> {
800800
if !stdout.trim().is_empty() {
801801
eprintln!("{}", stdout);
802802
}
803+
std::process::exit(output.status.code().unwrap_or(1));
803804
}
804805

805806
Ok(())
@@ -885,6 +886,7 @@ fn run_pull(args: &[String], verbose: u8) -> Result<()> {
885886
if !stdout.trim().is_empty() {
886887
eprintln!("{}", stdout);
887888
}
889+
std::process::exit(output.status.code().unwrap_or(1));
888890
}
889891

890892
Ok(())
@@ -1063,7 +1065,7 @@ fn run_fetch(args: &[String], verbose: u8) -> Result<()> {
10631065
if !stderr.trim().is_empty() {
10641066
eprintln!("{}", stderr);
10651067
}
1066-
return Ok(());
1068+
std::process::exit(output.status.code().unwrap_or(1));
10671069
}
10681070

10691071
// Count new refs from stderr (git fetch outputs to stderr)
@@ -1163,6 +1165,10 @@ fn run_stash(subcommand: Option<&str>, args: &[String], verbose: u8) -> Result<(
11631165
&combined,
11641166
&msg,
11651167
);
1168+
1169+
if !output.status.success() {
1170+
std::process::exit(output.status.code().unwrap_or(1));
1171+
}
11661172
}
11671173
_ => {
11681174
// Default: git stash (push)
@@ -1195,6 +1201,10 @@ fn run_stash(subcommand: Option<&str>, args: &[String], verbose: u8) -> Result<(
11951201
};
11961202

11971203
timer.track("git stash", "rtk git stash", &combined, &msg);
1204+
1205+
if !output.status.success() {
1206+
std::process::exit(output.status.code().unwrap_or(1));
1207+
}
11981208
}
11991209
}
12001210

@@ -1265,6 +1275,7 @@ fn run_worktree(args: &[String], verbose: u8) -> Result<()> {
12651275
if !stderr.trim().is_empty() {
12661276
eprintln!("{}", stderr);
12671277
}
1278+
std::process::exit(output.status.code().unwrap_or(1));
12681279
}
12691280
return Ok(());
12701281
}

0 commit comments

Comments
 (0)