Skip to content

Commit

Permalink
feat(hook): use a subshell by default on linux
Browse files Browse the repository at this point in the history
This will allow to use environment variables in hooks without
calling a subshell explicitly.
  • Loading branch information
oknozor committed Mar 8, 2022
1 parent 654baa9 commit fe47333
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/hook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::SETTINGS;
use parser::Token;

use anyhow::{anyhow, ensure, Result};
use itertools::Itertools;

#[derive(Debug, Eq, PartialEq)]
pub struct VersionSpan {
Expand Down Expand Up @@ -162,9 +163,22 @@ impl Hook {
pub fn run(&self) -> Result<()> {
let (cmd, args) = self.0.split_first().expect("hook must not be empty");

let status = Command::new(&cmd).args(args).status()?;
#[cfg(target_family = "unix")]
{
let args = args.iter().join(" ");
let cmd = format!("{cmd} {args}");

ensure!(status.success(), "hook failed with status {}", status);
let status = Command::new("sh").arg("-c").arg(cmd).status()?;

ensure!(status.success(), "hook failed with status {}", status);
}

#[cfg(target_family = "windows")]
{
let status = Command::new(cmd).args(args).status()?;

ensure!(status.success(), "hook failed with status {}", status);
}

Ok(())
}
Expand Down

0 comments on commit fe47333

Please sign in to comment.