git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/2] commit doc: document that -c, -C, -F and --fixup with -m error
@ 2017-12-20 19:38 Ævar Arnfjörð Bjarmason
  2017-12-20 19:38 ` [PATCH 2/2] commit: add support for --fixup <commit> -m"<extra message>" Ævar Arnfjörð Bjarmason
  2017-12-20 19:45 ` [PATCH 1/2] commit doc: document that -c, -C, -F and --fixup with -m error Eric Sunshine
  0 siblings, 2 replies; 16+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2017-12-20 19:38 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Pat Notz, Ævar Arnfjörð Bjarmason

Document that providing any of -c, -C, -F and --fixup along with -m
will result in an error. Some variant of this has been errored about
explicitly since 0c091296c0 ("git-commit: log parameter updates.",
2005-08-08), but the documentation was never updated to reflect this.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 Documentation/git-commit.txt | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 8c74a2ca03..df83176314 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -144,6 +144,9 @@ OPTIONS
 	Use the given <msg> as the commit message.
 	If multiple `-m` options are given, their values are
 	concatenated as separate paragraphs.
++
+Combining the `-m` option and any of `-c`, `-C`, `-F` or `--fixup`
+will result in an error.
 
 -t <file>::
 --template=<file>::
-- 
2.15.1.424.g9478a66081


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

* [PATCH 2/2] commit: add support for --fixup <commit> -m"<extra message>"
  2017-12-20 19:38 [PATCH 1/2] commit doc: document that -c, -C, -F and --fixup with -m error Ævar Arnfjörð Bjarmason
@ 2017-12-20 19:38 ` Ævar Arnfjörð Bjarmason
  2017-12-20 20:03   ` Eric Sunshine
  2017-12-20 19:45 ` [PATCH 1/2] commit doc: document that -c, -C, -F and --fixup with -m error Eric Sunshine
  1 sibling, 1 reply; 16+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2017-12-20 19:38 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Pat Notz, Ævar Arnfjörð Bjarmason

Add support for supplying the -m option with --fixup. Doing so has
errored out ever since --fixup was introduced. Before this, the only
way to amend the fixup message while committing was to use --edit and
amend it in the editor.

The use-case for this feature is one of:

 * Leaving a quick note to self when creating a --fixup commit when
   it's not self-evident why the commit should be squashed without a
   note into another one.

 * (Ab)using the --fixup feature to "fix up" commits that have already
   been pushed to a branch that doesn't allow non-fast-forwards,
   i.e. just noting "this should have been part of that other commit",
   and if the history ever got rewritten in the future the two should
   be combined.

   In such a case you might want to leave a small message,
   e.g. "forgot this part, which broke XYZ".

When the --fixup option was initially added the "Option -m cannot be
combined" error was expanded from -c, -C and -F to also include
--fixup[1]

Those options could also support combining with -m, but given what
they do I can't think of a good use-case for doing that, so I have not
made the more invasive change of splitting up the logic in commit.c to
first act on those, and then on -m options.

1. d71b8ba7c9 ("commit: --fixup option for use with rebase
   --autosquash", 2010-11-02)

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 Documentation/git-commit.txt | 4 ++--
 builtin/commit.c             | 8 +++++---
 t/t7500-commit.sh            | 9 ++++++++-
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index df83176314..4489677fd1 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -145,8 +145,8 @@ OPTIONS
 	If multiple `-m` options are given, their values are
 	concatenated as separate paragraphs.
 +
-Combining the `-m` option and any of `-c`, `-C`, `-F` or `--fixup`
-will result in an error.
+Combining the `-m` option and any of `-c`, `-C` or `-F` will result in
+an error.
 
 -t <file>::
 --template=<file>::
diff --git a/builtin/commit.c b/builtin/commit.c
index 8a87701414..4e68394391 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -701,7 +701,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		}
 	}
 
-	if (have_option_m) {
+	if (have_option_m && !fixup_message) {
 		strbuf_addbuf(&sb, &message);
 		hook_arg1 = "message";
 	} else if (logfile && !strcmp(logfile, "-")) {
@@ -731,6 +731,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		ctx.output_encoding = get_commit_output_encoding();
 		format_commit_message(commit, "fixup! %s\n\n",
 				      &sb, &ctx);
+		if (have_option_m)
+			strbuf_addbuf(&sb, &message);
 		hook_arg1 = "message";
 	} else if (!stat(git_path_merge_msg(), &statbuf)) {
 		/*
@@ -1197,8 +1199,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
 		f++;
 	if (f > 1)
 		die(_("Only one of -c/-C/-F/--fixup can be used."));
-	if (have_option_m && f > 0)
-		die((_("Option -m cannot be combined with -c/-C/-F/--fixup.")));
+	if (have_option_m && (edit_message || use_message || logfile))
+		die((_("Option -m cannot be combined with -c/-C/-F.")));
 	if (f || have_option_m)
 		template_file = NULL;
 	if (edit_message)
diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
index 5739d3ed23..2d95778b74 100755
--- a/t/t7500-commit.sh
+++ b/t/t7500-commit.sh
@@ -272,6 +272,14 @@ test_expect_success 'commit --fixup provides correct one-line commit message' '
 	commit_msg_is "fixup! target message subject line"
 '
 
+test_expect_success 'commit --fixup -m"something" -m"extra"' '
+	commit_for_rebase_autosquash_setup &&
+	git commit --fixup HEAD~1 -m"something" -m"extra" &&
+	commit_msg_is "fixup! target message subject linesomething
+
+extra"
+'
+
 test_expect_success 'commit --squash works with -F' '
 	commit_for_rebase_autosquash_setup &&
 	echo "log message from file" >msgfile &&
@@ -325,7 +333,6 @@ test_expect_success 'invalid message options when using --fixup' '
 	test_must_fail git commit --fixup HEAD~1 --squash HEAD~2 &&
 	test_must_fail git commit --fixup HEAD~1 -C HEAD~2 &&
 	test_must_fail git commit --fixup HEAD~1 -c HEAD~2 &&
-	test_must_fail git commit --fixup HEAD~1 -m "cmdline message" &&
 	test_must_fail git commit --fixup HEAD~1 -F log
 '
 
-- 
2.15.1.424.g9478a66081


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

* Re: [PATCH 1/2] commit doc: document that -c, -C, -F and --fixup with -m error
  2017-12-20 19:38 [PATCH 1/2] commit doc: document that -c, -C, -F and --fixup with -m error Ævar Arnfjörð Bjarmason
  2017-12-20 19:38 ` [PATCH 2/2] commit: add support for --fixup <commit> -m"<extra message>" Ævar Arnfjörð Bjarmason
