{"thread":{"id":"11667","subject":"[PATCH] git-commit: add a prepare-commit-msg hook","startedAt":"2008-01-18T14:51:25Z","lastAt":"2008-01-21T22:44:30Z","messageCount":23,"participants":["Paolo Bonzini","Johannes Schindelin","Benoit Sigoure","Alex Riesen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"65882","messageId":"4790BCED.4050207@gnu.org","threadId":"11667","inReplyTo":null,"subject":"[PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Paolo Bonzini","fromEmail":"bonzini@gnu.org","sentAt":"2008-01-18T14:51:25Z","receivedAt":"2008-01-18T14:51:25Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"The prepare-commit-msg hook is run whenever a \"fresh\" commit message\n(i.e. not one taken from another commit with -c) is shown in the editor.\nIt can modify the commit message in-place and/or abort the commit.\n\nWhile the default hook just adds a Signed-Off-By line at the bottom\nof the commit messsage, the hook is more intended to build a template\nfor the commit message following project standards.\n\nSigned-Off-By: Paolo Bonzini <bonzini@gnu.org>\n---\n Documentation/git-commit.txt        |   13 ++++++++-----\n Documentation/hooks.txt             |   21 +++++++++++++++++++++\n builtin-commit.c                    |    3 +++\n templates/hooks--commit-msg         |    3 +++\n templates/hooks--prepare-commit-msg |   14 ++++++++++++++\n 5 files changed, 49 insertions(+), 5 deletions(-)\n create mode 100644 templates/hooks--prepare-commit-msg\n\n\tThe real motivation for this is building the commit message\n\tfrom GNU ChangeLogs.  But I figured that putting it in the\n\treal commit message rather than a cover letter would have\n\timplied rejection of the patch...\n\ndiff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt\nindex c3725b2..c68191b 100644\n--- a/Documentation/git-commit.txt\n+++ b/Documentation/git-commit.txt\n@@ -62,18 +62,21 @@ OPTIONS\n \tand the authorship information (including the timestamp)\n \twhen creating the commit.  With '-C', the editor is not\n \tinvoked; with '-c' the user can further edit the commit\n-\tmessage.\n+\tmessage.  In either case, the prepare-commit-msg hook is\n+\tbypassed.\n\n -F <file>::\n \tTake the commit message from the given file.  Use '-' to\n-\tread the message from the standard input.\n+\tread the message from the standard input.  This option\n+\tbypasses the prepare-commit-msg hook.\n\n --author <author>::\n \tOverride the author name used in the commit.  Use\n \t`A U Thor <author@example.com>` format.\n\n -m <msg>|--message=<msg>::\n-\tUse the given <msg> as the commit message.\n+\tUse the given <msg> as the commit message.  This option\n+\tbypasses the prepare-commit-msg hook.\n\n -t <file>|--template=<file>::\n \tUse the contents of the given file as the initial version\n@@ -280,8 +283,8 @@ order).\n\n HOOKS\n -----\n-This command can run `commit-msg`, `pre-commit`, and\n-`post-commit` hooks.  See link:hooks.html[hooks] for more\n+This command can run `commit-msg`, `prepare-commit-msg`, `pre-commit`,\n+and `post-commit` hooks.  See link:hooks.html[hooks] for more\n information.\n\n\ndiff --git a/Documentation/hooks.txt b/Documentation/hooks.txt\nindex f110162..2ef5567 100644\n--- a/Documentation/hooks.txt\n+++ b/Documentation/hooks.txt\n@@ -61,6 +61,27 @@ The default 'pre-commit' hook, when enabled, catches introduction\n of lines with trailing whitespaces and aborts the commit when\n such a line is found.\n\n+prepare-commit-msg\n+------------------\n+\n+This hook is invoked by `git-commit` right before starting the editor\n+with an empty log message.  It is not executed if the commit message is\n+specified otherwise, such as with the `\\-m`, `\\-F`, `\\-c`, `\\-C` options.\n+It takes a single parameter, the name of the file that holds git's own\n+template commit log message.  Exiting with non-zero status causes\n+`git-commit` to abort.\n+\n+The hook is allowed to edit the message file in place, and\n+can be used to augment the default commit message with some\n+project standard information.  It can also be used for the same\n+purpose as the pre-commit message, if the verification has\n+to be skipped for automatic commits (e.g. during rebasing).\n+\n+The default 'prepare-commit-msg' hook adds a Signed-Off-By line\n+(doing it with a hook is not necessarily a good idea, but doing\n+it in 'commit-msg' is worse because you are not reminded in\n+the editor).\n+\n commit-msg\n ----------\n\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 0227936..1de0d02 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -869,6 +869,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t\tchar index[PATH_MAX];\n \t\tconst char *env[2] = { index, NULL };\n \t\tsnprintf(index, sizeof(index), \"GIT_INDEX_FILE=%s\", index_file);\n+\t\tif (!edit_message) {\n+\t\t\trun_hook(index_file, \"prepare-commit-msg\", git_path(commit_editmsg));\n+\t\t}\n \t\tlaunch_editor(git_path(commit_editmsg), NULL, env);\n \t}\n \tif (!no_verify &&\ndiff --git a/templates/hooks--commit-msg b/templates/hooks--commit-msg\nindex c5cdb9d..4ef86eb 100644\n--- a/templates/hooks--commit-msg\n+++ b/templates/hooks--commit-msg\n@@ -9,6 +9,9 @@\n # To enable this hook, make this file executable.\n\n # Uncomment the below to add a Signed-off-by line to the message.\n+# Doing this in a hook is a bad idea in general, but the prepare-commit-msg\n+# hook is more suited to it.\n+#\n # SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\\(.*>\\).*$/Signed-off-by: \\1/p')\n # grep -qs \"^$SOB\" \"$1\" || echo \"$SOB\" >> \"$1\"\n\ndiff --git a/templates/hooks--prepare-commit-msg b/templates/hooks--prepare-commit-msg\nnew file mode 100644\nindex 0000000..176283b\n--- /dev/null\n+++ b/templates/hooks--prepare-commit-msg\n@@ -0,0 +1,14 @@\n+#!/bin/sh\n+#\n+# An example hook script to prepare the commit log message.\n+# Called by git-commit with one argument, the name of the file\n+# that has the commit message.  The hook should exit with non-zero\n+# status after issuing an appropriate message if it wants to stop the\n+# commit.  The hook is allowed to edit the commit message file.\n+#\n+# To enable this hook, make this file executable.\n+\n+# This example adds a Signed-off-by line to the message, that can\n+# still be edited.\n+SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\\(.*>\\).*$/Signed-off-by: \\1/p')\n+grep -qs \"^$SOB\" \"$1\" || echo \"$SOB\" >> \"$1\"\n-- \n1.5.3.4.910.gc5122-dirty\n"},{"id":"65888","messageId":"alpine.LSU.1.00.0801181545530.5731@racer.site","threadId":"11667","inReplyTo":"4790BCED.4050207@gnu.org","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-01-18T15:47:54Z","receivedAt":"2008-01-18T15:47:54Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 18 Jan 2008, Paolo Bonzini wrote:\n\n> The prepare-commit-msg hook is run whenever a \"fresh\" commit message \n> (i.e. not one taken from another commit with -c) is shown in the editor. \n> It can modify the commit message in-place and/or abort the commit.\n> \n> While the default hook just adds a Signed-Off-By line at the bottom of \n> the commit messsage, the hook is more intended to build a template for \n> the commit message following project standards.\n\nWould it not be much better for that hook to verify that the template has \nnot been added?\n\nOr would not be yet even better to use the commit.template config \nvariable, which was intended for that purpose?\n\nCiao,\nDscho\n"},{"id":"65889","messageId":"4790CAF7.5010908@gnu.org","threadId":"11667","inReplyTo":"alpine.LSU.1.00.0801181545530.5731@racer.site","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Paolo Bonzini","fromEmail":"bonzini@gnu.org","sentAt":"2008-01-18T15:51:19Z","receivedAt":"2008-01-18T15:51:19Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"\n>> The prepare-commit-msg hook is run whenever a \"fresh\" commit message \n>> (i.e. not one taken from another commit with -c) is shown in the editor. \n>> It can modify the commit message in-place and/or abort the commit.\n>>\n>> While the default hook just adds a Signed-Off-By line at the bottom of \n>> the commit messsage, the hook is more intended to build a template for \n>> the commit message following project standards.\n> \n> Would it not be much better for that hook to verify that the template has \n> not been added?\n\nI fail to parse this.\n\n> Or would not be yet even better to use the commit.template config \n> variable, which was intended for that purpose?\n\nThe template might not necessarily be fixed, for example it could be \npreloaded with the list of modified files.  See the cover letter for an \nexample.\n\nPaolo\n"},{"id":"65891","messageId":"alpine.LSU.1.00.0801181605020.5731@racer.site","threadId":"11667","inReplyTo":"4790CAF7.5010908@gnu.org","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-01-18T16:06:00Z","receivedAt":"2008-01-18T16:06:00Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 18 Jan 2008, Paolo Bonzini wrote:\n\n> \n> > > The prepare-commit-msg hook is run whenever a \"fresh\" commit message \n> > > (i.e. not one taken from another commit with -c) is shown in the \n> > > editor. It can modify the commit message in-place and/or abort the \n> > > commit.\n> > > \n> > > While the default hook just adds a Signed-Off-By line at the bottom \n> > > of the commit messsage, the hook is more intended to build a \n> > > template for the commit message following project standards.\n> > \n> > Would it not be much better for that hook to verify that the template \n> > has not been added?\n> \n> I fail to parse this.\n\nWhat I meant is this:\n\nIn the message hook, just grep if the template was already added.  If it \nwas, just return.  If it was not, add it.\n\nNo need for yet another hook.\n\nCiao,\nDscho\n"},{"id":"65895","messageId":"4790D5CF.8000602@gnu.org","threadId":"11667","inReplyTo":"alpine.LSU.1.00.0801181605020.5731@racer.site","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Paolo Bonzini","fromEmail":"bonzini@gnu.org","sentAt":"2008-01-18T16:37:35Z","receivedAt":"2008-01-18T16:37:35Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"\n> In the message hook, just grep if the template was already added.  If it \n> was, just return.  If it was not, add it.\n\nAh, so you want me to always type \":q!\" to exit and unnecessarily \ncomplicate the commit-msg hook.  Cunning, but no, thanks.\n\nI'll make an example.  This is my prepare-commit-msg hook:\n\ndiff_collect_changelog ()\n{\n   git diff \"$@\" -- \\\n    `git diff \"$@\" --name-status -r | \\\n         awk '/ChangeLog/ { print substr ($0, 3) }'` | sed -n \\\n     -e '/^@@/,/^+/ {' \\\n     -e '  s/^ //p' \\\n     -e '  t' \\\n     -e '}' \\\n     -e '/^diff/,/^@@/ {' \\\n     -e '  s/^diff --git a\\/\\(.*\\)\\/ChangeLog[^ ]* b\\/.*/\\1:/p' \\\n     -e '  tdummy' \\\n     -e '  :dummy' \\\n     -e '  d' \\\n     -e '}' \\\n     -e 's/^+//p' \\\n     -e 't'\n}\n\ndiff_collect_changelog --cached > /tmp/foo$$\ncat \"$GIT_COMMIT_MSG\" >> /tmp/foo$$ && \\\n   mv /tmp/foo$$ \"$GIT_COMMIT_MSG\"\nrm -f /tmp/foo$$\n\nor something like that.  The alternative I see would be to start the vi \nediting session with \"!!make_changelog --cached\".  So I thought about \nhaving an hook that runs the command for me.  Do you have better ideas?\n\nPaolo\n"},{"id":"65903","messageId":"alpine.LSU.1.00.0801181804410.5731@racer.site","threadId":"11667","inReplyTo":"4790D5CF.8000602@gnu.org","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-01-18T18:06:07Z","receivedAt":"2008-01-18T18:06:07Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 18 Jan 2008, Paolo Bonzini wrote:\n\n> \n> > In the message hook, just grep if the template was already added.  If it\n> > was, just return.  If it was not, add it.\n> \n> Ah, so you want me to always type \":q!\" to exit and unnecessarily \n> complicate the commit-msg hook.  Cunning, but no, thanks.\n\nNo, my intention was to avoid complications.  Like introducing yet another \ncommit hook.  I like clean, elegant semantics.  I don't like overbloated \nsemantics.  That's why I speak up whenever I fear it is entering git.\n\nHth,\nDscho\n"},{"id":"65907","messageId":"4790F54D.7000008@gnu.org","threadId":"11667","inReplyTo":"alpine.LSU.1.00.0801181804410.5731@racer.site","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Paolo Bonzini","fromEmail":"bonzini@gnu.org","sentAt":"2008-01-18T18:51:57Z","receivedAt":"2008-01-18T18:51:57Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"\n> No, my intention was to avoid complications.  Like introducing yet another \n> commit hook.  I like clean, elegant semantics.  I don't like overbloated \n> semantics.  That's why I speak up whenever I fear it is entering git.\n\nDo you think my three line patch is too complicated?  Possibly I was too\nzealous in documenting the semantics for the new hook and that looked\nlike unelegant semantics.\n\nDo you have another possibility which allows the same workflow (git\ncommit shows the output of that script) within the existing framework?\n\nPaolo\n"},{"id":"65908","messageId":"D54C77E4-D7FB-4CFC-81A6-AA4A0E66BA5D@lrde.epita.fr","threadId":"11667","inReplyTo":"alpine.LSU.1.00.0801181804410.5731@racer.site","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Benoit Sigoure","fromEmail":"tsuna@lrde.epita.fr","sentAt":"2008-01-18T19:01:18Z","receivedAt":"2008-01-18T19:01:18Z","isPatch":true,"sender":{"key":"tsunanet@gmail.com","avatar":"https://avatars.githubusercontent.com/u/128281?v=4"},"body":"On Jan 18, 2008, at 7:06 PM, Johannes Schindelin wrote:\n\n> On Fri, 18 Jan 2008, Paolo Bonzini wrote:\n>\n>>\n>>> In the message hook, just grep if the template was already  \n>>> added.  If it\n>>> was, just return.  If it was not, add it.\n>>\n>> Ah, so you want me to always type \":q!\" to exit and unnecessarily\n>> complicate the commit-msg hook.  Cunning, but no, thanks.\n>\n> No, my intention was to avoid complications.  Like introducing yet  \n> another\n> commit hook.  I like clean, elegant semantics.  I don't like  \n> overbloated\n> semantics.  That's why I speak up whenever I fear it is entering git.\n\n\nFWIW I'd love such a hook and I've been writing wrappers around Git  \ncommit for over a year now to simulate this.  I know many people with  \nwhom I work that would also love such a feature.\n\n-- \nBenoit Sigoure aka Tsuna\nEPITA Research and Development Laboratory\n"},{"id":"65909","messageId":"20080118190509.GA3411@steel.home","threadId":"11667","inReplyTo":"4790BCED.4050207@gnu.org","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2008-01-18T19:05:09Z","receivedAt":"2008-01-18T19:05:09Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Paolo Bonzini, Fri, Jan 18, 2008 15:51:25 +0100:\n> +\t\tif (!edit_message) {\n> +\t\t\trun_hook(index_file, \"prepare-commit-msg\", git_path(commit_editmsg));\n> +\t\t}\n>  \t\tlaunch_editor(git_path(commit_editmsg), NULL, env);\n\n\"preedit-new-commit-msg\", perhaps. A \"prepare-\" suggests it is called\nevery time, even if no editor is specified, which it is not.\n\nAnd it really does look like a template...\n"},{"id":"65912","messageId":"47910229.90700@gnu.org","threadId":"11667","inReplyTo":"20080118190509.GA3411@steel.home","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Paolo Bonzini","fromEmail":"bonzini@gnu.org","sentAt":"2008-01-18T19:46:49Z","receivedAt":"2008-01-18T19:46:49Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"Alex Riesen wrote:\n> Paolo Bonzini, Fri, Jan 18, 2008 15:51:25 +0100:\n>> +\t\tif (!edit_message) {\n>> +\t\t\trun_hook(index_file, \"prepare-commit-msg\", git_path(commit_editmsg));\n>> +\t\t}\n>>  \t\tlaunch_editor(git_path(commit_editmsg), NULL, env);\n> \n> \"preedit-new-commit-msg\", perhaps. A \"prepare-\" suggests it is called\n> every time, even if no editor is specified, which it is not.\n> \n> And it really does look like a template...\n\nIt is, but quite a powerful one. :-)  template-commit-msg?\n\nPaolo\n"},{"id":"65923","messageId":"20080118210825.GB3411@steel.home","threadId":"11667","inReplyTo":"47910229.90700@gnu.org","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2008-01-18T21:08:25Z","receivedAt":"2008-01-18T21:08:25Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Paolo Bonzini, Fri, Jan 18, 2008 20:46:49 +0100:\n> Alex Riesen wrote:\n>> Paolo Bonzini, Fri, Jan 18, 2008 15:51:25 +0100:\n>>> +\t\tif (!edit_message) {\n>>> +\t\t\trun_hook(index_file, \"prepare-commit-msg\", git_path(commit_editmsg));\n>>> +\t\t}\n>>>  \t\tlaunch_editor(git_path(commit_editmsg), NULL, env);\n>> \"preedit-new-commit-msg\", perhaps. A \"prepare-\" suggests it is called\n>> every time, even if no editor is specified, which it is not.\n>> And it really does look like a template...\n>\n> It is, but quite a powerful one. :-)\n\nExcept that \"template\" is already taken. Someone uses it and some may\neven got used to \"template\" having that meaning.\n\n> template-commit-msg?\n\nNot really. It will be run even if the template (the one Git have\nalready) is not used.\n\nIt really looks a bit complicated. If at all, how about running that\n\"pre-editor\" hook with information about where the message comes from?\n\nI.e. if the message comes from a template:\n\n    preedit-commit-msg .git/COMMIT_MSG template\n\nor, for a message coming from commit:\n\n    preedit-commit-msg .git/COMMIT_MSG commit 0123456789abdef\n\nor, for a message coming from a file\n\n    preedit-commit-msg .git/COMMIT_MSG file user/path/to/file\n\nand finally, for a new message:\n\n    preedit-commit-msg .git/COMMIT_MSG\n\n?\n"},{"id":"65927","messageId":"7vbq7ibxhh.fsf@gitster.siamese.dyndns.org","threadId":"11667","inReplyTo":"4790BCED.4050207@gnu.org","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-01-18T22:05:46Z","receivedAt":"2008-01-18T22:05:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"I do not particularly like hooks that act before or after an\noperation is initiated locally, act solely on local data.  This\nis maybe because I still consider git tools building blocks\nsuitable for higher level scripting more than other people do.\n\nThere are five valid reasons you might want a hook to a git\noperation:\n\n (1) A hook that countermands the normal decision made by the\n     underlying command.  Examples of this class are the update\n     hook and the pre-commit hook.\n\n (2) A hook that operates on data generated after the command\n     starts to run.  The ability to munge the commit log message\n     by the commit-msg hook is an example.\n\n (3) A hook that operates on the remote end of the connection\n     that you may not otherwise have access to other than over\n     the git protocol.  An example is the post-update hook.\n\n (4) A hook that runs under a lock that is acquired by the\n     command for mutual exclusion.  Currently there is no\n     example, but if we allowed the update hook to modify the\n     commit that was pushed through send-pack => receive-pack\n     pair, which was discussed on the list a while ago, it would\n     be a good example of this.\n\n (5) A hook that is run differently depending on the outcome of\n     the command.  The post-merge hook conditionally run by\n     git-pull is an example of this (it is not even run if no\n     merge takes place).  Another example is the post-checkout\n     hook that gets information that is otherwise harder to get\n     (namely, if it was a branch checkout or file checkout --\n     you can figure it out by examining the command line but\n     that already is part of the processing git-checkout does\n     anyway, so no need to force duplicating that code in the\n     userland).\n\nYou cannot do an equivalent operation from outside the git\ncommand for the above classes of operations.  You need hooks\nfor them.\n\nOn the other hand, if you want to always cause an action before\nrunning a git opeation locally, you do not have to have a hook.\nYou can just prepare such a message based on GNU ChangeLog and\nthen run git-commit with -F, both inside your wrapper.\n\nOf course there can be a very valid exception to the above\npolicy.  If it is common enough so that the policy means\neffectively everybody has to reinvent the same wrapper.  But for\nthis particular case I still do not see that is the case.\n"},{"id":"65948","messageId":"4791C3A8.7000308@gnu.org","threadId":"11667","inReplyTo":"7vbq7ibxhh.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Paolo Bonzini","fromEmail":"bonzini@gnu.org","sentAt":"2008-01-19T09:32:24Z","receivedAt":"2008-01-19T09:32:24Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"\n> On the other hand, if you want to always cause an action before\n> running a git opeation locally, you do not have to have a hook.\n> You can just prepare such a message based on GNU ChangeLog and\n> then run git-commit with -F, both inside your wrapper.\n\nI see two other possibilities:\n\n1) Would you prefer allowing to run a command by setting commit.template \nto something starting with an exclamation mark, i.e. something like \n\"!git diff --cached --name-status -r\"?\n\n2) The pre-commit could receive a file name on the command line.  If it \ncreates that file, it would be used as a template for the commit \nmessage.  The default implementation of pre-commit could include, \ncommented out, a reimplementation of prepare_log_message.  I like this \nthe least.\n\n3) Consider that the patch, as I implemented it, does not act solely on \nlocal data, because the index could be modified by the pre-commit hook. \n  This possibility is contemplated explicitly in builtin-commit.c:\n\n         /*\n          * Re-read the index as pre-commit hook could have updated it,\n          * and write it out as a tree.\n          */\n\nPaolo\n"},{"id":"65958","messageId":"alpine.LSU.1.00.0801191119050.5731@racer.site","threadId":"11667","inReplyTo":"4791C3A8.7000308@gnu.org","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-01-19T11:20:42Z","receivedAt":"2008-01-19T11:20:42Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 19 Jan 2008, Paolo Bonzini wrote:\n\n> > On the other hand, if you want to always cause an action before \n> > running a git opeation locally, you do not have to have a hook. You \n> > can just prepare such a message based on GNU ChangeLog and then run \n> > git-commit with -F, both inside your wrapper.\n> \n> I see two other possibilities:\n> \n> 1) [..]\n>\n> 2) [..]\n>\n> 3) [..]\n\nOf course, there is a fourth of \"two other\" possibilities:\n\nMake a script calling git-commit with \"-F - -e\" and pipe your generated \ntemplate into it.\n\nUse this script whenever you want to create a new commit.\n\nHth,\nDscho\n"},{"id":"65978","messageId":"143E9431-934C-4711-A580-8AC60A9D472E@lrde.epita.fr","threadId":"11667","inReplyTo":"alpine.LSU.1.00.0801191119050.5731@racer.site","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Benoit Sigoure","fromEmail":"tsuna@lrde.epita.fr","sentAt":"2008-01-19T15:41:38Z","receivedAt":"2008-01-19T15:41:38Z","isPatch":true,"sender":{"key":"tsunanet@gmail.com","avatar":"https://avatars.githubusercontent.com/u/128281?v=4"},"body":"On Jan 19, 2008, at 12:20 PM, Johannes Schindelin wrote:\n\n> On Sat, 19 Jan 2008, Paolo Bonzini wrote:\n>\n>>> On the other hand, if you want to always cause an action before\n>>> running a git opeation locally, you do not have to have a hook. You\n>>> can just prepare such a message based on GNU ChangeLog and then run\n>>> git-commit with -F, both inside your wrapper.\n>>\n>> I see two other possibilities:\n>>\n>> 1) [..]\n>>\n>> 2) [..]\n>>\n>> 3) [..]\n>\n> Of course, there is a fourth of \"two other\" possibilities:\n>\n> Make a script calling git-commit with \"-F - -e\" and pipe your  \n> generated\n> template into it.\n>\n> Use this script whenever you want to create a new commit.\n\n\nThat's what I've done for over a year (http://repo.or.cz/w/svn- \nwrapper.git -- it started out as a wrapper around SVN but also works  \nfine with Git) and many people also made their own script to achieve  \nsomething similar (e.g, vc-dwim http://lists.gnu.org/archive/html/bug- \ngnulib/2007-10/msg00135.html).\n\nHaving such a wrapper in Git would just make our life easier.\n\n-- \nBenoit Sigoure aka Tsuna\nEPITA Research and Development Laboratory\n"},{"id":"65979","messageId":"47921F8F.9020401@gnu.org","threadId":"11667","inReplyTo":"alpine.LSU.1.00.0801191119050.5731@racer.site","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Paolo Bonzini","fromEmail":"bonzini@gnu.org","sentAt":"2008-01-19T16:04:31Z","receivedAt":"2008-01-19T16:04:31Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"\n> Of course, there is a fourth of \"two other\" possibilities:\n\n(The third was just the previously posted patch, so two \"other than the \nposted one\") :-)\n\n> Make a script calling git-commit with \"-F - -e\" and pipe your generated \n> template into it.\n\nYou considered that this script should parse -a, -i, -o, whatever, \nright? ;-)\n\nThe point is that a hook can use the index as prepared by git-commit.\n\nPaolo\n"},{"id":"66056","messageId":"7vd4rw6siv.fsf@gitster.siamese.dyndns.org","threadId":"11667","inReplyTo":"alpine.LSU.1.00.0801191119050.5731@racer.site","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-01-20T22:28:40Z","receivedAt":"2008-01-20T22:28:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> Of course, there is a fourth of \"two other\" possibilities:\n>\n> Make a script calling git-commit with \"-F - -e\" and pipe your generated \n> template into it.\n>\n> Use this script whenever you want to create a new commit.\n\nI think that the approach has one huge advantage.  Commands\nother than \"git commit\" itself (\"git merge\", \"git rebase\", \"git\nam\", etc.) do call \"git commit\" to record the changes they made.\nI suspect these command would not want this template behaviour,\nand not adding this custom commit message \"feature\" to \"git\ncommit\" would avoid the risk of breaking them.\n\nAt the same time, this exact issue could be a drawback.  Some of\nthem _might_ want it.  But in that case, the the custom template\n\"hook\" needs to be told _why_ it is being called, so that it can\nadjust its behaviour.\n"},{"id":"66083","messageId":"479438D1.2050107@gnu.org","threadId":"11667","inReplyTo":"7vd4rw6siv.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Paolo Bonzini","fromEmail":"bonzini@gnu.org","sentAt":"2008-01-21T06:16:49Z","receivedAt":"2008-01-21T06:16:49Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"\n> I think that the approach has one huge advantage.  Commands\n> other than \"git commit\" itself (\"git merge\", \"git rebase\", \"git\n> am\", etc.) do call \"git commit\" to record the changes they made.\n> I suspect these command would not want this template behaviour,\n> and not adding this custom commit message \"feature\" to \"git\n> commit\" would avoid the risk of breaking them.\n\nMy patch does not do that.  Of all these commands, only git-rebase uses \nporcelain git-commit rather than plumbing git-commit-tree, and it uses \nthe -C or -F options (which disable the hook in my patch).\n\n> At the same time, this exact issue could be a drawback.  Some of\n> them _might_ want it.  But in that case, the the custom template\n> \"hook\" needs to be told _why_ it is being called, so that it can\n> adjust its behaviour.\n\nI would like to understand why both of you have not considered the point \n  that the script would need the updated index from git-commit.  Because \nshort of reusing half of the old Bourne-shell git-commit, I don't see \nhow this would be possible, but maybe there's something obvious.  Or \nmaybe we need new plumbing like git-build-index -- then I'd still need \nto complicate my script to build a template commit message, but I \nwouldn't need to muddle myself (not too much at least) in handling the \ncommand line.\n\nPaolo\n"},{"id":"66117","messageId":"alpine.LSU.1.00.0801211101450.5731@racer.site","threadId":"11667","inReplyTo":"479438D1.2050107@gnu.org","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-01-21T11:04:29Z","receivedAt":"2008-01-21T11:04:29Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 21 Jan 2008, Paolo Bonzini wrote:\n\n> I would like to understand why both of you have not considered the point \n> that the script would need the updated index from git-commit.\n\nI have.  But I want to avoid a regression at any cost.  And your patch \njust looks to me like it could do that.\n\nBut it _has_ been already suggested that you could provide arguments for \nthe existing msg-hook, which would not break anything, since the hook does \nnot get any argument yet, and therefore existing hooks would be \nunaffected.\n\nAlso, the change would be non-intrusive, easy-to-review, and it would not \ntake so much time away from the bug-fixing that we want to do right now in \nthe rc-cycle.\n\nOkay?\nDscho\n"},{"id":"66133","messageId":"47948C9B.7030100@gnu.org","threadId":"11667","inReplyTo":"alpine.LSU.1.00.0801211101450.5731@racer.site","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Paolo Bonzini","fromEmail":"bonzini@gnu.org","sentAt":"2008-01-21T12:14:19Z","receivedAt":"2008-01-21T12:14:19Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"> I have.  But I want to avoid a regression at any cost.  And your patch \n> just looks to me like it could do that.\n\nWhat kind of regression?\n\n> But it _has_ been already suggested that you could provide arguments for \n> the existing msg-hook, which would not break anything\n\nSure it won't break anything, but it won't work either!  The existing \nmessage hook runs after the editing session -- I want the hook to \nintroduce text that is merely a suggestion that the user can delete, or \na template that the user needs to customize further.\n\n> since the hook does \n> not get any argument yet, and therefore existing hooks would be \n> unaffected.\n\nHow does adding a new hook affect existing hooks?\n\n> Also, the change would be non-intrusive, easy-to-review\n\nPlease.  That's ludicrous.\n\nMy patch is 3 lines of inserted code and 0 modified lines, checking one \nvariable that is set once in builtin-commit.c (edit_message).  The \ndocumentation says that it runs whenever the editor runs except for -c, \nand launch_editor runs after the 3 lines of code I inserted.\n\nSeeing how biased you are, I don't really know why I bothered answering you.\n\n> take so much time away from the bug-fixing that we want to do right now in \n\nThat's the first sensible argument that I hear.\n\nPaolo\n"},{"id":"66136","messageId":"alpine.LSU.1.00.0801211231480.5731@racer.site","threadId":"11667","inReplyTo":"47948C9B.7030100@gnu.org","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-01-21T12:46:06Z","receivedAt":"2008-01-21T12:46:06Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 21 Jan 2008, Paolo Bonzini wrote:\n\n> > I have.  But I want to avoid a regression at any cost.  And your patch \n> > just looks to me like it could do that.\n> \n> What kind of regression?\n\nSee below.\n\n> > But it _has_ been already suggested that you could provide arguments \n> > for the existing msg-hook, which would not break anything\n> \n> Sure it won't break anything, but it won't work either!  The existing \n> message hook runs after the editing session -- I want the hook to \n> introduce text that is merely a suggestion that the user can delete, or \n> a template that the user needs to customize further.\n\nOMG you're right.  But why didn't you say so in the commit message?  \nSomething like \"This hook complements the commit-msg hook, in that it runs \n_before_ the editor is launched\".\n\n> > since the hook does not get any argument yet, and therefore existing \n> > hooks would be unaffected.\n> \n> How does adding a new hook affect existing hooks?\n\nMy impression -- even after reading your commit message -- was that it \ndoes almost the same as the commit-msg hook, only that it runs _in \naddition_ to it when doing a non-amend commit.\n\nFWIW this is the first reply by you that uncovers this error of mine.\n\n> > Also, the change would be non-intrusive, easy-to-review\n> \n> Please.  That's ludicrous.\n> \n> My patch is 3 lines of inserted code and 0 modified lines, checking one \n> variable that is set once in builtin-commit.c (edit_message).\n\nActually, after reading the commit message I was in \n\"this-is-not-necessary\" mode, and therefore the diffstat looked too large \nfor me.\n\nThat is why I thought that a regression was looming somewhere.\n\nAnd in reality, your patch should be 2 lines of code.\n\n> The documentation says that it runs whenever the editor runs except for \n> -c, and launch_editor runs after the 3 lines of code I inserted.\n\nActually, reading your patch again I think it also triggers for \"-c\", as \nwell as for \"[-C|-F|-m] ... -e\".\n\nAnd it does not necessarily start with \"an empty log message\"; think of \n\"--signoff\".\n\nBesides, I think that the name should be more to the point, something like \n\"pre-edit-commit-msg\".\n\nAlso, I should think that the hook should get some information about the \ncircumstances (possibly as command line arguments), given that it is \ncalled in more cases than you said.\n\nSo I think the patch is not ready yet, although I finally got the _point_ \nof having yet-another hook.\n\n> Seeing how biased you are, I don't really know why I bothered answering \n> you.\n\nSo I am biased.  And you have to convince me.  It's not that hard to \nconvince me.\n\n> > take so much time away from the bug-fixing that we want to do right \n> > now in\n> \n> That's the first sensible argument that I hear.\n\nHeh.  Then I'm happy that I put it into my mail, too!\n\nCiao,\nDscho\n"},{"id":"66137","messageId":"4794972F.9000007@gnu.org","threadId":"11667","inReplyTo":"alpine.LSU.1.00.0801211231480.5731@racer.site","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Paolo Bonzini","fromEmail":"bonzini@gnu.org","sentAt":"2008-01-21T12:59:27Z","receivedAt":"2008-01-21T12:59:27Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"\n>> Sure it won't break anything, but it won't work either!  The existing \n>> message hook runs after the editing session -- I want the hook to \n>> introduce text that is merely a suggestion that the user can delete, or \n>> a template that the user needs to customize further.\n> \n> OMG you're right.  But why didn't you say so in the commit message?  \n> Something like \"This hook complements the commit-msg hook, in that it runs \n> _before_ the editor is launched\".\n\nI can't believe this. ;-)  At least I'm laughing for something nice now!\n\nYou're right, I should have said instead of this:\n\n> The prepare-commit-msg hook is run whenever a \"fresh\" commit message \n> (i.e. not one taken from another commit with -c) is shown in the editor. \n\n... just before a \"fresh\" commit message is shown in the editor.\n          ^^^^^^\n\n>>> Also, the change would be non-intrusive, easy-to-review\n>> Please.  That's ludicrous.\n>>\n>> My patch is 3 lines of inserted code and 0 modified lines, checking one \n>> variable that is set once in builtin-commit.c (edit_message).\n> \n> Actually, after reading the commit message I was in \n> \"this-is-not-necessary\" mode, and therefore the diffstat looked too large \n> for me.\n\nYes, but still the diffstat was all .txt files... ;-)\n\n> Actually, reading your patch again I think it also triggers for \"-c\", as \n> well as for \"[-C|-F|-m] ... -e\".\n\nNot for \"-c\", that's the point of the \"edit_message\" check.  You're \nright about \"-e\" though.\n\nPoints taken, and patch will be resubmitted after 1.5.4.\n\nPaolo\n"},{"id":"66219","messageId":"7vve5mx0hd.fsf@gitster.siamese.dyndns.org","threadId":"11667","inReplyTo":"4794972F.9000007@gnu.org","subject":"Re: [PATCH] git-commit: add a prepare-commit-msg hook","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-01-21T22:44:30Z","receivedAt":"2008-01-21T22:44:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Paolo Bonzini <bonzini@gnu.org> writes:\n\n>> Actually, reading your patch again I think it also triggers for\n>> \"-c\", as well as for \"[-C|-F|-m] ... -e\".\n>\n> Not for \"-c\", that's the point of the \"edit_message\" check.  You're\n> right about \"-e\" though.\n>\n> Points taken, and patch will be resubmitted after 1.5.4.\n\nThanks.  I think the approach is sane, and it naturally falls\ninto the second category of \"why we might want to a hook for\"\nlist I sent earlier.\n\nI do not think adding \"-X makes that hook ignored\" for\ndescription of every option is warranted, though.  Users should\nnot have to be reminded that there is a hook he may never use\nand it does not trigger if he specifies his own message using -X\nor -Y or -Z option.\n\nThe usage of the hook is optional, and the primary description\nof what it does and why a user might want to use it should be in\nits own description (perhaps in hooks.txt and a section that\nlists hooks in git-commit manpage).  As long as that description\nmakes it clear that the hook is a way to specify a dynamic\ntemplate in a situation that requries a fresh message, the users\nwho are interested in using it would perfectly well understand\nthat options that make git-commit not to take a fresh message\nwould not invoke the hook.\n"}]}