Skip to content

Commit 94c4289

Browse files
johnkeepinggitster
authored andcommitted
format-patch: output header for empty commits
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d15644f commit 94c4289

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

builtin/log.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
20972097

20982098
/* Always generate a patch */
20992099
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
2100+
rev.always_show_header = 1;
21002101

21012102
rev.zero_commit = zero_commit;
21022103
rev.patch_name_max = fmt_patch_name_max;

t/t4014-format-patch.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ test_expect_success setup '
5959
test_tick &&
6060
git commit -m "patchid 3" &&
6161
62+
git checkout -b empty main &&
63+
test_tick &&
64+
git commit --allow-empty -m "empty commit" &&
65+
6266
git checkout main
6367
'
6468

@@ -128,6 +132,12 @@ test_expect_success 'replay did not screw up the log message' '
128132
grep "^Side .* with .* backslash-n" actual
129133
'
130134

135+
test_expect_success 'format-patch empty commit' '
136+
git format-patch --stdout main..empty >empty &&
137+
grep "^From " empty >from &&
138+
test_line_count = 1 from
139+
'
140+
131141
test_expect_success 'extra headers' '
132142
git config format.headers "To: R E Cipient <[email protected]>
133143
" &&

0 commit comments

Comments
 (0)