{"thread":{"id":"53606","subject":"The commit-msg hook is not invoked by git-merge as specified in documentation","startedAt":"2020-06-03T12:46:33Z","lastAt":"2020-06-04T15:14:51Z","messageCount":5,"participants":["Kalle Kromann","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"399073","messageId":"AM0PR08MB55379DD182941E93F3BD3D37D7880@AM0PR08MB5537.eurprd08.prod.outlook.com","threadId":"53606","inReplyTo":null,"subject":"The commit-msg hook is not invoked by git-merge as specified in documentation","fromName":"Kalle Kromann","fromEmail":"kalle.kromann@man-es.com","sentAt":"2020-06-03T12:46:27Z","receivedAt":"2020-06-03T12:46:33Z","isPatch":false,"sender":{"key":"kalle.kromann@man-es.com","avatar":null},"body":"Hello,\n\nAt least two places in the git docs it is specified that the hook \"commit-msg\" is invoked by both git-commit and git-merge.\n\nhttps://git-scm.com/docs/githooks#_commit_msg\nhttps://git-scm.com/docs/git-merge#Documentation/git-merge.txt---no-verify\n\nI'm experiencing a different behavior however. The hook seems to work fine on git-commit, but is not invoked by git-merge.\nWhen I use git-merge my text editor opens with the default message, but when I close the editor the hook is not invoked as I would expect.\n\nFor reference, the prepare-commit-msg hook works with both commands as expected.\n\nIs there something subtle I'm overlooking?\nOf course a fast forward merge should not invoke the commit-msg hook, because no commit is made.\nBut in my tests with non FF-merges the hook is still not invoked.\n\nKind regards,\nKalle Kromann\nThis is an e-mail from MAN Energy Solutions, branch of MAN Energy Solutions SE, Germany (CVR no. 31611792).\nThis e-mail (including any attachments) is confidential and may be privileged. If you have received this e-mail by mistake, please notify the sender by e-mail and delete it from your system.\nAny unauthorized use or dissemination of this e-mail or its contents in whole or in part is strictly prohibited. Please note that e-mails are susceptible to change.\nMAN Energy Solutions SE (including its group companies) shall not be liable for improper or incomplete transmission of the information contained in this e-mail or for any delay in its receipt.\nMAN Energy Solutions SE (or its group companies) does not guarantee that this e-mail has not been compromised or that it is free of viruses, interceptions or interference.\n"},{"id":"399085","messageId":"xmqq367crlti.fsf@gitster.c.googlers.com","threadId":"53606","inReplyTo":"AM0PR08MB55379DD182941E93F3BD3D37D7880@AM0PR08MB5537.eurprd08.prod.outlook.com","subject":"Re: The commit-msg hook is not invoked by git-merge as specified in documentation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-03T19:28:09Z","receivedAt":"2020-06-03T19:28:17Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kalle Kromann <kalle.kromann@man-es.com> writes:\n\n> For reference, the prepare-commit-msg hook works with both commands as expected.\n>\n> Is there something subtle I'm overlooking?\n\nOn what platform, and which version of Git are we talking about?\nWhat is the difference between these two hooks?  I.e. perhaps\n\n    $ ls -l .git/hooks/prepare-commit-msg .git/hooks/commit-msg\n\ntells you some subtle differences between the two?\n\n> Of course a fast forward merge should not invoke the commit-msg\n> hook, because no commit is made.  But in my tests with non\n> FF-merges the hook is still not invoked.\n\nOther than the last one, nothing comes to my mind.  And it does not\nreproduce for me.\n\nI just did this:\n\n    $ echo exit 1 >.git/hooks/commit-msg\n    $ chmod +x .git/hooks/commit-msg\n    $ git checkout master^0\n    $ git merge ds/line-log-on-bloom\n\t    ... editor launches and I save the message ...\n    Auto-merging revision.c\n    Auto-merging line-log.c\n    Auto-merging bloom.h\n    Auto-merging bloom.c\n    Not committing merge; use 'git commit' to complete the merge.\n\nThe last line comes from builtin/merge.c::abort_commit(), which is\ncalled from this piece of code in builtin/merge.c::prepare_to_commit()\n\n\tif (run_commit_hook(0 < option_edit, get_index_file(), \"prepare-commit-msg\",\n\t\t\t    git_path_merge_msg(the_repository), \"merge\", NULL))\n\t\tabort_commit(remoteheads, NULL);\n\tif (0 < option_edit) {\n\t\tif (launch_editor(git_path_merge_msg(the_repository), NULL, NULL))\n\t\t\tabort_commit(remoteheads, NULL);\n\t}\n\n\tif (!no_verify && run_commit_hook(0 < option_edit, get_index_file(),\n\t\t\t\t\t  \"commit-msg\",\n\t\t\t\t\t  git_path_merge_msg(the_repository), NULL))\n\t\tabort_commit(remoteheads, NULL);\n\nI do not have prepare-commit-msg, and my launch_editor() thing\nsuccessfully returned, and the call to abort_commit() is cleraly\ncoming from the last line, where run_commit_hook() noticed that the\ncommit-msg hook ran and reported a failure.\n\nAfter this, I did this to just confirm:\n\n    $ echo exit 0 >.git/hooks/commit-msg\n    $ git reset --hard\n    $ git merge ds/line-log-on-bloom\n\nThis time, instead of \"Not committing...\", I got\n\n    Merge made by the 'recursive' strategy.\n\nfollowed by the usual diffstat.\n\nThe above demonstrates that commit-msg does run well enough to cause\nits exit status affects the outcome in both cases.\n\nFor fun, I tried another.\n\n    $ echo exit 1 >.git/hooks/commit-msg\n    $ chmod -x .git/hooks/commit-msg\n    $ git reset --hard master\n    $ GIT_EDITOR=: git merge ds/line-log-on-bloom\n    Auto-merging revision.c\n    Auto-merging line-log.c\n    Auto-merging bloom.h\n    Auto-merging bloom.c\n    hint: The '.git/hooks/commit-msg' hook was ignored because it's not set as executable.\n    hint: You can disable this warning with `git config advice.ignoredHook false`.\n    Merge made by the 'recursive' strategy.\n    ... diffstat follows ...\n\nSo...\n\n"},{"id":"399108","messageId":"AM0PR08MB553711CE7CE5D39EC2CE8422D7890@AM0PR08MB5537.eurprd08.prod.outlook.com","threadId":"53606","inReplyTo":"xmqq367crlti.fsf@gitster.c.googlers.com","subject":"RE: The commit-msg hook is not invoked by git-merge as specified in documentation","fromName":"Kalle Kromann","fromEmail":"kalle.kromann@man-es.com","sentAt":"2020-06-04T08:27:29Z","receivedAt":"2020-06-04T08:27:34Z","isPatch":false,"sender":{"key":"kalle.kromann@man-es.com","avatar":null},"body":"Hello, thanks for the reply.\n\nSorry for not including it originally, the platform I was using to test was WSL (Windows subsystem for Linux).\nAnd the git version was the latest available from apt-get in WSL, 2.7.4.\n\nIt seems like one of these things is affecting the execution of the hook.\nI just did the exact same test in Cygwin with git version 2.17 and it works as expected here.\n\nDo you know if it's a recent change that git-merge should invoke the hook as well?\nOr do you think it is related to using git in WSL?\n\nThanks again!\nThis is an e-mail from MAN Energy Solutions, branch of MAN Energy Solutions SE, Germany (CVR no. 31611792).\nThis e-mail (including any attachments) is confidential and may be privileged. If you have received this e-mail by mistake, please notify the sender by e-mail and delete it from your system.\nAny unauthorized use or dissemination of this e-mail or its contents in whole or in part is strictly prohibited. Please note that e-mails are susceptible to change.\nMAN Energy Solutions SE (including its group companies) shall not be liable for improper or incomplete transmission of the information contained in this e-mail or for any delay in its receipt.\nMAN Energy Solutions SE (or its group companies) does not guarantee that this e-mail has not been compromised or that it is free of viruses, interceptions or interference.\n"},{"id":"399120","messageId":"xmqq8sh2rhm5.fsf@gitster.c.googlers.com","threadId":"53606","inReplyTo":"AM0PR08MB553711CE7CE5D39EC2CE8422D7890@AM0PR08MB5537.eurprd08.prod.outlook.com","subject":"Re: The commit-msg hook is not invoked by git-merge as specified in documentation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-04T15:11:14Z","receivedAt":"2020-06-04T15:11:20Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kalle Kromann <kalle.kromann@man-es.com> writes:\n\n> And the git version was the latest available from apt-get in WSL, 2.7.4.\n\nWow, that's ancient.  \n\n\"git merge\" started calling commit-msg hook f8b86359 (builtin/merge:\nhonor commit-msg hook for merges, 2017-09-07), which first appeared\nin 2.15 (from Oct 2017, that is also ancient in Git timescale) IIUC.\n\n\n"},{"id":"399121","messageId":"AM0PR08MB55374383893333BEA293041ED7890@AM0PR08MB5537.eurprd08.prod.outlook.com","threadId":"53606","inReplyTo":"xmqq8sh2rhm5.fsf@gitster.c.googlers.com","subject":"RE: The commit-msg hook is not invoked by git-merge as specified in documentation","fromName":"Kalle Kromann","fromEmail":"kalle.kromann@man-es.com","sentAt":"2020-06-04T15:14:47Z","receivedAt":"2020-06-04T15:14:51Z","isPatch":false,"sender":{"key":"kalle.kromann@man-es.com","avatar":null},"body":"Thank you so much for your help.\n\nI'm still quite new to git, and this was definitely a rookie mistake.\nThis is an e-mail from MAN Energy Solutions, branch of MAN Energy Solutions SE, Germany (CVR no. 31611792).\nThis e-mail (including any attachments) is confidential and may be privileged. If you have received this e-mail by mistake, please notify the sender by e-mail and delete it from your system.\nAny unauthorized use or dissemination of this e-mail or its contents in whole or in part is strictly prohibited. Please note that e-mails are susceptible to change.\nMAN Energy Solutions SE (including its group companies) shall not be liable for improper or incomplete transmission of the information contained in this e-mail or for any delay in its receipt.\nMAN Energy Solutions SE (or its group companies) does not guarantee that this e-mail has not been compromised or that it is free of viruses, interceptions or interference.\n"}]}