Bug: Incorrect stripping of the [PATCH] prefix in git-am
Description:
When applying a patch created via git format-patch with git am,
any prefix of the commit message that's within square brackets is stripped from the commit message.
Reproduction:
$ git log --oneline --decorate --graph --all
* b41514b (HEAD) [baz] baz
| * 5e31740 (master) [bar] bar
|/
* aaf5d34 [foo] foo
$ git format-patch aaf5d34
$ git checkout master
$ git am 0001-baz-baz.patch
$ git log --oneline --decorate --graph --all
* d5161b8 (HEAD, master) baz
* 5e31740 [bar] bar
* aaf5d34 [foo] fooI have omitted all output except for the git log output for brevity.
As you can see, the commit resulting from git am has lost the "[bar]" prefix from its commit message.
Looking at the patch,
$ cat 0001-baz-baz.patch
From b41514be8a70fd44052bff0d3ce720373ec9cfd8 Mon Sep 17 00:00:00 2001
From: Nathanael Huebbe <[email protected]>
Date: Wed, 25 Nov 2015 15:28:09 +0100
Subject: [PATCH] [baz] baz ---
baz | 1 +
1 file changed, 1 insertion(+)
create mode 100644 baz
diff --git a/baz b/baz
new file mode 100644
index 0000000..7601807
--- /dev/null
+++ b/baz
@@ -0,0 +1 @@
+baz
--
2.1.4I see that the commit message contains the "[PATCH]"-prefix that git am is supposed to strip, yet it seems to incorrectly continue to also strip the "[baz]"-prefix.
Affected versions:
I have reproduced the bug with versions 1.9.1, 2.1.4, and 2.6.3
Severity:
While I do not consider this a high priority bug, it becomes quite irksome in some workflows. In my case, an upstream svn repository has the policy of using "[branch-name]" prefixes to the commit messages, which are stripped whenever I transplant a commit using the git format-patch/git am combination.
Signature · 2 lines
Please be aware that the enemies of your civil rights and your freedom are on CC of all unencrypted communication. Protect yourself.
Am 25.11.2015 um 16:29 schrieb huebbe:
Quoted 4 lines
Description:
When applying a patch created via
git format-patchwithgit am,
any prefix of the commit message that's within square brackets is stripped from the commit message.
As advertised in the man page of 'git am' (or 'git mailinfo' that is).
Is 'git am --keep-non-patch' what you're looking for ?
Quoted 51 lines
Reproduction:
$ git log --oneline --decorate --graph --all * b41514b (HEAD) [baz] baz | * 5e31740 (master) [bar] bar |/ * aaf5d34 [foo] foo $ git format-patch aaf5d34 $ git checkout master $ git am 0001-baz-baz.patch $ git log --oneline --decorate --graph --all * d5161b8 (HEAD, master) baz * 5e31740 [bar] bar * aaf5d34 [foo] fooI have omitted all output except for the
git logoutput for brevity.
As you can see, the commit resulting fromgit amhas lost the "[bar]" prefix from its commit message.Looking at the patch,
$ cat 0001-baz-baz.patch From b41514be8a70fd44052bff0d3ce720373ec9cfd8 Mon Sep 17 00:00:00 2001 From: Nathanael Huebbe <[email protected]> Date: Wed, 25 Nov 2015 15:28:09 +0100 Subject: [PATCH] [baz] baz--- baz | 1 + 1 file changed, 1 insertion(+) create mode 100644 baz diff --git a/baz b/baz new file mode 100644 index 0000000..7601807 --- /dev/null +++ b/baz @@ -0,0 +1 @@ +baz -- 2.1.4I see that the commit message contains the "[PATCH]"-prefix that
git amis supposed to strip, yet it seems to incorrectly continue to also strip the "[baz]"-prefix.Affected versions:
I have reproduced the bug with versions 1.9.1, 2.1.4, and 2.6.3
Quoted 8 lines
Severity:
While I do not consider this a high priority bug, it becomes quite irksome in some workflows. In my case, an upstreamsvnrepository has the policy of using "[branch-name]" prefixes to the commit messages, which are stripped whenever I transplant a commit using thegit format-patch/git amcombination.
HTH,
Stefan
Signature · 4 lines
----------------------------------------------------------------
/dev/random says: Oxymoron: Slow speed.
python -c "print '73746566616e2e6e616577654061746c61732d656c656b74726f6e696b2e636f6d'.decode('hex')"
GPG Key fingerprint = 2DF5 E01B 09C3 7501 BCA9 9666 829B 49C5 9221 27AFYes, it looks like the --keep-non-patch option works around this.
However, shouldn't that be the default behaviour?
I mean, what is the point in stripping stuff that is not proven to be inserted by git itself? That's not what I expect a tool to do which I trust.
Cheers,
Nathanael
Quoted 73 lines · On 11/25/2015 04:44 PM, [email protected] wrote:
Am 25.11.2015 um 16:29 schrieb huebbe:
Quoted 4 lines
Description:
When applying a patch created via
git format-patchwithgit am,
any prefix of the commit message that's within square brackets is stripped from the commit message.As advertised in the man page of 'git am' (or 'git mailinfo' that is).
Is 'git am --keep-non-patch' what you're looking for ?
Quoted 51 lines
Reproduction:
$ git log --oneline --decorate --graph --all * b41514b (HEAD) [baz] baz | * 5e31740 (master) [bar] bar |/ * aaf5d34 [foo] foo $ git format-patch aaf5d34 $ git checkout master $ git am 0001-baz-baz.patch $ git log --oneline --decorate --graph --all * d5161b8 (HEAD, master) baz * 5e31740 [bar] bar * aaf5d34 [foo] fooI have omitted all output except for the
git logoutput for brevity.
As you can see, the commit resulting fromgit amhas lost the "[bar]" prefix from its commit message.Looking at the patch,
$ cat 0001-baz-baz.patch From b41514be8a70fd44052bff0d3ce720373ec9cfd8 Mon Sep 17 00:00:00 2001 From: Nathanael Huebbe <[email protected]> Date: Wed, 25 Nov 2015 15:28:09 +0100 Subject: [PATCH] [baz] baz--- baz | 1 + 1 file changed, 1 insertion(+) create mode 100644 baz diff --git a/baz b/baz new file mode 100644 index 0000000..7601807 --- /dev/null +++ b/baz @@ -0,0 +1 @@ +baz -- 2.1.4I see that the commit message contains the "[PATCH]"-prefix that
git amis supposed to strip, yet it seems to incorrectly continue to also strip the "[baz]"-prefix.Affected versions:
I have reproduced the bug with versions 1.9.1, 2.1.4, and 2.6.3Quoted 8 lines
Severity:
While I do not consider this a high priority bug, it becomes quite irksome in some workflows. In my case, an upstreamsvnrepository has the policy of using "[branch-name]" prefixes to the commit messages, which are stripped whenever I transplant a commit using thegit format-patch/git amcombination.HTH,
Stefan
Signature · 2 lines
Please be aware that the enemies of your civil rights and your freedom are on CC of all unencrypted communication. Protect yourself.
Quoted 5 lines · huebbe
Yes, it looks like the
--keep-non-patchoption works around this.However, shouldn't that be the default behaviour?
I mean, what is the point in stripping stuff that is not proven to be inserted bygititself? That's not what I expect a tool to do which I trust.
The "[]" convention is a microformat used by Linux kernel folks. So it's not "whoops, we are stripping stuff not added by git". It is respecting a microformat used by the tool's authors.
That being said, if we were choosing a default from scratch today, it might go the other way. But we aren't, and we have to deal with the burden of breaking existing scripts by flipping it.
-Peff
Quoted 12 lines · Jeff King
Quoted 5 lines · huebbe
Yes, it looks like the
--keep-non-patchoption works around this.However, shouldn't that be the default behaviour?
I mean, what is the point in stripping stuff that is not proven to be inserted bygititself? That's not what I expect a tool to do which I trust.The "[]" convention is a microformat used by Linux kernel folks. So it's not "whoops, we are stripping stuff not added by git". It is respecting a microformat used by the tool's authors.
Quoted 5 lines
That being said, if we were choosing a default from scratch today, it might go the other way. But we aren't, and we have to deal with the burden of breaking existing scripts by flipping it.
-Peff
Ok, I think I understand the reason for this behavior now. However, I still believe that the git format-patch/git am combo should retain the original commit messages by default.
As such, I would like to ask whether it would be possible/sensible to somehow escape square brackets, or mark the beginning
of the original commit message in the git format-patch output? This would allow git am to reproduce the exact commit message by default without breaking the "[]" convention.
For example, I could imagine to use this behavior:
* git format-patch produces a message of the format "[PATCH ...]: original commit message".
* git am strips the longest prefix that consists entirely of bracketed stuff
and ends with the string "]: ". If that terminator is not found -> old behavior.
* Users could insert any "[FOO]" strings they like before the ":", which would still be stripped from the commit message by git am.
Of course, any such change would not be without pitfalls. With the rule above, we would get ": " prepended to commit messages if a patch is created with a git version that has the change, and applied with an older version that does not know about the terminator.
What do you guys think? Is there anything I missed?
Cheers,
Nathanael
Signature · 2 lines
Please be aware that the enemies of your civil rights and your freedom are on CC of all unencrypted communication. Protect yourself.
Quoted 5 lines · huebbe
As such, I would like to ask whether it would be possible/sensible to somehow escape square brackets, or mark the beginning
of the original commit message in thegit format-patchoutput? This would allowgit amto reproduce the exact commit message by default without breaking the "[]" convention.
I am not sure why "git format-patch -k | git am -k" does not do what you want. That is what those options were added for (and what git-rebase uses internally to make sure commit messages are left unmunged).
-Peff
Dear Peff,
I have no problem working around this bug/feature.
I just happen to think that the current *default* behaviour
is not the default behaviour that users have a right to expect:
I believe that users have every right to expect git format-patch/git am to preserve commit messages perfectly by default.
Since I see that people are using the current behaviour as a feature, I tried to come up with an alternative behaviour that would do both:
1. Respect user assumptions to preserve commit messages by default.
2. Allow users to prepend stuff when mailing a patch, that will get stripped automatically.
Just because the current behaviour is ... irritating.
Cheers,
Nathanael
Quoted 14 lines · Jeff King
Quoted 5 lines · huebbe
As such, I would like to ask whether it would be possible/sensible to somehow escape square brackets, or mark the beginning
of the original commit message in thegit format-patchoutput? This would allowgit amto reproduce the exact commit message by default without breaking the "[]" convention.I am not sure why "git format-patch -k | git am -k" does not do what you want. That is what those options were added for (and what git-rebase uses internally to make sure commit messages are left unmunged).
-Peff
Signature · 2 lines
Please be aware that the enemies of your civil rights and your freedom are on CC of all unencrypted communication. Protect yourself.
Quoted 8 lines · Jeff King
Quoted 5 lines · huebbe
Yes, it looks like the
--keep-non-patchoption works around this.However, shouldn't that be the default behaviour?
I mean, what is the point in stripping stuff that is not proven to be inserted bygititself? That's not what I expect a tool to do which I trust.
Quoted 7 lines
The "[]" convention is a microformat used by Linux kernel folks. So it's not "whoops, we are stripping stuff not added by git". It is respecting a microformat used by the tool's authors.
That being said, if we were choosing a default from scratch today, it might go the other way. But we aren't, and we have to deal with the burden of breaking existing scripts by flipping it.
Do we as the Git community have a place where we take notes for version 3?
This sounds perfectly fine (to me at least) to change the default with a major version number as the changelog for major version numbers may even be read by kernel devs maintaining such scripts ;)
Or could we even patch that today to have --keep-non-patch be default later on by checking for our version number ourselves and deciding upon that for the default?
Quoted 6 lines
-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 1 line · Stefan Beller
Do we as the Git community have a place where we take notes for version 3?
I do not think there is, I do think we might need one when a need arises, and I do not think this topic is one that creates such a need.
And I said "might" in the second one, based on the experience at 2.0; we didn't need such a separate place when managing the backward incompatible changes for that release.
Quoted 7 lines · Jeff King
The "[]" convention is a microformat used by Linux kernel folks. So it's not "whoops, we are stripping stuff not added by git". It is respecting a microformat used by the tool's authors.
That being said, if we were choosing a default from scratch today, it might go the other way. But we aren't, and we have to deal with the burden of breaking existing scripts by flipping it.
And I do think it no longer is sensible to expect that it still is kernel-only convention. Any project that uses e-mail based workflow with Git have known how "[]" microformat works, may even have taken advantage of it to build their workflow around it, and flipping the default will only hurt them.
A project that chooses not to follow the convention can easily tweak a knob to keep using different conventions, so I do not see anything to change here.