From 212780fe0e4d74add47b33a89055cdd571b512cc Mon Sep 17 00:00:00 2001 From: Brandon LeBlanc Date: Mon, 15 Jul 2024 18:16:37 -0700 Subject: [PATCH] feat: split exec_replace into a third variant --- crates/git-remote-codecommit/src/main.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/git-remote-codecommit/src/main.rs b/crates/git-remote-codecommit/src/main.rs index 5a61b37..6558c5b 100644 --- a/crates/git-remote-codecommit/src/main.rs +++ b/crates/git-remote-codecommit/src/main.rs @@ -138,7 +138,7 @@ fn exec_replace(mut cmd: std::process::Command) -> anyhow::Result { anyhow::bail!("failed to execute git: {err}") } -#[cfg(not(unix))] +#[cfg(windows)] fn exec_replace(mut cmd: std::process::Command) -> anyhow::Result { use std::os::windows::process::ExitCodeExt; @@ -150,7 +150,6 @@ fn exec_replace(mut cmd: std::process::Command) -> anyhow::Result { // sent to all processes attached to the console, including the parent // process. Therefore, by ignoring the ctrl-c, we let the child handle the // signal and exit. We can reap the process normally. - #[cfg(windows)] ctrlc::set_handler(|| {}).context("failed to set ctrl-c handler")?; let exit = cmd @@ -162,6 +161,21 @@ fn exec_replace(mut cmd: std::process::Command) -> anyhow::Result { Ok(ExitCode::from_raw(exit.code().unwrap_or(0) as u32)) } +#[cfg(not(any(unix, windows)))] +fn exec_replace(mut cmd: std::process::Command) -> anyhow::Result { + let exit = cmd + .spawn() + .context("failed to spawn git process")? + .wait() + .context("failed to wait for subprocess")?; + + if exit.success() { + Ok(ExitCode::SUCCESS) + } else { + Ok(ExitCode::FAILURE) + } +} + fn generate_url( timestamp: SystemTime, parsed_uri: ParsedUri<'_>,