Running hooks through shell on Windows and Unix
[?]
Jan 7, 2021, 11:27 AM
VL7ZYKHBPKLNY5SA5QBW56SJ7LBBCKCGV5UAYLVF75KY6PPBOD4ACDependencies
- [2]
SEWGHUHQ.pijul/config: simplify remotes and hooks - [3]
SXEYMYF7Fixing the bad changes in history (unfortunately, by rebooting).
Change contents
- replacement in pijul/src/config.rs at line 68
pub record: Vec<String>,pub record: Vec<HookEntry>,}#[derive(Debug, Serialize, Deserialize)]pub struct HookEntry(toml::Value);#[derive(Debug, Serialize, Deserialize)]struct RawHook {command: String,args: Vec<String>,}impl HookEntry {pub fn run(&self) -> Result<(), anyhow::Error> {let (proc, s) = match &self.0 {toml::Value::String(ref s) => {if s.is_empty() {return Ok(());}(if cfg!(target_os = "windows") {std::process::Command::new("cmd").args(&["/C", s]).output().expect("failed to execute process")} else {std::process::Command::new(std::env::var("SHELL").unwrap_or("sh".to_string()),).arg("-c").arg(s).output().expect("failed to execute process")},s.clone(),)}v => {let hook = v.clone().try_into::<RawHook>()?;(std::process::Command::new(&hook.command).args(&hook.args).output().expect("failed to execute process"),hook.command,)}};if !proc.status.success() {use std::io::Write;let mut stderr = std::io::stderr();writeln!(stderr, "Hook {:?} exited with code {:?}", s, proc.status)?;std::process::exit(proc.status.code().unwrap_or(1))}Ok(())} - replacement in pijul/src/commands/record.rs at line 59[2.142]→[2.142:204](∅→∅),[2.204]→[2.204:245](∅→∅),[2.245]→[2.245:280](∅→∅),[2.280]→[2.280:381](∅→∅),[2.381]→[2.381:462](∅→∅),[2.462]→[2.462:525](∅→∅),[2.525]→[3.103521:103535](∅→∅),[3.103521]→[3.103521:103535](∅→∅)
let mut proc = std::process::Command::new("bash").current_dir(&repo.path).args(&["-c", &h]).spawn()?;let status = proc.wait()?;if !status.success() {writeln!(stderr, "Hook {:?} exited with code {:?}", h, status)?;std::process::exit(status.code().unwrap_or(1))}h.run()?