Skip to content

Commit 2fe95f4

Browse files
committed
format-patch: notice failure to open cover letter for writing
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, when it fails to open the file. Signed-off-by: Junio C Hamano <[email protected]>
1 parent bc208ae commit 2fe95f4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
10501050

10511051
if (!use_stdout &&
10521052
open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", rev, quiet))
1053-
return;
1053+
die(_("failed to create cover-letter file"));
10541054

10551055
log_write_email_headers(rev, head, &pp.after_subject, &need_8bit_cte, 0);
10561056

t/t4014-format-patch.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,12 @@ test_expect_success 'excessive subject' '
589589
ls patches/0004-This-is-an-excessively-long-subject-line-for-a-messa.patch
590590
'
591591

592+
test_expect_success 'failure to write cover-letter aborts gracefully' '
593+
test_when_finished "rmdir 0000-cover-letter.patch" &&
594+
mkdir 0000-cover-letter.patch &&
595+
test_must_fail git format-patch --no-renames --cover-letter -1
596+
'
597+
592598
test_expect_success 'cover-letter inherits diff options' '
593599
git mv file foo &&
594600
git commit -m foo &&

0 commit comments

Comments
 (0)