{"thread":{"id":"46392","subject":"Re: [FEATURE] git-commit option to prepend filename to commit message","startedAt":"2017-07-15T16:22:02Z","lastAt":"2017-07-15T16:22:02Z","messageCount":1,"participants":["John J Foerch"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"324578","messageId":"19245062.3672.1500135717004@elwamui-karabash.atl.sa.earthlink.net","threadId":"46392","inReplyTo":null,"subject":"Re: [FEATURE] git-commit option to prepend filename to commit message","fromName":"John J Foerch","fromEmail":"jjfoerch@earthlink.net","sentAt":"2017-07-15T16:21:56Z","receivedAt":"2017-07-15T16:22:02Z","isPatch":false,"sender":{"key":"jjfoerch@earthlink.net","avatar":"https://gravatar.com/avatar/ca5eeb736f3c5ab7b89ac6f1317ce76a6cf00826f16a37f06a1df40702a1cf35?d=mp&s=160"},"body":"\n\n\n-----Original Message-----\n>From: Jeff King <peff@peff.net>\n>Sent: Jul 15, 2017 12:05 PM\n>To: John J Foerch <jjfoerch@earthlink.net>\n>Cc: git@vger.kernel.org\n>Subject: Re: [FEATURE] git-commit option to prepend filename to commit message\n>\n>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>\n>Johannes already pointed you to the prepare-commit-msg hook, which I\n>think is the right solution. I wrote a rough sketch for fun (note that\n>you could write it in whatever language you like if the mix of\n>perl/shell isn't to your liking):\n>\n>-- >8 --\n>#!/bin/sh\n>\n># only kick in for vanilla commit, or \"-m\"\n>case \"$2\" in\n>\"\"|message) ;;\n>*) exit 0\n>esac\n>\n># common prefix of all changed files\n>prefix=$(\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 &&\n>mv \"$1\".tmp \"$1\"\n\nThank you for that!\n"}]}