git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] format-patch let -k override a config-specified format.numbered
@ 2009-05-07 16:31 Jim Meyering
  2009-05-08  1:03 ` Stephen Boyd
  2009-05-09  7:08 ` Junio C Hamano
  0 siblings, 2 replies; 4+ messages in thread
From: Jim Meyering @ 2009-05-07 16:31 UTC (permalink / raw)
  To: git list; +Cc: Stephen C. Tweedie


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
---

Here's a quick demo of the problem:

  $ git config format.numbered true
  $ git format-patch --stdout -1 -k > /dev/null
  fatal: -n and -k are mutually exclusive.

This started when a colleague reported that "git rebase master" was failing
with a "fatal: -n and -k are mutually exclusive".  Stephen Tweedie discovered
that it was due to the format.numbered=true setting in ~/.gitconfig
conflicting with the -k of the format-patch command run as part of
the rebase operation.  Here's a fix.

Stephen suggested an alternate patch in which rather than adding a
new variable, you'd use "numbered = -1" to indicate that the setting
originated in config.  Let me know if you'd prefer that.

 builtin-log.c                    |   14 +++++++++++++-
 t/t4021-format-patch-numbered.sh |    7 +++++++
 2 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/builtin-log.c b/builtin-log.c
index 5eaec5d..f10cfeb 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -755,6 +755,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	int cover_letter = 0;
 	int boundary_count = 0;
 	int no_binary_diff = 0;
+	int numbered_cmdline_opt = 0;
 	struct commit *origin = NULL, *head = NULL;
 	const char *in_reply_to = NULL;
 	struct patch_ids ids;
@@ -786,8 +787,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		if (!strcmp(argv[i], "--stdout"))
 			use_stdout = 1;
 		else if (!strcmp(argv[i], "-n") ||
-				!strcmp(argv[i], "--numbered"))
+				!strcmp(argv[i], "--numbered")) {
 			numbered = 1;
+			numbered_cmdline_opt = 1;
+		}
 		else if (!strcmp(argv[i], "-N") ||
 				!strcmp(argv[i], "--no-numbered")) {
 			numbered = 0;
@@ -918,6 +921,15 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)

 	if (start_number < 0)
 		start_number = 1;
+
+	/*
+	 * If numbered is set solely due to format.numbered in config,
+	 * and it would conflict with --keep-subject (-k) from the
+	 * command line, reset "numbered".
+	 */
+	if (numbered && keep_subject && !numbered_cmdline_opt)
+		numbered = 0;
+
 	if (numbered && keep_subject)
 		die ("-n and -k are mutually exclusive.");
 	if (keep_subject && subject_prefix)
diff --git a/t/t4021-format-patch-numbered.sh b/t/t4021-format-patch-numbered.sh
index 390af23..9b6e1be 100755
--- a/t/t4021-format-patch-numbered.sh
+++ b/t/t4021-format-patch-numbered.sh
@@ -86,6 +86,13 @@ test_expect_success 'format.numbered && --no-numbered' '

 '

+test_expect_success 'format.numbered && --keep-subject' '
+
+	git format-patch --keep-subject --stdout HEAD^ >patch4a &&
+	grep "^Subject: Third" patch4a
+
+'
+
 test_expect_success 'format.numbered = auto' '

 	git config format.numbered auto
--
1.6.3.195.gad81

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] format-patch let -k override a config-specified format.numbered
  2009-05-07 16:31 [PATCH] format-patch let -k override a config-specified format.numbered Jim Meyering
@ 2009-05-08  1:03 ` Stephen Boyd
  2009-05-09  7:08 ` Junio C Hamano
  1 sibling, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2009-05-08  1:03 UTC (permalink / raw)
  To: Jim Meyering; +Cc: git list, Stephen C. Tweedie

Jim Meyering wrote:
> This started when a colleague reported that "git rebase master" was failing
> with a "fatal: -n and -k are mutually exclusive".  Stephen Tweedie discovered
> that it was due to the format.numbered=true setting in ~/.gitconfig
> conflicting with the -k of the format-patch command run as part of
> the rebase operation.  Here's a fix.

