Bug 1671640

Summary: git am does garbage commit summary
Product: [Fedora] Fedora Reporter: Milan Crha <mcrha>
Component: gitAssignee: Todd Zullinger <tmz>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 28CC: amahdal, besser82, c.david86, chrisw, pcahyna, pstodulk, sebastian.kisela, tmz
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-02-01 07:44:29 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Milan Crha 2019-02-01 07:07:03 UTC
Using:

   git format-patch -2

and then revert the patches (or using a different checkout) and apply the first of them with

   git am /path/to/0001-.....patch

does change/garbage the commit summary, when it contains prefix "[something] ".
I use this prefix to mark which part of the code the commit belongs to, which is sometimes useful. It's properly saved in the format-patch result:

   Subject: [PATCH 1/2] [some part] Text

the same as in the git log result before reverting the commit:

   [some part] Text

but after git am the git log result changes to:

   Text

which is wrong. I'd expect that format-patch and am will produce exactly the same result.

Maybe this is a known bug. I faced it earlier too. My currently installed git is git-2.17.0-3.fc28.x86_64.

Comment 1 Todd Zullinger 2019-02-01 07:40:07 UTC
Hi Milan,

You may want to look into the `--keep-non-patch` option to git-am.  That passes the `-b` option to git-mailinfo which limits stripping bracketed strings in the subject to those that contain PATCH.  See also the `-k/--keep-subject` option to git-format-patch.

I don't think there's any bug here, just a needed adjustment if your workflow uses git-am on patches which contain bracketed strings that you wish to keep.  I believe this has been discussed on the git list a few times in the past, but I don't have any links handy.  (You may find some via the list archive at <https://public-inbox.org/git/>.)

Comment 2 Milan Crha 2019-02-01 07:44:29 UTC
Thanks for a quick reply and a pointer for the parameters. I can imagine it could be discussed elsewhere many times. My personal opinion would be to keep them by default, it avoids data loss, thus is safer default. Not a thing you might change only for Fedora for sure, thus I'm closing this. Thanks again.

Comment 3 Todd Zullinger 2019-02-01 08:01:12 UTC
Yeah, I think some past discussions have suggested having the `-b` option be the default in git-mailinfo (or effectively similar/same behavior).  Surprisingly, it doesn't come up all that often.  I can only guess that most projects that have an email-based workflow (or one that uses git format-patch/am) use a format like git and the kernel.  That is, where the area of the code is given as "area: fix frotz" rather than "[area] fix frotz" which avoids this rather awkward interaction of git-format-patch and git-am.  Either that or it bites each new project maintainer a few times and then they alias `git am` to `git am --keep-non-patch`.  In any case, I'm glad that there are existing options to make this work better for you.  Sorry the defaults don't work as well.  With a little luck it will be further improved in the future.