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.
---
devel/nmbug/nmbug | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug
index b18ded7..4a79722 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;
}
--
1.9.1.353.gc66d89d