use std::ffi::OsString;
use std::process::{Command, ExitCode};
pub fn exec_git(args: &[OsString]) -> ExitCode {
let mut command = Command::new("git");
command.args(args);
#[cfg(unix)]
{
use std::os::unix::process::CommandExt;
let error = command.exec();
eprintln!("git-sprout: could not run git: {error}");
ExitCode::from(1)
}
#[cfg(not(unix))]
status_of(&mut command)
}
pub fn run_git(args: &[OsString]) -> ExitCode {
status_of(Command::new("git").args(args))
}
#[allow(dead_code)]
fn status_of(command: &mut Command) -> ExitCode {
match command.status() {
Ok(status) => ExitCode::from(u8::try_from(status.code().unwrap_or(1)).unwrap_or(1)),
Err(error) => {
eprintln!("git-sprout: could not run git: {error}");
ExitCode::from(1)
}
}
}