]> git.notmuchmail.org Git - notmuch/commitdiff
nmbug: Add a git_with_status helper function
authorW. Trevor King <wking@tremily.us>
Sun, 6 Jul 2014 20:40:19 +0000 (13:40 -0700)
committerDavid Bremner <david@tethera.net>
Wed, 16 Jul 2014 09:31:23 +0000 (06:31 -0300)
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

index b18ded7b7c1e48cf7b54a1e6901cb92c7cbf1961..4a79722613c85fd869244a7bccf7f04604806b8f 100755 (executable)
@@ -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;
 }