git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] format-patch: output header for empty commits
@ 2023-03-03 16:03 John Keeping
  2023-03-03 17:13 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: John Keeping @ 2023-03-03 16:03 UTC (permalink / raw)
  To: git; +Cc: John Keeping

When formatting an empty commit, it is surprising that a totally empty
file is generated.  Set the flag to always print the header, matching
the behaviour of git-log.

Signed-off-by: John Keeping <john@keeping.me.uk>
---
 builtin/log.c           |  1 +
 t/t4014-format-patch.sh | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/builtin/log.c b/builtin/log.c
index a70fba198f..87b4fb2edc 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -2097,6 +2097,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 
 	/* Always generate a patch */
 	rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
+	rev.always_show_header = 1;
 
 	rev.zero_commit = zero_commit;
 	rev.patch_name_max = fmt_patch_name_max;
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index f3313b8c58..ffc7c60680 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -59,6 +59,10 @@ test_expect_success setup '
 	test_tick &&
 	git commit -m "patchid 3" &&
 
+	git checkout -b empty main &&
+	test_tick &&
+	git commit --allow-empty -m "empty commit" &&
+
 	git checkout main
 '
 
@@ -128,6 +132,12 @@ test_expect_success 'replay did not screw up the log message' '
 	grep "^Side .* with .* backslash-n" actual
 '
 
+test_expect_success 'format-patch empty commit' '
+	git format-patch --stdout main..empty >empty &&
+	grep "^From " empty >from &&
+	test_line_count = 1 from
+'
+
 test_expect_success 'extra headers' '
 	git config format.headers "To: R E Cipient <rcipient@example.com>
 " &&
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-08 20:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-03 16:03 [PATCH] format-patch: output header for empty commits John Keeping
2023-03-03 17:13 ` Junio C Hamano
2023-03-04 10:45   ` John Keeping
2023-03-06 17:08     ` Junio C Hamano
2023-03-08 20:33       ` John Keeping
2023-03-08 20:43         ` Junio C Hamano

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).