{"thread":{"id":"50612","subject":"[BUG] git-am: all colons in the beginning of a subject are lost","startedAt":"2019-02-28T10:02:26Z","lastAt":"2019-02-28T11:26:12Z","messageCount":2,"participants":["Max Filenko","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"370357","messageId":"m2wolk6xjw.fsf@filenko.ms","threadId":"50612","inReplyTo":null,"subject":"[BUG] git-am: all colons in the beginning of a subject are lost","fromName":"Max Filenko","fromEmail":"contact@filenko.ms","sentAt":"2019-02-28T10:02:11Z","receivedAt":"2019-02-28T10:02:26Z","isPatch":false,"sender":{"key":"contact@filenko.ms","avatar":"https://gravatar.com/avatar/dccb5e1c907092ccaa4f3de72ec35a23a654206593e3e475a8ed6ffc219df036?d=mp&s=160"},"body":"Hi!\n\nIf there are colons in the beginning of a patch subject line `git-am'\nwill drop them.\n\nConsider the following patch:\n\n    $ cat 0001-four-colons-prepended.patch\n    From e8213a2d10a61c9dc75521d88d656b8d5330e6bb Mon Sep 17 00:00:00 2001\n    From: Max Filenko <contact@filenko.ms>\n    Date: Tue, 12 Feb 2019 12:21:21 +0100\n    Subject: [PATCH] :::: four colons prepended\n    \n    ---\n     file.txt | 2 +-\n     1 file changed, 1 insertion(+), 1 deletion(-)\n    \n    diff --git a/file.txt b/file.txt\n    index 4dd1ef7..b5da95d 100644\n    --- a/file.txt\n    +++ b/file.txt\n    @@ -1 +1 @@\n    -This is a file.\n    +This is a plain text file.\n    -- \n    2.17.1\n\nThere will be no colons in the beginning of a commit message if I apply\nthis patch:\n\n    $ git am 0001-four-colons-prepended.patch\n    Applying: four colons prepended\n\nThe four colons already gone in the log message above. There are neither\nno colons in the commit subject line:\n\n    $ git show\n    commit 6341a6a2872f850ecb376c268b1b3bae54a6a74f (HEAD -> master)\n    Author: Max Filenko <contact@filenko.ms>\n    Date:   Tue Feb 12 12:21:21 2019 +0100\n    \n        four colons prepended\n    \n    diff --git a/file.txt b/file.txt\n    index 4dd1ef7..b5da95d 100644\n    --- a/file.txt\n    +++ b/file.txt\n    @@ -1 +1 @@\n    -This is a file.\n    +This is a plain text file.\n\nI was able to reproduce this with git 2.17.1 on Ubuntu 18.04.2 LTS as\nwell as with git 2.17.2 (Apple Git-113) on macOS 10.14.3.\n\nI was able to trace this down to <builtin/am.c>. It seems like there are\nno colons already in the `state->msg' which to my understanding is being\nfilled by `read_commit_msg()' function. I would really appreciate a hand\non debugging it further.\n\nI'm re-submitting this bug report because the original one [1] wasn't\nreally noticed. Hopefully, it's just because I've missed the proper\nprefix in my email's subject line :)\n\n[1]:\nhttp://public-inbox.org/git/m2lg2lxmmm.fsf@bouncer.i-did-not-set--mail-host-address--so-tickle-me/\n\n--\nBest,\nMax\n"},{"id":"370363","messageId":"20190228112608.GA25552@sigill.intra.peff.net","threadId":"50612","inReplyTo":"m2wolk6xjw.fsf@filenko.ms","subject":"Re: [BUG] git-am: all colons in the beginning of a subject are lost","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-02-28T11:26:08Z","receivedAt":"2019-02-28T11:26:12Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Feb 28, 2019 at 11:02:11AM +0100, Max Filenko wrote:\n\n>     Subject: [PATCH] :::: four colons prepended\n> [...]\n> There will be no colons in the beginning of a commit message if I apply\n> this patch:\n> \n>     $ git am 0001-four-colons-prepended.patch\n>     Applying: four colons prepended\n\nI suspect this has to do with the sanitization that happens as part of\nremoving \"[PATCH]\". Note that if you use \"-k\" (to preserve the subject)\nit doesn't happen, though of course you also get \"[PATCH]\" then.\n\nIf you want to pass the subject lines through verbatim, use \"-k\" with\nboth format-patch and git-am.\n\n> I was able to trace this down to <builtin/am.c>. It seems like there are\n> no colons already in the `state->msg' which to my understanding is being\n> filled by `read_commit_msg()' function. I would really appreciate a hand\n> on debugging it further.\n\nIt's probably easier to debug with git-mailinfo, which has the same\nbehavior:\n\n  $ git mailinfo msg patch <0001-four-colons-prepended.patch\n  Author: Jeff King\n  Email: peff@peff.net\n  Subject: four colons prepended\n  Date: Thu, 28 Feb 2019 06:12:50 -0500\n\nand is based on the same routines.\n\nThe contents are preserved until we end up in mailinfo.c's\ncleanup_subject(). And there leading colons are explicitly removed:\n\n       case ' ': case '\\t': case ':':\n               strbuf_remove(subject, at, 1);\n               continue;\n\nThat behavior goes all the way back to 2744b2344d (Start of early patch\napplicator tools for git., 2005-04-11), when Git was only 4 days old.\n\nSince it also handles cruft like \"Re:\", I suspect the goal there was I\nsuspect the goal there was to remove cruft like \"Re::::\" or \"Re: :\"\nwhich sometimes happens. I don't know if anybody would complain if we\nwere more careful about leaving lone colons that weren't part of a \"Re\"\nchain.\n\n-Peff\n"}]}