From 4697e86a523fbbe43bf7ef38169f526adcbd710c Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 6 Jul 2014 13:40:19 -0700 Subject: [PATCH] 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. --- devel/nmbug/nmbug | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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; } -- 2.39.2