1use std::ffi::OsString;
5use std::process::{Command, ExitCode};
6
7pub fn exec_git(args: &[OsString]) -> ExitCode {
10 let mut command = Command::new("git");
11 command.args(args);
12
13 #[cfg(unix)]
14 {
15 use std::os::unix::process::CommandExt;
16 let error = command.exec();
17 eprintln!("git-sprout: could not run git: {error}");
18 ExitCode::from(1)
19 }
20
21 #[cfg(not(unix))]
22 status_of(&mut command)
23}
24
25pub fn run_git(args: &[OsString]) -> ExitCode {
27 status_of(Command::new("git").args(args))
28}
29
30#[allow(dead_code)]
31fn status_of(command: &mut Command) -> ExitCode {
32 match command.status() {
33 Ok(status) => ExitCode::from(u8::try_from(status.code().unwrap_or(1)).unwrap_or(1)),
34 Err(error) => {
35 eprintln!("git-sprout: could not run git: {error}");
36 ExitCode::from(1)
37 }
38 }
39}