Skip to content

Commit

Permalink
format-patch: show 0/1 and 1/1 for singleton patch with cover letter
Browse files Browse the repository at this point in the history
Change the default behavior of git-format-patch to generate numbered
sequence of 0/1 and 1/1 when generating both a cover-letter and a single
patch. This standardizes the cover letter to have 0/N which helps
distinguish the cover letter from the patch itself. Since the behavior
is easily changed via configuration as well as the use of -n and -N this
should be acceptable default behavior.

Add tests for the new default behavior.

Signed-off-by: Jacob Keller <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
jacob-keller authored and gitster committed Aug 23, 2016
1 parent 05219a1 commit 957ed3a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 4 additions & 4 deletions builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -1650,16 +1650,16 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
/* nothing to do */
return 0;
total = nr;
if (!keep_subject && auto_number && total > 1)
numbered = 1;
if (numbered)
rev.total = total + start_number - 1;
if (cover_letter == -1) {
if (config_cover_letter == COVER_AUTO)
cover_letter = (total > 1);
else
cover_letter = (config_cover_letter == COVER_ON);
}
if (!keep_subject && auto_number && (total > 1 || cover_letter))
numbered = 1;
if (numbered)
rev.total = total + start_number - 1;

if (!signature) {
; /* --no-signature inhibits all signatures */
Expand Down
17 changes: 17 additions & 0 deletions t/t4021-format-patch-numbered.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ test_no_numbered() {
test_num_no_numbered $1 2
}

test_single_cover_letter_numbered() {
grep "^Subject: \[PATCH 0/1\]" $1 &&
grep "^Subject: \[PATCH 1/1\]" $1
}

test_single_numbered() {
grep "^Subject: \[PATCH 1/1\]" $1
}
Expand Down Expand Up @@ -121,4 +126,16 @@ test_expect_success '--start-number && --numbered' '
grep "^Subject: \[PATCH 3/3\]" patch8
'

test_expect_success 'single patch with cover-letter defaults to numbers' '
git format-patch --cover-letter --stdout HEAD~1 >patch9.single &&
test_single_cover_letter_numbered patch9.single
'

test_expect_success 'Use --no-numbered and --cover-letter single patch' '
git format-patch --no-numbered --stdout --cover-letter HEAD~1 >patch10 &&
test_no_numbered patch10
'



test_done

0 comments on commit 957ed3a

Please sign in to comment.