From: Junio C Hamano <junio@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH] format-patch: notice failure to open cover letter for writing
Date: Thu, 21 Feb 2019 15:50:11 -0800 [thread overview]
Message-ID: <xmqqlg28snv0.fsf@gitster-ct.c.googlers.com> (raw)
The make_cover_letter() function is supposed to open a new file for
writing, and let the caller write into it via FILE *rev->diffopt.file
but because the function does not return anything, the caller does not
bother checking the return value.
Make sure it dies, instead of keep going with a NULL output
filestream and relying on it to cause a crash.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/log.c | 2 +-
t/t4014-format-patch.sh | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/builtin/log.c b/builtin/log.c
index 3e145fe502..43fc9a07df 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1047,7 +1047,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
if (!use_stdout &&
open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", rev, quiet))
- return;
+ die(_("Failed to create cover-letter file"));
log_write_email_headers(rev, head, &pp.after_subject, &need_8bit_cte, 0);
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 909c743c13..b6e2fdbc44 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -589,6 +589,12 @@ test_expect_success 'excessive subject' '
ls patches/0004-This-is-an-excessively-long-subject-line-for-a-messa.patch
'
+test_expect_success 'failure to write cover-letter aborts gracefully' '
+ test_when_finished "rmdir 0000-cover-letter.patch" &&
+ mkdir 0000-cover-letter.patch &&
+ test_must_fail git format-patch --no-renames --cover-letter -1
+'
+
test_expect_success 'cover-letter inherits diff options' '
git mv file foo &&
git commit -m foo &&
next reply other threads:[~2019-02-21 23:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-21 23:50 Junio C Hamano [this message]
2019-02-22 6:26 ` [PATCH] format-patch: notice failure to open cover letter for writing Jeff King
2019-02-22 7:50 ` Duy Nguyen
2019-02-22 17:54 ` Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqlg28snv0.fsf@gitster-ct.c.googlers.com \
--to=junio@pobox.com \
--cc=git@vger.kernel.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 NNTP newsgroup(s).