I think the real fix here should be in rebase. We should be passing
--no-numbered to format-patch. I was expecting 'format.subjectprefix' to
trigger the same bug, but it seems we don't set subject_prefix=1 in this
case. I imagine fixing that can be done in a later patch.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] format-patch let -k override a config-specified format.numbered
  2009-05-07 16:31 [PATCH] format-patch let -k override a config-specified format.numbered Jim Meyering
  2009-05-08  1:03 ` Stephen Boyd
@ 2009-05-09  7:08 ` Junio C Hamano
  2009-05-09  8:12   ` Jim Meyering
  1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2009-05-09  7:08 UTC (permalink / raw)
  To: Jim Meyering; +Cc: git list, Stephen C. Tweedie

Jim Meyering <meyering@redhat.com> writes:

> 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
> ---

Sign-off?

> Here's a quick demo of the problem:
>
>   $ git config format.numbered true
>   $ git format-patch --stdout -1 -k > /dev/null
>   fatal: -n and -k are mutually exclusive.
>
> This started when a colleague reported that "git rebase master" was failing
> with a "fatal: -n and -k are mutually exclusive".  Stephen Tweedie discovered
> that it was due to the format.numbered=true setting in ~/.gitconfig
> conflicting with the -k of the format-patch command run as part of
> the rebase operation.  Here's a fix.
>
> Stephen suggested an alternate patch in which rather than adding a
> new variable, you'd use "numbered = -1" to indicate that the setting
> originated in config.  Let me know if you'd prefer that.

Some people might find an extra variable redundant or verbose, but I think
your approach is easier to follow and to the point, especially with the
in-code comment.

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] format-patch let -k override a config-specified format.numbered
  2009-05-09  7:08 ` Junio C Hamano
@ 2009-05-09  8:12   ` Jim Meyering
  0 siblings, 0 replies; 4+ messages in thread
From: Jim Meyering @ 2009-05-09  8:12 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git list, Stephen C. Tweedie


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 <meyering@redhat.com>
---
Junio C Hamano wrote:
> Jim Meyering <meyering@redhat.com> writes:
>> 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
>> ---
>
> Sign-off?

Whoops. Here you go.

 builtin-log.c                    |   14 +++++++++++++-
 t/t4021-format-patch-numbered.sh |    7 +++++++
 2 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/builtin-log.c b/builtin-log.c
index 5eaec5d..f10cfeb 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -755,6 +755,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	int cover_letter = 0;
 	int boundary_count = 0;
 	int no_binary_diff = 0;
+	int numbered_cmdline_opt = 0;
 	struct commit *origin = NULL, *head = NULL;
 	const char *in_reply_to = NULL;
 	struct patch_ids ids;
@@ -786,8 +787,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		if (!strcmp(argv[i], "--stdout"))
 			use_stdout = 1;
 		else if (!strcmp(argv[i], "-n") ||
-				!strcmp(argv[i], "--numbered"))
+				!strcmp(argv[i], "--numbered")) {
 			numbered = 1;
+			numbered_cmdline_opt = 1;
+		}
 		else if (!strcmp(argv[i], "-N") ||
 				!strcmp(argv[i], "--no-numbered")) {
 			numbered = 0;
@@ -918,6 +921,15 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)

 	if (start_number < 0)
 		start_number = 1;
+
+	/*
+	 * If numbered is set solely due to format.numbered in config,
+	 * and it would conflict with --keep-subject (-k) from the
+	 * command line, reset "numbered".
+	 */
+	if (numbered && keep_subject && !numbered_cmdline_opt)
+		numbered = 0;
+
 	if (numbered && keep_subject)
 		die ("-n and -k are mutually exclusive.");
 	if (keep_subject && subject_prefix)
diff --git a/t/t4021-format-patch-numbered.sh b/t/t4021-format-patch-numbered.sh
index 390af23..9b6e1be 100755
--- a/t/t4021-format-patch-numbered.sh
+++ b/t/t4021-format-patch-numbered.sh
@@ -86,6 +86,13 @@ test_expect_success 'format.numbered && --no-numbered' '

 '

+test_expect_success 'format.numbered && --keep-subject' '
+
+	git format-patch --keep-subject --stdout HEAD^ >patch4a &&
+	grep "^Subject: Third" patch4a
+
+'
+
 test_expect_success 'format.numbered = auto' '

 	git config format.numbered auto
--
1.6.3.195.gad81

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-05-09  8:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-07 16:31 [PATCH] format-patch let -k override a config-specified format.numbered Jim Meyering
2009-05-08  1:03 ` Stephen Boyd
2009-05-09  7:08 ` Junio C Hamano
2009-05-09  8:12   ` Jim Meyering

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).