Skip to main content

git_sprout/
delegate.rs

1// ABOUTME: Runs the real `git worktree add` and passes its exit status through.
2// ABOUTME: Every failure path in the tool ends here, so the user gets git's own result.
3
4use std::ffi::OsString;
5use std::process::{Command, ExitCode};
6
7/// Runs `git worktree <args>` inheriting stdio, and returns git's exit code.
8pub fn worktree_add(args: &[OsString]) -> ExitCode {
9    let status = Command::new("git").arg("worktree").args(args).status();
10    match status {
11        Ok(s) => ExitCode::from(u8::try_from(s.code().unwrap_or(1)).unwrap_or(1)),
12        Err(err) => {
13            eprintln!("git-sprout: could not run git: {err}");
14            ExitCode::from(1)
15        }
16    }
17}