From 552b0ffff3cef2b18c4ed4fb1a07d56823f9e1af Mon Sep 17 00:00:00 2001 From: Bradford Boyle Date: Fri, 16 Nov 2018 21:06:04 -0800 Subject: [PATCH] Return exit code from `git` subprocesses (#40) `git-together` was throwing away the `ExitStatus` result returned from invoking `git` commands. This causes an issue in particular with the `--exit-code` option of `git-diff` which is supposed to return 1 if there were differences. This commit uses the exit code of the underlying `git` command, where appropriate; otherwise, it returns 0. Authored-by: Bradford D. Boyle --- src/lib.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0622378..d7e1d77 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,7 @@ fn namespaced(name: &str) -> String { format!("{}.{}", NAMESPACE, name) } -pub fn run() -> Result<()> { +pub fn run() -> Result { let all_args: Vec<_> = env::args().skip(1).collect(); let mut args: Vec<&str> = all_args.iter().map(String::as_ref).collect(); @@ -38,7 +38,7 @@ pub fn run() -> Result<()> { args.retain(|&arg| arg != "--global"); - match *args.as_slice() { + let code = match *args.as_slice() { [sub_cmd] if triggers.contains(&sub_cmd) => { let inits = gt.get_active()?; let inits: Vec<_> = inits.iter().map(String::as_ref).collect(); @@ -47,6 +47,8 @@ pub fn run() -> Result<()> { for (initials, author) in inits.iter().zip(authors.iter()) { println!("{}: {}", initials, author); } + + 0 } [sub_cmd, "--list"] if triggers.contains(&sub_cmd) => { let authors = gt.all_authors()?; @@ -56,9 +58,12 @@ pub fn run() -> Result<()> { for (initials, author) in sorted { println!("{}: {}", initials, author); } + + 0 } [sub_cmd, "--clear"] if triggers.contains(&sub_cmd) => { gt.clear_active()?; + 0 } [sub_cmd, "--version"] if triggers.contains(&sub_cmd) => { println!( @@ -66,12 +71,16 @@ pub fn run() -> Result<()> { option_env!("CARGO_PKG_NAME").unwrap_or("git-together"), option_env!("CARGO_PKG_VERSION").unwrap_or("unknown version") ); + + 0 } [sub_cmd, ref inits..] if triggers.contains(&sub_cmd) => { let authors = gt.set_active(inits)?; for author in authors { println!("{}", author); } + + 0 } [sub_cmd, ref rest..] if gt.is_signoff_cmd(sub_cmd) => { if sub_cmd == "merge" { @@ -87,16 +96,18 @@ pub fn run() -> Result<()> { if status.success() { gt.rotate_active()?; } + status.code().ok_or("process terminated by signal")? } - [ref args..] => { - Command::new("git") + [ref args..] => { + let status = Command::new("git") .args(args) .status() .chain_err(|| "failed to execute process")?; + status.code().ok_or("process terminated by signal")? } }; - Ok(()) + Ok(code) } pub struct GitTogether {