{"thread":{"id":"19232","subject":"[PATCH] format-patch let -k override a config-specified format.numbered","startedAt":"2009-05-07T16:31:07Z","lastAt":"2009-05-09T08:12:01Z","messageCount":4,"participants":["Jim Meyering","Stephen Boyd","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"113231","messageId":"8763gcri2c.fsf@meyering.net","threadId":"19232","inReplyTo":null,"subject":"[PATCH] format-patch let -k override a config-specified format.numbered","fromName":"Jim Meyering","fromEmail":"meyering@redhat.com","sentAt":"2009-05-07T16:31:07Z","receivedAt":"2009-05-07T16:31:07Z","isPatch":true,"sender":{"key":"jim@meyering.net","avatar":"https://avatars.githubusercontent.com/u/710630?v=4"},"body":"\nLet a command-line --keep-subject (-k) override a config-specified\nformat.numbered (--numbered (-n)), rather than provoking the\n\"-n and -k are mutually exclusive\" failure.\n* t4021-format-patch-numbered.sh: Test for the above\n---\n\nHere's a quick demo of the problem:\n\n  $ git config format.numbered true\n  $ git format-patch --stdout -1 -k > /dev/null\n  fatal: -n and -k are mutually exclusive.\n\nThis started when a colleague reported that \"git rebase master\" was failing\nwith a \"fatal: -n and -k are mutually exclusive\".  Stephen Tweedie discovered\nthat it was due to the format.numbered=true setting in ~/.gitconfig\nconflicting with the -k of the format-patch command run as part of\nthe rebase operation.  Here's a fix.\n\nStephen suggested an alternate patch in which rather than adding a\nnew variable, you'd use \"numbered = -1\" to indicate that the setting\noriginated in config.  Let me know if you'd prefer that.\n\n builtin-log.c                    |   14 +++++++++++++-\n t/t4021-format-patch-numbered.sh |    7 +++++++\n 2 files changed, 20 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 5eaec5d..f10cfeb 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -755,6 +755,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \tint cover_letter = 0;\n \tint boundary_count = 0;\n \tint no_binary_diff = 0;\n+\tint numbered_cmdline_opt = 0;\n \tstruct commit *origin = NULL, *head = NULL;\n \tconst char *in_reply_to = NULL;\n \tstruct patch_ids ids;\n@@ -786,8 +787,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\tif (!strcmp(argv[i], \"--stdout\"))\n \t\t\tuse_stdout = 1;\n \t\telse if (!strcmp(argv[i], \"-n\") ||\n-\t\t\t\t!strcmp(argv[i], \"--numbered\"))\n+\t\t\t\t!strcmp(argv[i], \"--numbered\")) {\n \t\t\tnumbered = 1;\n+\t\t\tnumbered_cmdline_opt = 1;\n+\t\t}\n \t\telse if (!strcmp(argv[i], \"-N\") ||\n \t\t\t\t!strcmp(argv[i], \"--no-numbered\")) {\n \t\t\tnumbered = 0;\n@@ -918,6 +921,15 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n\n \tif (start_number < 0)\n \t\tstart_number = 1;\n+\n+\t/*\n+\t * If numbered is set solely due to format.numbered in config,\n+\t * and it would conflict with --keep-subject (-k) from the\n+\t * command line, reset \"numbered\".\n+\t */\n+\tif (numbered && keep_subject && !numbered_cmdline_opt)\n+\t\tnumbered = 0;\n+\n \tif (numbered && keep_subject)\n \t\tdie (\"-n and -k are mutually exclusive.\");\n \tif (keep_subject && subject_prefix)\ndiff --git a/t/t4021-format-patch-numbered.sh b/t/t4021-format-patch-numbered.sh\nindex 390af23..9b6e1be 100755\n--- a/t/t4021-format-patch-numbered.sh\n+++ b/t/t4021-format-patch-numbered.sh\n@@ -86,6 +86,13 @@ test_expect_success 'format.numbered && --no-numbered' '\n\n '\n\n+test_expect_success 'format.numbered && --keep-subject' '\n+\n+\tgit format-patch --keep-subject --stdout HEAD^ >patch4a &&\n+\tgrep \"^Subject: Third\" patch4a\n+\n+'\n+\n test_expect_success 'format.numbered = auto' '\n\n \tgit config format.numbered auto\n--\n1.6.3.195.gad81\n"},{"id":"113295","messageId":"4A0384E0.4020506@gmail.com","threadId":"19232","inReplyTo":"8763gcri2c.fsf@meyering.net","subject":"Re: [PATCH] format-patch let -k override a config-specified format.numbered","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-05-08T01:03:28Z","receivedAt":"2009-05-08T01:03:28Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"Jim Meyering wrote:\n> This started when a colleague reported that \"git rebase master\" was failing\n> with a \"fatal: -n and -k are mutually exclusive\".  Stephen Tweedie discovered\n> that it was due to the format.numbered=true setting in ~/.gitconfig\n> conflicting with the -k of the format-patch command run as part of\n> the rebase operation.  Here's a fix.\n\nI think the real fix here should be in rebase. We should be passing\n--no-numbered to format-patch. I was expecting 'format.subjectprefix' to\ntrigger the same bug, but it seems we don't set subject_prefix=1 in this\ncase. I imagine fixing that can be done in a later patch.\n"},{"id":"113391","messageId":"7vbpq2da8v.fsf@alter.siamese.dyndns.org","threadId":"19232","inReplyTo":"8763gcri2c.fsf@meyering.net","subject":"Re: [PATCH] format-patch let -k override a config-specified format.numbered","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-09T07:08:16Z","receivedAt":"2009-05-09T07:08:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jim Meyering <meyering@redhat.com> writes:\n\n> Let a command-line --keep-subject (-k) override a config-specified\n> format.numbered (--numbered (-n)), rather than provoking the\n> \"-n and -k are mutually exclusive\" failure.\n> * t4021-format-patch-numbered.sh: Test for the above\n> ---\n\nSign-off?\n\n> Here's a quick demo of the problem:\n>\n>   $ git config format.numbered true\n>   $ git format-patch --stdout -1 -k > /dev/null\n>   fatal: -n and -k are mutually exclusive.\n>\n> This started when a colleague reported that \"git rebase master\" was failing\n> with a \"fatal: -n and -k are mutually exclusive\".  Stephen Tweedie discovered\n> that it was due to the format.numbered=true setting in ~/.gitconfig\n> conflicting with the -k of the format-patch command run as part of\n> the rebase operation.  Here's a fix.\n>\n> Stephen suggested an alternate patch in which rather than adding a\n> new variable, you'd use \"numbered = -1\" to indicate that the setting\n> originated in config.  Let me know if you'd prefer that.\n\nSome people might find an extra variable redundant or verbose, but I think\nyour approach is easier to follow and to the point, especially with the\nin-code comment.\n\nThanks.\n"},{"id":"113394","messageId":"878wl6ofu6.fsf@meyering.net","threadId":"19232","inReplyTo":"7vbpq2da8v.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] format-patch let -k override a config-specified format.numbered","fromName":"Jim Meyering","fromEmail":"jim@meyering.net","sentAt":"2009-05-09T08:12:01Z","receivedAt":"2009-05-09T08:12:01Z","isPatch":true,"sender":{"key":"jim@meyering.net","avatar":"https://avatars.githubusercontent.com/u/710630?v=4"},"body":"\nLet a command-line --keep-subject (-k) override a config-specified\nformat.numbered (--numbered (-n)), rather than provoking the\n\"-n and -k are mutually exclusive\" failure.\n* t4021-format-patch-numbered.sh: Test for the above\n\nSigned-off-by: Jim Meyering <meyering@redhat.com>\n---\nJunio C Hamano wrote:\n> Jim Meyering <meyering@redhat.com> writes:\n>> Let a command-line --keep-subject (-k) override a config-specified\n>> format.numbered (--numbered (-n)), rather than provoking the\n>> \"-n and -k are mutually exclusive\" failure.\n>> * t4021-format-patch-numbered.sh: Test for the above\n>> ---\n>\n> Sign-off?\n\nWhoops. Here you go.\n\n builtin-log.c                    |   14 +++++++++++++-\n t/t4021-format-patch-numbered.sh |    7 +++++++\n 2 files changed, 20 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 5eaec5d..f10cfeb 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -755,6 +755,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \tint cover_letter = 0;\n \tint boundary_count = 0;\n \tint no_binary_diff = 0;\n+\tint numbered_cmdline_opt = 0;\n \tstruct commit *origin = NULL, *head = NULL;\n \tconst char *in_reply_to = NULL;\n \tstruct patch_ids ids;\n@@ -786,8 +787,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\tif (!strcmp(argv[i], \"--stdout\"))\n \t\t\tuse_stdout = 1;\n \t\telse if (!strcmp(argv[i], \"-n\") ||\n-\t\t\t\t!strcmp(argv[i], \"--numbered\"))\n+\t\t\t\t!strcmp(argv[i], \"--numbered\")) {\n \t\t\tnumbered = 1;\n+\t\t\tnumbered_cmdline_opt = 1;\n+\t\t}\n \t\telse if (!strcmp(argv[i], \"-N\") ||\n \t\t\t\t!strcmp(argv[i], \"--no-numbered\")) {\n \t\t\tnumbered = 0;\n@@ -918,6 +921,15 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n\n \tif (start_number < 0)\n \t\tstart_number = 1;\n+\n+\t/*\n+\t * If numbered is set solely due to format.numbered in config,\n+\t * and it would conflict with --keep-subject (-k) from the\n+\t * command line, reset \"numbered\".\n+\t */\n+\tif (numbered && keep_subject && !numbered_cmdline_opt)\n+\t\tnumbered = 0;\n+\n \tif (numbered && keep_subject)\n \t\tdie (\"-n and -k are mutually exclusive.\");\n \tif (keep_subject && subject_prefix)\ndiff --git a/t/t4021-format-patch-numbered.sh b/t/t4021-format-patch-numbered.sh\nindex 390af23..9b6e1be 100755\n--- a/t/t4021-format-patch-numbered.sh\n+++ b/t/t4021-format-patch-numbered.sh\n@@ -86,6 +86,13 @@ test_expect_success 'format.numbered && --no-numbered' '\n\n '\n\n+test_expect_success 'format.numbered && --keep-subject' '\n+\n+\tgit format-patch --keep-subject --stdout HEAD^ >patch4a &&\n+\tgrep \"^Subject: Third\" patch4a\n+\n+'\n+\n test_expect_success 'format.numbered = auto' '\n\n \tgit config format.numbered auto\n--\n1.6.3.195.gad81\n"}]}