Skip to content

Commit

Permalink
feat: split exec_replace into a third variant
Browse files Browse the repository at this point in the history
  • Loading branch information
demosdemon committed Jul 16, 2024
1 parent d68196f commit 212780f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions crates/git-remote-codecommit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn exec_replace(mut cmd: std::process::Command) -> anyhow::Result<ExitCode> {
anyhow::bail!("failed to execute git: {err}")
}

#[cfg(not(unix))]
#[cfg(windows)]
fn exec_replace(mut cmd: std::process::Command) -> anyhow::Result<ExitCode> {
use std::os::windows::process::ExitCodeExt;

Expand All @@ -150,7 +150,6 @@ fn exec_replace(mut cmd: std::process::Command) -> anyhow::Result<ExitCode> {
// 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
Expand All @@ -162,6 +161,21 @@ fn exec_replace(mut cmd: std::process::Command) -> anyhow::Result<ExitCode> {
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<ExitCode> {
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<'_>,
Expand Down

0 comments on commit 212780f

Please sign in to comment.