From: W. Trevor King Date: Sun, 6 Jul 2014 20:40:19 +0000 (-0700) Subject: nmbug: Add a git_with_status helper function X-Git-Tag: 0.19_rc1~129 X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=commitdiff_plain;h=4697e86a523fbbe43bf7ef38169f526adcbd710c nmbug: Add a git_with_status helper function Sometimes we want to catch Git errors and handle them, instead of dying with an error message. This lower-level version of git() allows us to get the error status when we want it. --- diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug index b18ded7b..4a797226 100755 --- a/devel/nmbug/nmbug +++ b/devel/nmbug/nmbug @@ -63,13 +63,20 @@ sub git_pipe { spawn ($envref, defined $ioref ? $ioref : (), defined $dir ? $dir : (), @_); } -sub git { +sub git_with_status { my $fh = git_pipe (@_); my $str = join ('', <$fh>); - unless (close $fh) { + close $fh; + my $status = $?; + chomp($str); + return ($str, $status); +} + +sub git { + my ($str, $status) = git_with_status (@_); + if ($status) { die "'git @_' exited with nonzero value\n"; } - chomp($str); return $str; }