git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] format-patch: notice failure to open cover letter for writing

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 22, 2019, 20:11 UTC
Message-ID
<20190222201111.98196-3-gitster@pobox.com>
In-Reply-To
<20190222201111.98196-1-gitster@pobox.com>

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 <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 f2d1fbf18a..ca86611efe 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1050,7 +1050,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 &&
-- 
2.21.0-rc2
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 9 in “format-patch --no-clobber”
  1. 0/3 format-patch --no-clobberJunio C Hamano, Feb 22, 2019
  2. 1/3 builtin/log: downcase the beginning of error messagesJunio C Hamano, Feb 22, 2019
  3. Eric SunshineFeb 22, 2019
  4. Junio C HamanoFeb 22, 2019
  5. 2/3 format-patch: notice failure to open cover letter for writingJunio C Hamano, Feb 22, 2019
  6. 3/3 format-patch: --no-clobber refrains from overwriting output filesJunio C Hamano, Feb 22, 2019
  7. Eric SunshineFeb 22, 2019
  8. Jeff KingFeb 23, 2019
  9. Ntentos StavrosMar 12, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.