@ 2017-12-20 19:45 ` Eric Sunshine
  1 sibling, 0 replies; 16+ messages in thread
From: Eric Sunshine @ 2017-12-20 19:45 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: Git List, Junio C Hamano, Pat Notz

On Wed, Dec 20, 2017 at 2:38 PM, Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> Document that providing any of -c, -C, -F and --fixup along with -m
> will result in an error. Some variant of this has been errored about
> explicitly since 0c091296c0 ("git-commit: log parameter updates.",
> 2005-08-08), but the documentation was never updated to reflect this.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
> @@ -144,6 +144,9 @@ OPTIONS
> ++
> +Combining the `-m` option and any of `-c`, `-C`, `-F` or `--fixup`
> +will result in an error.

This sounds a bit scary, as if there is something wrong with Git.
Perhaps say instead that they are "mutually exclusive":

    The `-m` option is mutually exclusive with `-c`, `-C`, `-F`, and
    `--fixup`.

Or something.

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

* Re: [PATCH 2/2] commit: add support for --fixup <commit> -m"<extra message>"
  2017-12-20 19:38 ` [PATCH 2/2] commit: add support for --fixup <commit> -m"<extra message>" Ævar Arnfjörð Bjarmason
@ 2017-12-20 20:03   ` Eric Sunshine
  2017-12-20 21:40     ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 16+ messages in thread
From: Eric Sunshine @ 2017-12-20 20:03 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: Git List, Junio C Hamano, Pat Notz

On Wed, Dec 20, 2017 at 2:38 PM, Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> Add support for supplying the -m option with --fixup. Doing so has
> errored out ever since --fixup was introduced. Before this, the only
> way to amend the fixup message while committing was to use --edit and
> amend it in the editor.

I can't tell, based upon this description, if '-m<msg> --edit' is a
valid combination and, if so, does it correctly open the editor after
appending <msg>?

> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
> @@ -272,6 +272,14 @@ test_expect_success 'commit --fixup provides correct one-line commit message' '
>         commit_msg_is "fixup! target message subject line"
>  '
>
> +test_expect_success 'commit --fixup -m"something" -m"extra"' '
> +       commit_for_rebase_autosquash_setup &&
> +       git commit --fixup HEAD~1 -m"something" -m"extra" &&
> +       commit_msg_is "fixup! target message subject linesomething
> +
> +extra"
> +'

Hmm, so the first -m appended to the "fixup!" line, but the second -m
appended after a blank line? That doesn't seem very intuitive.

Also, doesn't the text following "fixup!" need to exactly match the
summary line of the commit message in order for "git rebase -i
--autosquash" to work? Am I overlooking something obvious?

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

* Re: [PATCH 2/2] commit: add support for --fixup <commit> -m"<extra message>"
  2017-12-20 20:03   ` Eric Sunshine
