[PATCH 3/4] nmbug: Catch stderr in is_unmerged

W. Trevor King wking at tremily.us
Sun Jul 6 13:40:21 PDT 2014


Add a '-2|' dir for "execute the command and pipe both stdout and
stderr to us".  Use this to catch stderr from the rev-parse call in
is_unmerged.  We already check the status, so we don't want to confuse
users with stuff like:

  error: No upstream configured for branch 'master'

on nmbug's stderr.
---
 devel/nmbug/nmbug | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug
index 998ee6b..c9ac046 100755
--- a/devel/nmbug/nmbug
+++ b/devel/nmbug/nmbug
@@ -56,7 +56,7 @@ my $EMPTYBLOB = git (qw{hash-object -t blob /dev/null});
 sub git_pipe {
   my $envref = (ref $_[0] eq 'HASH') ? shift : {};
   my $ioref  = (ref $_[0] eq 'ARRAY') ? shift : undef;
-  my $dir = ($_[0] eq '-|' or $_[0] eq '|-') ? shift : undef;
+  my $dir = ($_[0] eq '-|' or $_[0] eq '-2|' or $_[0] eq '|-') ? shift : undef;
 
   unshift @_, 'git';
   $envref->{GIT_DIR} ||= $NMBGIT;
@@ -83,10 +83,15 @@ sub git {
 sub spawn {
   my $envref = (ref $_[0] eq 'HASH') ? shift : {};
   my $ioref  = (ref $_[0] eq 'ARRAY') ? shift : undef;
-  my $dir = ($_[0] eq '-|' or $_[0] eq '|-') ? shift : '-|';
+  my $dir = ($_[0] eq '-|' or $_[0] eq '-2|' or $_[0] eq '|-') ? shift : '-|';
+  my $stderr_to_stdout = $dir eq '-2|';
 
   die unless @_;
 
+  if ($dir eq '-2|') {
+    $dir = '-|';
+  }
+
   if (open my $child, $dir) {
     return $child;
   }
@@ -105,6 +110,9 @@ sub spawn {
       if ($dir ne '|-') {
 	open STDIN, '<', '/dev/null' or die "reopening stdin: $!"
       }
+      if ($stderr_to_stdout) {
+	open(STDERR, ">&STDOUT");
+      }
       exec @_;
       die "exec @_: $!";
     }
@@ -430,7 +438,7 @@ sub do_status {
 sub is_unmerged {
   my $commit = shift || '@{upstream}';
 
-  my ($fetch_head, $status) = git_with_status ('rev-parse', $commit);
+  my ($fetch_head, $status) = git_with_status ('-2|', 'rev-parse', $commit);
   if ($status) {
     return 0;
   }
-- 
1.9.1.353.gc66d89d



More information about the notmuch mailing list