From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] lei p2q: exit with failure if format-patch fails
Date: Mon, 26 Apr 2021 08:43:23 +0000 [thread overview]
Message-ID: <20210426084323.22239-1-e@80x24.org> (raw)
Merely redirecting the failure message from git to our stderr is
insufficient.
---
lib/PublicInbox/LeiP2q.pm | 7 +++++--
t/lei-p2q.t | 4 +++-
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/lib/PublicInbox/LeiP2q.pm b/lib/PublicInbox/LeiP2q.pm
index a8a3dd2c..cb2309c7 100644
--- a/lib/PublicInbox/LeiP2q.pm
+++ b/lib/PublicInbox/LeiP2q.pm
@@ -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) {
diff --git a/t/lei-p2q.t b/t/lei-p2q.t
index 87cf9fa7..be2d437c 100644
--- a/t/lei-p2q.t
+++ b/t/lei-p2q.t
@@ -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');
reply other threads:[~2021-04-26 8:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210426084323.22239-1-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).