threads / patch / 47474

patch, 2 partscommit doc: document that -c, -C, -F and --fixup with -m error

Subject: [PATCH 1/2] commit doc: document that -c, -C, -F and --fixup with -m error

## tl;dr

16 messages between Dec 20, 2017 and Dec 23, 2017. Diffs are folded; open one to read it.

replies: 15people: 3as markdown or json

Ævar Arnfjörð Bjarmason· Dec 20, 2017, 19:38 UTC · lore

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(+)
Show changes to Documentation/git-commit.txt +3 −0
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
Ævar Arnfjörð Bjarmason· Dec 20, 2017, 19:38 UTC · re: Ævar Arnfjörð Bjarmason · lore

[PATCH 2/2] commit: add support for --fixup <commit> -m"<extra message>"

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(-)
Show changes to 3 files +15 −6

Documentation/git-commit.txt, builtin/commit.c, t/t7500-commit.sh

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
Eric Sunshine· Dec 20, 2017, 20:03 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: [PATCH 2/2] commit: add support for --fixup <commit> -m"<extra message>"

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

Show 14 quoted lines
> 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?

Ævar Arnfjörð Bjarmason· Dec 20, 2017, 21:40 UTC · re: Eric Sunshine · lore

Re: [PATCH 2/2] commit: add support for --fixup <commit> -m"<extra message>"

On Wed, Dec 20 2017, Eric Sunshine jotted:
Show 10 quoted lines
> 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.

Show 21 quoted lines
>> 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.

Eric Sunshine· Dec 20, 2017, 21:50 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: [PATCH 2/2] commit: add support for --fixup <commit> -m"<extra message>"

On Wed, Dec 20, 2017 at 4:40 PM, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

Show 22 quoted lines
> 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.

Ævar Arnfjörð Bjarmason· Dec 22, 2017, 16:00 UTC · re: Eric Sunshine · lore

[PATCH v2 0/2] support -m"<msg>" combined with commit --fixup

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
Ævar Arnfjörð Bjarmason· Dec 22, 2017, 16:00 UTC · re: Ævar Arnfjörð Bjarmason · lore

[PATCH v2 1/2] commit doc: document that -c, -C, -F and --fixup with -m error

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(+)
Show changes to Documentation/git-commit.txt +3 −0
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
Eric Sunshine· Dec 22, 2017, 19:53 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: [PATCH v2 0/2] support -m"<msg>" combined with commit --fixup

On Fri, Dec 22, 2017 at 11:00 AM, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

Show 6 quoted lines
> 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...
Show 19 quoted lines
> 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?)

Ævar Arnfjörð Bjarmason· Dec 22, 2017, 20:43 UTC · re: Eric Sunshine · lore

Re: [PATCH v2 0/2] support -m"<msg>" combined with commit --fixup

On Fri, Dec 22 2017, Eric Sunshine jotted:
Show 10 quoted lines
> 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.
Show 23 quoted lines
>> 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...

Ævar Arnfjörð Bjarmason· Dec 22, 2017, 20:41 UTC · re: Eric Sunshine · lore

[PATCH v2 2/2] commit: add support for --fixup <commit> -m"<extra message>"

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(-)
Show changes to 3 files +14 −6

Documentation/git-commit.txt, builtin/commit.c, t/t7500-commit.sh

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
Junio C Hamano· Dec 22, 2017, 21:28 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: [PATCH v2 2/2] commit: add support for --fixup <commit> -m"<extra message>"

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 7 quoted lines
> 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.

Show 10 quoted lines
> 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.
Show 5 quoted lines
>  * (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.

Junio C Hamano· Dec 22, 2017, 21:29 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 2/2] commit: add support for --fixup <commit> -m"<extra message>"

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.
Ævar Arnfjörð Bjarmason· Dec 22, 2017, 21:58 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 2/2] commit: add support for --fixup <commit> -m"<extra message>"

On Fri, Dec 22 2017, Junio C. Hamano jotted:
Show 46 quoted lines
> Æ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.

Show 6 quoted lines
> 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.

Show 7 quoted lines
> 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.

Junio C Hamano· Dec 22, 2017, 22:06 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: [PATCH v2 2/2] commit: add support for --fixup <commit> -m"<extra message>"

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

Ævar Arnfjörð Bjarmason· Dec 23, 2017, 12:49 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 2/2] commit: add support for --fixup <commit> -m"<extra message>"

On Fri, Dec 22 2017, Junio C. Hamano jotted:
Show 7 quoted lines
> Æ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.
Show 6 quoted lines
> 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.
Eric Sunshine· Dec 20, 2017, 19:45 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: [PATCH 1/2] commit doc: document that -c, -C, -F and --fixup with -m error

On Wed, Dec 20, 2017 at 2:38 PM, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

Show 12 quoted lines
> 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.

← back to recent threads