Skip to content

Commit ca6b91d

Browse files
meyeringgitster
authored andcommitted
format-patch let -k override a config-specified format.numbered
Let a command-line --keep-subject (-k) override a config-specified format.numbered (--numbered (-n)), rather than provoking the "-n and -k are mutually exclusive" failure. * t4021-format-patch-numbered.sh: Test for the above Signed-off-by: Jim Meyering <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f01f109 commit ca6b91d

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

builtin-log.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
755755
int cover_letter = 0;
756756
int boundary_count = 0;
757757
int no_binary_diff = 0;
758+
int numbered_cmdline_opt = 0;
758759
struct commit *origin = NULL, *head = NULL;
759760
const char *in_reply_to = NULL;
760761
struct patch_ids ids;
@@ -786,8 +787,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
786787
if (!strcmp(argv[i], "--stdout"))
787788
use_stdout = 1;
788789
else if (!strcmp(argv[i], "-n") ||
789-
!strcmp(argv[i], "--numbered"))
790+
!strcmp(argv[i], "--numbered")) {
790791
numbered = 1;
792+
numbered_cmdline_opt = 1;
793+
}
791794
else if (!strcmp(argv[i], "-N") ||
792795
!strcmp(argv[i], "--no-numbered")) {
793796
numbered = 0;
@@ -918,6 +921,15 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
918921

919922
if (start_number < 0)
920923
start_number = 1;
924+
925+
/*
926+
* If numbered is set solely due to format.numbered in config,
927+
* and it would conflict with --keep-subject (-k) from the
928+
* command line, reset "numbered".
929+
*/
930+
if (numbered && keep_subject && !numbered_cmdline_opt)
931+
numbered = 0;
932+
921933
if (numbered && keep_subject)
922934
die ("-n and -k are mutually exclusive.");
923935
if (keep_subject && subject_prefix)

t/t4021-format-patch-numbered.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ test_expect_success 'format.numbered && --no-numbered' '
8686
8787
'
8888

89+
test_expect_success 'format.numbered && --keep-subject' '
90+
91+
git format-patch --keep-subject --stdout HEAD^ >patch4a &&
92+
grep "^Subject: Third" patch4a
93+
94+
'
95+
8996
test_expect_success 'format.numbered = auto' '
9097
9198
git config format.numbered auto

0 commit comments

Comments
 (0)