format-patch: show 0/1 and 1/1 for singleton patch with cover letter
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 <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jacob Keller committed
Aug 23, 2016 at 15:45 UTC
957ed3a56c50f5c542e0cac58d75e1d4b9658ac3
2 files changed
+21
-4
builtin/log.c
+4
-4
@@ -1650,16 +1650,16 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1650
/* nothing to do */
1651
return 0;
1652
total = nr;
1653
- if (!keep_subject && auto_number && total > 1)
1654
- numbered = 1;
1655
- if (numbered)
1656
- rev.total = total + start_number - 1;
1653
if (cover_letter == -1) {
1654
if (config_cover_letter == COVER_AUTO)
1655
cover_letter = (total > 1);
1656
else
1657
cover_letter = (config_cover_letter == COVER_ON);
1658
}
1659
+ if (!keep_subject && auto_number && (total > 1 || cover_letter))
1660
+ numbered = 1;
1661
+ if (numbered)
1662
+ rev.total = total + start_number - 1;
1663
1664
if (!signature) {
1665
; /* --no-signature inhibits all signatures */
t/t4021-format-patch-numbered.sh
+17
@@ -36,6 +36,11 @@ test_no_numbered() {
36
test_num_no_numbered $1 2
37
}
38
39
+test_single_cover_letter_numbered() {
40
+ grep "^Subject: \[PATCH 0/1\]" $1 &&
41
+ grep "^Subject: \[PATCH 1/1\]" $1
42
+}
43
+
44
test_single_numbered() {
45
grep "^Subject: \[PATCH 1/1\]" $1
46
}
@@ -121,4 +126,16 @@ test_expect_success '--start-number && --numbered' '
126
grep "^Subject: \[PATCH 3/3\]" patch8
127
'
128
129
+test_expect_success 'single patch with cover-letter defaults to numbers' '
130
+ git format-patch --cover-letter --stdout HEAD~1 >patch9.single &&
131
+ test_single_cover_letter_numbered patch9.single
132
+'
133
+
134
+test_expect_success 'Use --no-numbered and --cover-letter single patch' '
135
+ git format-patch --no-numbered --stdout --cover-letter HEAD~1 >patch10 &&
136
+ test_no_numbered patch10
137
+'
138
+
139
+
140
+
141
test_done