@ 2017-12-20 21:40     ` Ævar Arnfjörð Bjarmason
  2017-12-20 21:50       ` Eric Sunshine
  0 siblings, 1 reply; 16+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2017-12-20 21:40 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git List, Junio C Hamano, Pat Notz


On Wed, Dec 20 2017, Eric Sunshine jotted:

> On Wed, Dec 20, 2017 at 2:38 PM, Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
>> Add support for supplying the -m option with --fixup. Doing so has
>> errored out ever since --fixup was introduced. Before this, the only
>> way to amend the fixup message while committing was to use --edit and
>> amend it in the editor.
>
> I can't tell, based upon this description, if '-m<msg> --edit' is a
> valid combination and, if so, does it correctly open the editor after
> appending <msg>?

Yes, that's works as expected for all the options, and this doesn't
break that.

>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> ---
>> diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
>> @@ -272,6 +272,14 @@ test_expect_success 'commit --fixup provides correct one-line commit message' '
>>         commit_msg_is "fixup! target message subject line"
>>  '
>>
>> +test_expect_success 'commit --fixup -m"something" -m"extra"' '
>> +       commit_for_rebase_autosquash_setup &&
>> +       git commit --fixup HEAD~1 -m"something" -m"extra" &&
>> +       commit_msg_is "fixup! target message subject linesomething
>> +
>> +extra"
>> +'
>
> Hmm, so the first -m appended to the "fixup!" line, but the second -m
> appended after a blank line? That doesn't seem very intuitive.
>
> Also, doesn't the text following "fixup!" need to exactly match the
> summary line of the commit message in order for "git rebase -i
> --autosquash" to work? Am I overlooking something obvious?

It does the right thing and it's actually
"$fixup_line\n\n$first_m\n\n$second_m" etc. It's just that this
commit_msg_is function is testing against the "%s%b" format, so the
first line of the body comes right after the subject.

Thanks for the review of both patches. I'll clarify the points raised in
commit message for v2 pending further feedback.

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

* Re: [PATCH 2/2] commit: add support for --fixup <commit> -m"<extra message>"
  2017-12-20 21:40     ` Ævar Arnfjörð Bjarmason
@ 2017-12-20 21:50       ` Eric Sunshine
  2017-12-22 16:00         ` [PATCH v2 0/2] support -m"<msg>" combined with commit --fixup Ævar Arnfjörð Bjarmason
                           ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Eric Sunshine @ 2017-12-20 21:50 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: Git List, Junio C Hamano, Pat Notz

On Wed, Dec 20, 2017 at 4:40 PM, Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> On Wed, Dec 20 2017, Eric Sunshine jotted:
>> On Wed, Dec 20, 2017 at 2:38 PM, Ævar Arnfjörð Bjarmason
>> <avarab@gmail.com> wrote:
>>> +test_expect_success 'commit --fixup -m"something" -m"extra"' '
>>> +       commit_for_rebase_autosquash_setup &&
>>> +       git commit --fixup HEAD~1 -m"something" -m"extra" &&
>>> +       commit_msg_is "fixup! target message subject linesomething
>>> +
>>> +extra"
>>> +'
>>
>> Hmm, so the first -m appended to the "fixup!" line, but the second -m
>> appended after a blank line? That doesn't seem very intuitive.
>>
>> Also, doesn't the text following "fixup!" need to exactly match the
>> summary line of the commit message in order for "git rebase -i
>> --autosquash" to work? Am I overlooking something obvious?
>
> It does the right thing and it's actually
> "$fixup_line\n\n$first_m\n\n$second_m" etc. It's just that this
> commit_msg_is function is testing against the "%s%b" format, so the
> first line of the body comes right after the subject.

Thanks for explaining. I guess I should have delved into
commit_msg_is() before commenting.

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

* [PATCH v2 0/2] support -m"<msg>" combined with commit --fixup
  2017-12-20 21:50       ` Eric Sunshine
@ 2017-12-22 16:00         ` Ævar Arnfjörð Bjarmason
  2017-12-22 19:53           ` Eric Sunshine
  2017-12-22 16:00         ` [PATCH v2 1/2] commit doc: document that -c, -C, -F and --fixup with -m error Ævar Arnfjörð Bjarmason
  2017-12-22 20:41         ` [PATCH v2 2/2] commit: add support for --fixup <commit> -m"<extra message>" Ævar Arnfjörð Bjarmason
  2 siblings, 1 reply; 16+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2017-12-22 16:00 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Pat Notz, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

Here's a hopefully ready to apply v2 incorporating feedback from Eric
(thanks!). A tbdiff with v1 follows below.

