]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei p2q: exit with failure if format-patch fails
authorEric Wong <e@80x24.org>
Mon, 26 Apr 2021 08:43:23 +0000 (08:43 +0000)
committerEric Wong <e@80x24.org>
Mon, 26 Apr 2021 11:40:44 +0000 (07:40 -0400)
Merely redirecting the failure message from git to our stderr is
insufficient.

lib/PublicInbox/LeiP2q.pm
t/lei-p2q.t

index a8a3dd2ccfa7d0bcae67ba7d9b3ec4a66b122ab0..cb2309c7adc9a1389d84285337221d83372ed8f6 100644 (file)
@@ -105,6 +105,7 @@ sub do_p2q { # via wq_do
        }
        my $smsg = bless {}, 'PublicInbox::Smsg';
        my $in = $self->{0};
+       my @cmd;
        unless ($in) {
                my $input = $self->{input};
                my $devfd = $lei->path_to_fd($input) // return;
@@ -114,11 +115,13 @@ sub do_p2q { # via wq_do
                        open($in, '<', $input) or
                                return $lei->fail("open < $input: $!");
                } else {
-                       my @cmd = (qw(git format-patch --stdout -1), $input);
+                       @cmd = (qw(git format-patch --stdout -1), $input);
                        $in = popen_rd(\@cmd, undef, { 2 => $lei->{2} });
                }
        };
-       my $eml = PublicInbox::Eml->new(\(do { local $/; <$in> }));
+       my $str = do { local $/; <$in> };
+       @cmd && !close($in) and return $lei->fail("E: @cmd failed: $?");
+       my $eml = PublicInbox::Eml->new(\$str);
        $lei->{diff_want} = +{ map { $_ => 1 } @want };
        $smsg->populate($eml);
        while (my ($pfx, $fields) = each %pfx2smsg) {
index 87cf9fa7d6d9fcad15097037f5cf8610e72a8f3f..be2d437c709d6e67f962eed7fb8c14dbc11eee12 100644 (file)
@@ -6,9 +6,11 @@ require_git 2.6;
 require_mods(qw(json DBD::SQLite Search::Xapian));
 
 test_lei(sub {
+       ok(!lei(qw(p2q this-better-cause-format-patch-to-fail)),
+               'p2q fails on bogus arg');
        lei_ok(qw(p2q -w dfpost t/data/0001.patch));
        is($lei_out, "dfpost:6e006fd73b1d\n", 'pathname');
-       open my $fh, '+<', 't/data/0001.patch';
+       open my $fh, '+<', 't/data/0001.patch' or xbail "open: $!";
        lei_ok([qw(p2q -w dfpost -)], undef, { %$lei_opt, 0 => $fh });
        is($lei_out, "dfpost:6e006fd73b1d\n", '--stdin');