{"thread":{"id":"46390","subject":"[FEATURE] git-commit option to prepend filename to commit message","startedAt":"2017-07-15T15:00:54Z","lastAt":"2017-07-15T16:05:47Z","messageCount":3,"participants":["John J Foerch","Johannes Sixt","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"324574","messageId":"18894679.1800.1500128374439@elwamui-karabash.atl.sa.earthlink.net","threadId":"46390","inReplyTo":null,"subject":"[FEATURE] git-commit option to prepend filename to commit message","fromName":"John J Foerch","fromEmail":"jjfoerch@earthlink.net","sentAt":"2017-07-15T14:19:34Z","receivedAt":"2017-07-15T15:00:54Z","isPatch":false,"sender":{"key":"jjfoerch@earthlink.net","avatar":"https://gravatar.com/avatar/ca5eeb736f3c5ab7b89ac6f1317ce76a6cf00826f16a37f06a1df40702a1cf35?d=mp&s=160"},"body":"Hello,\n\nI had an idea for a feature for git commit that I wanted to pass along and see if maybe others would also think this would be useful.\n\nVery often, I make commits that affect a single file, and have simple commit messages of this form:\n\n    <filename>: <what changed>\n\nThe feature would be a command line option for git commit that would automatically prepend the \"<filename>: \" to the commit message.  The different cases of its behavior could be:\n\n - commit affecting a single file, with commit message given by -m:\n\n   : prepend \"<filename>: \" to the message given by -m\n\n - commit affecting a single file, with commit message from editor:\n\n   : pre-fill commit message template with \"<filename>: \"\n\n - commit affecting multiple files:\n\n   : use common base directory of all affected files for <filename>, behaviors as above for use with -m or editor.\n\nAnybody think that this or something like it would be a good convenience?\n\nThank you,\n\nJohn Foerch\n"},{"id":"324575","messageId":"ef92480f-3de6-fa82-78bc-2a91566e8864@kdbg.org","threadId":"46390","inReplyTo":"18894679.1800.1500128374439@elwamui-karabash.atl.sa.earthlink.net","subject":"Re: [FEATURE] git-commit option to prepend filename to commit message","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2017-07-15T16:01:32Z","receivedAt":"2017-07-15T16:02:07Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 15.07.2017 um 16:19 schrieb John J Foerch:\n> The feature would be a command line option for git commit that would\n> automatically prepend the \"<filename>: \" to the commit message.\nWrite a prepare-commit-msg hook:\n\nhttps://www.kernel.org/pub/software/scm/git/docs/githooks.html#_prepare_commit_msg\n\n-- Hannes\n"},{"id":"324576","messageId":"20170715160540.f2g5opqlr5z3r4aa@sigill.intra.peff.net","threadId":"46390","inReplyTo":"18894679.1800.1500128374439@elwamui-karabash.atl.sa.earthlink.net","subject":"Re: [FEATURE] git-commit option to prepend filename to commit message","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-07-15T16:05:40Z","receivedAt":"2017-07-15T16:05:47Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Jul 15, 2017 at 10:19:34AM -0400, John J Foerch wrote:\n\n> The feature would be a command line option for git commit that would\n> automatically prepend the \"<filename>: \" to the commit message.  The\n> different cases of its behavior could be:\n> \n>  - commit affecting a single file, with commit message given by -m:\n> \n>    : prepend \"<filename>: \" to the message given by -m\n> \n>  - commit affecting a single file, with commit message from editor:\n> \n>    : pre-fill commit message template with \"<filename>: \"\n> \n>  - commit affecting multiple files:\n> \n>    : use common base directory of all affected files for <filename>, behaviors as above for use with -m or editor.\n> \n> Anybody think that this or something like it would be a good convenience?\n\nJohannes already pointed you to the prepare-commit-msg hook, which I\nthink is the right solution. I wrote a rough sketch for fun (note that\nyou could write it in whatever language you like if the mix of\nperl/shell isn't to your liking):\n\n-- >8 --\n#!/bin/sh\n\n# only kick in for vanilla commit, or \"-m\"\ncase \"$2\" in\n\"\"|message) ;;\n*) exit 0\nesac\n\n# common prefix of all changed files\nprefix=$(\n        git diff-index --name-only HEAD |\n        perl -lne '\n                if (!defined $prefix) {\n                        $prefix = $_;\n                } else {\n                        chop $prefix while !/^\\Q$prefix\\E/;\n                }\n                END {\n                        # trim trailing slash if present\n                        $prefix =~ s{/$}{};\n                        print $prefix\n                }\n        '\n)\n\n# now stick the prefix at the start of the message-in-progress\n{\n        printf '%s' \"$prefix: \"\n        cat \"$1\"\n} >\"$1\".tmp &&\nmv \"$1\".tmp \"$1\"\n"}]}