Ævar Arnfjörð Bjarmason (2):
  commit doc: document that -c, -C, -F and --fixup with -m error
  commit: add support for --fixup <commit> -m"<extra message>"

 Documentation/git-commit.txt | 2 ++
 builtin/commit.c             | 8 +++++---
 t/t7500-commit.sh            | 9 ++++++++-
 3 files changed, 15 insertions(+), 4 deletions(-)

1: 7d5e2531ee ! 1: 82333992ec commit doc: document that -c, -C, -F and --fixup with -m error
    @@ -7,6 +7,7 @@
         explicitly since 0c091296c0 ("git-commit: log parameter updates.",
         2005-08-08), but the documentation was never updated to reflect this.
         
    +    Wording-by: Eric Sunshine <sunshine@sunshineco.com>
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
     diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
    @@ -17,8 +18,8 @@
      	If multiple `-m` options are given, their values are
      	concatenated as separate paragraphs.
     ++
    -+Combining the `-m` option and any of `-c`, `-C`, `-F` or `--fixup`
    -+will result in an error.
    ++The `-m` option is mutually exclusive with `-c`, `-C`, `-F`, and
    ++`--fixup`.
      
      -t <file>::
      --template=<file>::
2: bd78a211ed ! 2: 780de6e042 commit: add support for --fixup <commit> -m"<extra message>"
    @@ -22,6 +22,21 @@
            In such a case you might want to leave a small message,
            e.g. "forgot this part, which broke XYZ".
         
    +    With this, --fixup <commit> -m"More" -m"Details" will result in a
    +    commit message like:
    +    
    +        !fixup <subject of <commit>>
    +    
    +        More
    +    
    +        Details
    +    
    +    The reason the test being added here seems to squash "More" at the end
    +    of the subject line of the commit being fixed up is because the test
    +    code is using "%s%b" so the body immediately follows the subject, it's
    +    not a bug in this code, and other tests t7500-commit.sh do the same
    +    thing.
    +    
         When the --fixup option was initially added the "Option -m cannot be
         combined" error was expanded from -c, -C and -F to also include
         --fixup[1]
    @@ -34,6 +49,7 @@
         1. d71b8ba7c9 ("commit: --fixup option for use with rebase
            --autosquash", 2010-11-02)
         
    +    Helped-by: Eric Sunshine <sunshine@sunshineco.com>
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
     diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
    @@ -43,10 +59,9 @@
      	If multiple `-m` options are given, their values are
      	concatenated as separate paragraphs.
      +
    --Combining the `-m` option and any of `-c`, `-C`, `-F` or `--fixup`
    --will result in an error.
    -+Combining the `-m` option and any of `-c`, `-C` or `-F` will result in
    -+an error.
    +-The `-m` option is mutually exclusive with `-c`, `-C`, `-F`, and
    +-`--fixup`.
    ++The `-m` option is mutually exclusive with `-c`, `-C`, and `-F`.
      
      -t <file>::
      --template=<file>::

-- 
2.15.1.424.g9478a66081



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

* [PATCH v2 1/2] commit doc: document that -c, -C, -F and --fixup with -m error
  2017-12-20 21:50       ` Eric Sunshine
  2017-12-22 16:00         ` [PATCH v2 0/2] support -m"<msg>" combined with commit --fixup Ævar Arnfjörð Bjarmason
@ 2017-12-22 16:00         ` Ævar Arnfjörð Bjarmason
  2017-12-22 20:41         ` [PATCH v2 2/2] commit: add support for --fixup <commit> -m"<extra message>" Ævar Arnfjörð Bjarmason
  2 siblings, 0 replies; 16+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2017-12-22 16:00 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Pat Notz, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

Document that providing any of -c, -C, -F and --fixup along with -m
will result in an error. Some variant of this has been errored about
explicitly since 0c091296c0 ("git-commit: log parameter updates.",
2005-08-08), but the documentation was never updated to reflect this.

Wording-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 Documentation/git-commit.txt | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 8c74a2ca03..3fbb7352bc 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -144,6 +144,9 @@ OPTIONS
 	Use the given <msg> as the commit message.
 	If multiple `-m` options are given, their values are
 	concatenated as separate paragraphs.
++
+The `-m` option is mutually exclusive with `-c`, `-C`, `-F`, and
+`--fixup`.
 
 -t <file>::
 --template=<file>::
-- 
2.15.1.424.g9478a66081


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

* Re: [PATCH v2 0/2] support -m"<msg>" combined with commit --fixup
  2017-12-22 16:00         ` [PATCH v2 0/2] support -m"<msg>" combined with commit --fixup Ævar Arnfjörð Bjarmason
@ 2017-12-22 19:53           ` Eric Sunshine
  2017-12-22 20:43             ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 16+ messages in thread
From: Eric Sunshine @ 2017-12-22 19:53 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: Git List, Junio C Hamano, Pat Notz

On Fri, Dec 22, 2017 at 11:00 AM, Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> Here's a hopefully ready to apply v2 incorporating feedback from Eric
> (thanks!). A tbdiff with v1 follows below.
>
> Ævar Arnfjörð Bjarmason (2):
>   commit doc: document that -c, -C, -F and --fixup with -m error
>   commit: add support for --fixup <commit> -m"<extra message>"

Patch 2/2 doesn't seem to have made it to the list...

> 2: bd78a211ed ! 2: 780de6e042 commit: add support for --fixup <commit> -m"<extra message>"
>     @@ -22,6 +22,21 @@
>             In such a case you might want to leave a small message,
>             e.g. "forgot this part, which broke XYZ".
>
>     +    With this, --fixup <commit> -m"More" -m"Details" will result in a
>     +    commit message like:
>     +
>     +        !fixup <subject of <commit>>
>     +
>     +        More
>     +
>     +        Details
>     +
>     +    The reason the test being added here seems to squash "More" at the end
>     +    of the subject line of the commit being fixed up is because the test
>     +    code is using "%s%b" so the body immediately follows the subject, it's
>     +    not a bug in this code, and other tests t7500-commit.sh do the same
>     +    thing.

Did you also intend to mention something about --edit still working
with -m? (Or do we assume that people will understand automatically
that it does?)

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

* [PATCH v2 2/2] commit: add support for --fixup <commit> -m"<extra message>"
  2017-12-20 21:50       ` Eric Sunshine
  2017-12-22 16:00         ` [PATCH v2 0/2] support -m"<msg>" combined with commit --fixup Ævar Arnfjörð Bjarmason
  2017-12-22 16:00         ` [PATCH v2 1/2] commit doc: document that -c, -C, -F and --fixup with -m error Ævar Arnfjörð Bjarmason
@ 2017-12-22 20:41         ` Ævar Arnfjörð Bjarmason
  2017-12-22 21:28           ` Junio C Hamano
  2 siblings, 1 reply; 16+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2017-12-22 20:41 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Pat Notz, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

Add support for supplying the -m option with --fixup. Doing so has
errored out ever since --fixup was introduced. Before this, the only
way to amend the fixup message while committing was to use --edit and
amend it in the editor.

The use-case for this feature is one of:

 * Leaving a quick note to self when creating a --fixup commit when
   it's not self-evident why the commit should be squashed without a
   note into another one.

 * (Ab)using the --fixup feature to "fix up" commits that have already
   been pushed to a branch that doesn't allow non-fast-forwards,
   i.e. just noting "this should have been part of that other commit",
   and if the history ever got rewritten in the future the two should
   be combined.

   In such a case you might want to leave a small message,
   e.g. "forgot this part, which broke XYZ".

With this, --fixup <commit> -m"More" -m"Details" will result in a
commit message like:

    !fixup <subject of <commit>>

    More

    Details

The reason the test being added here seems to squash "More" at the end
of the subject line of the commit being fixed up is because the test
code is using "%s%b" so the body immediately follows the subject, it's
not a bug in this code, and other tests t7500-commit.sh do the same
thing.

When the --fixup option was initially added the "Option -m cannot be
combined" error was expanded from -c, -C and -F to also include
--fixup[1]

Those options could also support combining with -m, but given what
they do I can't think of a good use-case for doing that, so I have not
made the more invasive change of splitting up the logic in commit.c to
first act on those, and then on -m options.

1. d71b8ba7c9 ("commit: --fixup option for use with rebase
   --autosquash", 2010-11-02)

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 Documentation/git-commit.txt | 3 +--
 builtin/commit.c             | 8 +++++---
 t/t7500-commit.sh            | 9 ++++++++-
 3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 3fbb7352bc..f970a43422 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -145,8 +145,7 @@ OPTIONS
 	If multiple `-m` options are given, their values are
 	concatenated as separate paragraphs.
 +
-The `-m` option is mutually exclusive with `-c`, `-C`, `-F`, and
-`--fixup`.
+The `-m` option is mutually exclusive with `-c`, `-C`, and `-F`.
 
 -t <file>::
 --template=<file>::
diff --git a/builtin/commit.c b/builtin/commit.c
index 8a87701414..4e68394391 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -701,7 +701,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		}
 	}
 
-	if (have_option_m) {
+	if (have_option_m && !fixup_message) {
 		strbuf_addbuf(&sb, &message);
 		hook_arg1 = "message";
 	} else if (logfile && !strcmp(logfile, "-")) {
@@ -731,6 +731,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		ctx.output_encoding = get_commit_output_encoding();
 		format_commit_message(commit, "fixup! %s\n\n",
 				      &sb, &ctx);
+		if (have_option_m)
+			strbuf_addbuf(&sb, &message);
 		hook_arg1 = "message";
 	} else if (!stat(git_path_merge_msg(), &statbuf)) {
 		/*
@@ -1197,8 +1199,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
 		f++;
 	if (f > 1)
 		die(_("Only one of -c/-C/-F/--fixup can be used."));
-	if (have_option_m && f > 0)
-		die((_("Option -m cannot be combined with -c/-C/-F/--fixup.")));
+	if (have_option_m && (edit_message || use_message || logfile))
+		die((_("Option -m cannot be combined with -c/-C/-F.")));
 	if (f || have_option_m)
 		template_file = NULL;
 	if (edit_message)
diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
index 5739d3ed23..2d95778b74 100755
--- a/t/t7500-commit.sh
+++ b/t/t7500-commit.sh
@@ -272,6 +272,14 @@ test_expect_success 'commit --fixup provides correct one-line commit message' '
 	commit_msg_is "fixup! target message subject line"
 '
 
+test_expect_success 'commit --fixup -m"something" -m"extra"' '
+	commit_for_rebase_autosquash_setup &&
+	git commit --fixup HEAD~1 -m"something" -m"extra" &&
+	commit_msg_is "fixup! target message subject linesomething
+
+extra"
+'
+
 test_expect_success 'commit --squash works with -F' '
 	commit_for_rebase_autosquash_setup &&
 	echo "log message from file" >msgfile &&
@@ -325,7 +333,6 @@ test_expect_success 'invalid message options when using --fixup' '
 	test_must_fail git commit --fixup HEAD~1 --squash HEAD~2 &&
 	test_must_fail git commit --fixup HEAD~1 -C HEAD~2 &&
 	test_must_fail git commit --fixup HEAD~1 -c HEAD~2 &&
-	test_must_fail git commit --fixup HEAD~1 -m "cmdline message" &&
 	test_must_fail git commit --fixup HEAD~1 -F log
 '
 
-- 
2.15.1.424.g9478a66081


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

* Re: [PATCH v2 0/2] support -m"<msg>" combined with commit --fixup
  2017-12-22 19:53           ` Eric Sunshine
@ 2017-12-22 20:43             ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 16+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2017-12-22 20:43 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git List, Junio C Hamano, Pat Notz


On Fri, Dec 22 2017, Eric Sunshine jotted:

> On Fri, Dec 22, 2017 at 11:00 AM, Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
>> Here's a hopefully ready to apply v2 incorporating feedback from Eric
>> (thanks!). A tbdiff with v1 follows below.
>>
>> Ævar Arnfjörð Bjarmason (2):
>>   commit doc: document that -c, -C, -F and --fixup with -m error
>>   commit: add support for --fixup <commit> -m"<extra message>"
>
> Patch 2/2 doesn't seem to have made it to the list...

Oops, here it comes.

>> 2: bd78a211ed ! 2: 780de6e042 commit: add support for --fixup <commit> -m"<extra message>"
>>     @@ -22,6 +22,21 @@
>>             In such a case you might want to leave a small message,
>>             e.g. "forgot this part, which broke XYZ".
>>
>>     +    With this, --fixup <commit> -m"More" -m"Details" will result in a
>>     +    commit message like:
>>     +
>>     +        !fixup <subject of <commit>>
>>     +
>>     +        More
>>     +
>>     +        Details
>>     +
>>     +    The reason the test being added here seems to squash "More" at the end
>>     +    of the subject line of the commit being fixed up is because the test
>>     +    code is using "%s%b" so the body immediately follows the subject, it's
>>     +    not a bug in this code, and other tests t7500-commit.sh do the same
>>     +    thing.
>
> Did you also intend to mention something about --edit still working
> with -m? (Or do we assume that people will understand automatically
> that it does?)

I thought it was clear enough since it works with --fixup now and with
everything else, and the commit message was already getting long
enough...

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

* Re: [PATCH v2 2/2] commit: add support for --fixup <commit> -m"<extra message>"
  2017-12-22 20:41         ` [PATCH v2 2/2] commit: add support for --fixup <commit> -m"<extra message>" Ævar Arnfjörð Bjarmason
@ 2017-12-22 21:28           ` Junio C Hamano
  2017-12-22 21:29             ` Junio C Hamano
  2017-12-22 21:58             ` Ævar Arnfjörð Bjarmason
  0 siblings, 2 replies; 16+ messages in thread
From: Junio C Hamano @ 2017-12-22 21:28 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: git, Pat Notz, Eric Sunshine

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> Those options could also support combining with -m, but given what
> they do I can't think of a good use-case for doing that, so I have not
> made the more invasive change of splitting up the logic in commit.c to
> first act on those, and then on -m options.
>
> 1. d71b8ba7c9 ("commit: --fixup option for use with rebase
>    --autosquash", 2010-11-02)

To be fair, when "rebase --autosquash -i" is run (which is why you
would use --fixup in the first place), the log message of the fixup
one is used only for locating which one is to be corrected, and the
contents of the log message is discarded.  So "given what it does",
I can't think of a good use-case for using --fixup and -m together,
either.  So "nobody immediately thought of it when it was added" is
certainly not a reason to later make the combination possible.

But I personally am moderately negative on one of these two imagined
use cases.

> Add support for supplying the -m option with --fixup. Doing so has
> errored out ever since --fixup was introduced. Before this, the only
> way to amend the fixup message while committing was to use --edit and
> amend it in the editor.
>
> The use-case for this feature is one of:
>
>  * Leaving a quick note to self when creating a --fixup commit when
>    it's not self-evident why the commit should be squashed without a
>    note into another one.

This is probably OK.

>  * (Ab)using the --fixup feature to "fix up" commits that have already
>    been pushed to a branch that doesn't allow non-fast-forwards,
>    i.e. just noting "this should have been part of that other commit",
>    and if the history ever got rewritten in the future the two should
>    be combined.

This has a smell of the tail wagging the dog.

Perhaps your editor does not have a good integration with external
commands to allow you to insert a single-liner output from

    git show --date=short -s --pretty='format:%h ("%s", %ad)' "$1"

and that is what you are abusing --fixup for?  

It is simply bad practice to leave a log entry that begins with
!fixup marker that would confuse automated tools like "rebase -i"
machinery on a commit that you have no intention of squashing into
another, as it invites mistakes.  

I do agree with the scenario where you would wish you could take
back an earlier mistake but you cannot.  But the log for such a
follow-up fix should be written just like any other follow-up fix
commit, i.e. describe what was wrong and how the wrongness is
corrected with the follow-up change.  What was wrong in "which
commit" is of course important part, but it is a relatively small
part.

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

* Re: [PATCH v2 2/2] commit: add support for --fixup <commit> -m"<extra message>"
  2017-12-22 21:28           ` Junio C Hamano
@ 2017-12-22 21:29             ` Junio C Hamano
  2017-12-22 21:58             ` Ævar Arnfjörð Bjarmason
  1 sibling, 0 replies; 16+ messages in thread
From: Junio C Hamano @ 2017-12-22 21:29 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: git, Pat Notz, Eric Sunshine

Junio C Hamano <gitster@pobox.com> writes:

> ...  So "nobody immediately thought of it when it was added" is
> certainly not a reason to later make the combination possible.

Oops, not a reason to later "_not_ to" make an update, of course.


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

* Re: [PATCH v2 2/2] commit: add support for --fixup <commit> -m"<extra message>"
  2017-12-22 21:28           ` Junio C Hamano
  2017-12-22 21:29             ` Junio C Hamano
@ 2017-12-22 21:58             ` Ævar Arnfjörð Bjarmason
  2017-12-22 22:06               ` Junio C Hamano
  1 sibling, 1 reply; 16+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2017-12-22 21:58 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Pat Notz, Eric Sunshine


On Fri, Dec 22 2017, Junio C. Hamano jotted:

> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>
>> Those options could also support combining with -m, but given what
>> they do I can't think of a good use-case for doing that, so I have not
>> made the more invasive change of splitting up the logic in commit.c to
>> first act on those, and then on -m options.
>>
>> 1. d71b8ba7c9 ("commit: --fixup option for use with rebase
>>    --autosquash", 2010-11-02)
>
> To be fair, when "rebase --autosquash -i" is run (which is why you
> would use --fixup in the first place), the log message of the fixup
> one is used only for locating which one is to be corrected, and the
> contents of the log message is discarded.  So "given what it does",
> I can't think of a good use-case for using --fixup and -m together,
> either.  So "nobody immediately thought of it when it was added" is
> certainly not a reason to later make the combination possible.
>
> But I personally am moderately negative on one of these two imagined
> use cases.
>
>> Add support for supplying the -m option with --fixup. Doing so has
>> errored out ever since --fixup was introduced. Before this, the only
>> way to amend the fixup message while committing was to use --edit and
>> amend it in the editor.
>>
>> The use-case for this feature is one of:
>>
>>  * Leaving a quick note to self when creating a --fixup commit when
>>    it's not self-evident why the commit should be squashed without a
>>    note into another one.
>
> This is probably OK.
>
>>  * (Ab)using the --fixup feature to "fix up" commits that have already
>>    been pushed to a branch that doesn't allow non-fast-forwards,
>>    i.e. just noting "this should have been part of that other commit",
>>    and if the history ever got rewritten in the future the two should
>>    be combined.
>
> This has a smell of the tail wagging the dog.
>
> Perhaps your editor does not have a good integration with external
> commands to allow you to insert a single-liner output from
>
>     git show --date=short -s --pretty='format:%h ("%s", %ad)' "$1"

Since this use-case is talking about pushing a fixup for an already
pushed commit, this is the first thing I put in -m"..." to reduce
ambiguity.

> and that is what you are abusing --fixup for?
>
> It is simply bad practice to leave a log entry that begins with
> !fixup marker that would confuse automated tools like "rebase -i"
> machinery on a commit that you have no intention of squashing into
> another, as it invites mistakes.

    "if the history ever got rewritten in the future the two should be
    combined"

So it's still the intent to squash these, it's just not being done right
now, and even if it never happens it'll be easy to glance at the
relevant commits in log --oneline.

> I do agree with the scenario where you would wish you could take
> back an earlier mistake but you cannot.  But the log for such a
> follow-up fix should be written just like any other follow-up fix
> commit, i.e. describe what was wrong and how the wrongness is
> corrected with the follow-up change.  What was wrong in "which
> commit" is of course important part, but it is a relatively small
> part.

I don't agree that git as a tool should be so opinionated. You can edit
these --fixup messages right now with --edit, and I do. That it doesn't
work with -m"" as it should is a longstanding UI wart.

Tools should be naturally composable without needless arbitrary
limitations.

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

* Re: [PATCH v2 2/2] commit: add support for --fixup <commit> -m"<extra message>"
  2017-12-22 21:58             ` Ævar Arnfjörð Bjarmason
@ 2017-12-22 22:06               ` Junio C Hamano
  2017-12-23 12:49                 ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 16+ messages in thread
From: Junio C Hamano @ 2017-12-22 22:06 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: git, Pat Notz, Eric Sunshine

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> I don't agree that git as a tool should be so opinionated. You can edit
> these --fixup messages right now with --edit, and I do. That it doesn't
> work with -m"" as it should is a longstanding UI wart.

I think you missed the point.

I was expressing my opinion, not an opinion of Git as a tool, that I
think one of these two "use case" scenario was a bad way not to be
encouraged.

That is totally different from allowing --fixup and -m working
together.  That is a good thing that helps the other "good" use case.

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

* Re: [PATCH v2 2/2] commit: add support for --fixup <commit> -m"<extra message>"
  2017-12-22 22:06               ` Junio C Hamano
@ 2017-12-23 12:49                 ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 16+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2017-12-23 12:49 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Pat Notz, Eric Sunshine


On Fri, Dec 22 2017, Junio C. Hamano jotted:

> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>
>> I don't agree that git as a tool should be so opinionated. You can edit
>> these --fixup messages right now with --edit, and I do. That it doesn't
>> work with -m"" as it should is a longstanding UI wart.
>
> I think you missed the point.

I did, yes. Sorry, I was being a bit touchy and argumentative there.

> I was expressing my opinion, not an opinion of Git as a tool, that I
> think one of these two "use case" scenario was a bad way not to be
> encouraged.
>
> That is totally different from allowing --fixup and -m working
> together.  That is a good thing that helps the other "good" use case.

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

end of thread, other threads:[~2017-12-23 12:49 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-20 19:38 [PATCH 1/2] commit doc: document that -c, -C, -F and --fixup with -m error Ævar Arnfjörð Bjarmason
2017-12-20 19:38 ` [PATCH 2/2] commit: add support for --fixup <commit> -m"<extra message>" Ævar Arnfjörð Bjarmason
2017-12-20 20:03   ` Eric Sunshine
2017-12-20 21:40     ` Ævar Arnfjörð Bjarmason
2017-12-20 21:50       ` Eric Sunshine
2017-12-22 16:00         ` [PATCH v2 0/2] support -m"<msg>" combined with commit --fixup Ævar Arnfjörð Bjarmason
2017-12-22 19:53           ` Eric Sunshine
2017-12-22 20:43             ` Ævar Arnfjörð Bjarmason
2017-12-22 16:00         ` [PATCH v2 1/2] commit doc: document that -c, -C, -F and --fixup with -m error Ævar Arnfjörð Bjarmason
2017-12-22 20:41         ` [PATCH v2 2/2] commit: add support for --fixup <commit> -m"<extra message>" Ævar Arnfjörð Bjarmason
2017-12-22 21:28           ` Junio C Hamano
2017-12-22 21:29             ` Junio C Hamano
2017-12-22 21:58             ` Ævar Arnfjörð Bjarmason
2017-12-22 22:06               ` Junio C Hamano
2017-12-23 12:49                 ` Ævar Arnfjörð Bjarmason
2017-12-20 19:45 ` [PATCH 1/2] commit doc: document that -c, -C, -F and --fixup with -m error Eric Sunshine

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).