git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [FEATURE] git-commit option to prepend filename to commit message
@ 2017-07-15 16:13 John J Foerch
  0 siblings, 0 replies; 5+ messages in thread
From: John J Foerch @ 2017-07-15 16:13 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: git



Perfect, thank you Hannes!

-----Original Message-----
>From: Johannes Sixt <j6t@kdbg.org>
>Sent: Jul 15, 2017 12:01 PM
>To: John J Foerch <jjfoerch@earthlink.net>
>Cc: git@vger.kernel.org
>Subject: Re: [FEATURE] git-commit option to prepend filename to commit message
>
>Am 15.07.2017 um 16:19 schrieb John J Foerch:
>> The feature would be a command line option for git commit that would
>> automatically prepend the "<filename>: " to the commit message.
>Write a prepare-commit-msg hook:
>
>https://www.kernel.org/pub/software/scm/git/docs/githooks.html#_prepare_commit_msg
>
>-- Hannes

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FEATURE] git-commit option to prepend filename to commit message
@ 2017-07-15 16:21 John J Foerch
  0 siblings, 0 replies; 5+ messages in thread
From: John J Foerch @ 2017-07-15 16:21 UTC (permalink / raw)
  To: Jeff King; +Cc: git




-----Original Message-----
>From: Jeff King <peff@peff.net>
>Sent: Jul 15, 2017 12:05 PM
>To: John J Foerch <jjfoerch@earthlink.net>
>Cc: git@vger.kernel.org
>Subject: Re: [FEATURE] git-commit option to prepend filename to commit message
>
>On Sat, Jul 15, 2017 at 10:19:34AM -0400, John J Foerch wrote:
>
>> The 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:
>> 
>>  - commit affecting a single file, with commit message given by -m:
>> 
>>    : prepend "<filename>: " to the message given by -m
>> 
>>  - commit affecting a single file, with commit message from editor:
>> 
>>    : pre-fill commit message template with "<filename>: "
>> 
>>  - commit affecting multiple files:
>> 
>>    : use common base directory of all affected files for <filename>, behaviors as above for use with -m or editor.
>> 
>> Anybody think that this or something like it would be a good convenience?
>
>Johannes already pointed you to the prepare-commit-msg hook, which I
>think is the right solution. I wrote a rough sketch for fun (note that
>you could write it in whatever language you like if the mix of
>perl/shell isn't to your liking):
>
>-- >8 --
>#!/bin/sh
>
># only kick in for vanilla commit, or "-m"
>case "$2" in
>""|message) ;;
>*) exit 0
>esac
>
># common prefix of all changed files
>prefix=$(
>        git diff-index --name-only HEAD |
>        perl -lne '
>                if (!defined $prefix) {
>                        $prefix = $_;
>                } else {
>                        chop $prefix while !/^\Q$prefix\E/;
>                }
>                END {
>                        # trim trailing slash if present
>                        $prefix =~ s{/$}{};
>                        print $prefix
>                }
>        '
>)
>
># now stick the prefix at the start of the message-in-progress
>{
>        printf '%s' "$prefix: "
>        cat "$1"
>} >"$1".tmp &&
>mv "$1".tmp "$1"

Thank you for that!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FEATURE] git-commit option to prepend filename to commit message
  2017-07-15 14:19 John J Foerch
  2017-07-15 16:01 ` Johannes Sixt
@ 2017-07-15 16:05 ` Jeff King
  1 sibling, 0 replies; 5+ messages in thread
From: Jeff King @ 2017-07-15 16:05 UTC (permalink / raw)
  To: John J Foerch; +Cc: git

On Sat, Jul 15, 2017 at 10:19:34AM -0400, John J Foerch wrote:

> The 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:
> 
>  - commit affecting a single file, with commit message given by -m:
> 
>    : prepend "<filename>: " to the message given by -m
> 
>  - commit affecting a single file, with commit message from editor:
> 
>    : pre-fill commit message template with "<filename>: "
> 
>  - commit affecting multiple files:
> 
>    : use common base directory of all affected files for <filename>, behaviors as above for use with -m or editor.
> 
> Anybody think that this or something like it would be a good convenience?

Johannes already pointed you to the prepare-commit-msg hook, which I
think is the right solution. I wrote a rough sketch for fun (note that
you could write it in whatever language you like if the mix of
perl/shell isn't to your liking):

-- >8 --
#!/bin/sh

# only kick in for vanilla commit, or "-m"
case "$2" in
""|message) ;;
*) exit 0
esac

# common prefix of all changed files
prefix=$(
        git diff-index --name-only HEAD |
        perl -lne '
                if (!defined $prefix) {
                        $prefix = $_;
                } else {
                        chop $prefix while !/^\Q$prefix\E/;
                }
                END {
                        # trim trailing slash if present
                        $prefix =~ s{/$}{};
                        print $prefix
                }
        '
)

# now stick the prefix at the start of the message-in-progress
{
        printf '%s' "$prefix: "
        cat "$1"
} >"$1".tmp &&
mv "$1".tmp "$1"

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FEATURE] git-commit option to prepend filename to commit message
  2017-07-15 14:19 John J Foerch
@ 2017-07-15 16:01 ` Johannes Sixt
  2017-07-15 16:05 ` Jeff King
  1 sibling, 0 replies; 5+ messages in thread
From: Johannes Sixt @ 2017-07-15 16:01 UTC (permalink / raw)
  To: John J Foerch; +Cc: git

Am 15.07.2017 um 16:19 schrieb John J Foerch:
> The feature would be a command line option for git commit that would
> automatically prepend the "<filename>: " to the commit message.
Write a prepare-commit-msg hook:

https://www.kernel.org/pub/software/scm/git/docs/githooks.html#_prepare_commit_msg

-- Hannes

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FEATURE] git-commit option to prepend filename to commit message
@ 2017-07-15 14:19 John J Foerch
  2017-07-15 16:01 ` Johannes Sixt
  2017-07-15 16:05 ` Jeff King
  0 siblings, 2 replies; 5+ messages in thread
From: John J Foerch @ 2017-07-15 14:19 UTC (permalink / raw)
  To: git

Hello,

I 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.

Very often, I make commits that affect a single file, and have simple commit messages of this form:

    <filename>: <what changed>

The 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:

 - commit affecting a single file, with commit message given by -m:

   : prepend "<filename>: " to the message given by -m

 - commit affecting a single file, with commit message from editor:

   : pre-fill commit message template with "<filename>: "

 - commit affecting multiple files:

   : use common base directory of all affected files for <filename>, behaviors as above for use with -m or editor.

Anybody think that this or something like it would be a good convenience?

Thank you,

John Foerch

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-07-15 16:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-15 16:13 [FEATURE] git-commit option to prepend filename to commit message John J Foerch
  -- strict thread matches above, loose matches on Subject: below --
2017-07-15 16:21 John J Foerch
2017-07-15 14:19 John J Foerch
2017-07-15 16:01 ` Johannes Sixt
2017-07-15 16:05 ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).