]> git.ipfire.org Git - thirdparty/git.git/commitdiff
format-patch: output header for empty commits
authorJohn Keeping <john@keeping.me.uk>
Fri, 3 Mar 2023 16:03:01 +0000 (16:03 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 3 Mar 2023 17:13:52 +0000 (09:13 -0800)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/log.c
t/t4014-format-patch.sh

index a70fba198f9451c9005b3ecd14cfce8765e1d838..87b4fb2edc79aaa94007067b39e893ed53a96266 100644 (file)
@@ -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;
index f3313b8c58feabb3cd2e52fb1147bd68c6f43862..ffc7c60680aeb97bae656c1cbece3db8381c7c17 100755 (executable)
@@ -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>
 " &&