From: Junio C Hamano <gitster@pobox.com>
To: Kalle Kromann <kalle.kromann@man-es.com>
Cc: "git\@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: The commit-msg hook is not invoked by git-merge as specified in documentation
Date: Wed, 03 Jun 2020 12:28:09 -0700 [thread overview]
Message-ID: <xmqq367crlti.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <AM0PR08MB55379DD182941E93F3BD3D37D7880@AM0PR08MB5537.eurprd08.prod.outlook.com> (Kalle Kromann's message of "Wed, 3 Jun 2020 12:46:27 +0000")
Kalle Kromann <kalle.kromann@man-es.com> writes:
> For reference, the prepare-commit-msg hook works with both commands as expected.
>
> Is there something subtle I'm overlooking?
On what platform, and which version of Git are we talking about?
What is the difference between these two hooks? I.e. perhaps
$ ls -l .git/hooks/prepare-commit-msg .git/hooks/commit-msg
tells you some subtle differences between the two?
> Of course a fast forward merge should not invoke the commit-msg
> hook, because no commit is made. But in my tests with non
> FF-merges the hook is still not invoked.
Other than the last one, nothing comes to my mind. And it does not
reproduce for me.
I just did this:
$ echo exit 1 >.git/hooks/commit-msg
$ chmod +x .git/hooks/commit-msg
$ git checkout master^0
$ git merge ds/line-log-on-bloom
... editor launches and I save the message ...
Auto-merging revision.c
Auto-merging line-log.c
Auto-merging bloom.h
Auto-merging bloom.c
Not committing merge; use 'git commit' to complete the merge.
The last line comes from builtin/merge.c::abort_commit(), which is
called from this piece of code in builtin/merge.c::prepare_to_commit()
if (run_commit_hook(0 < option_edit, get_index_file(), "prepare-commit-msg",
git_path_merge_msg(the_repository), "merge", NULL))
abort_commit(remoteheads, NULL);
if (0 < option_edit) {
if (launch_editor(git_path_merge_msg(the_repository), NULL, NULL))
abort_commit(remoteheads, NULL);
}
if (!no_verify && run_commit_hook(0 < option_edit, get_index_file(),
"commit-msg",
git_path_merge_msg(the_repository), NULL))
abort_commit(remoteheads, NULL);
I do not have prepare-commit-msg, and my launch_editor() thing
successfully returned, and the call to abort_commit() is cleraly
coming from the last line, where run_commit_hook() noticed that the
commit-msg hook ran and reported a failure.
After this, I did this to just confirm:
$ echo exit 0 >.git/hooks/commit-msg
$ git reset --hard
$ git merge ds/line-log-on-bloom
This time, instead of "Not committing...", I got
Merge made by the 'recursive' strategy.
followed by the usual diffstat.
The above demonstrates that commit-msg does run well enough to cause
its exit status affects the outcome in both cases.
For fun, I tried another.
$ echo exit 1 >.git/hooks/commit-msg
$ chmod -x .git/hooks/commit-msg
$ git reset --hard master
$ GIT_EDITOR=: git merge ds/line-log-on-bloom
Auto-merging revision.c
Auto-merging line-log.c
Auto-merging bloom.h
Auto-merging bloom.c
hint: The '.git/hooks/commit-msg' hook was ignored because it's not set as executable.
hint: You can disable this warning with `git config advice.ignoredHook false`.
Merge made by the 'recursive' strategy.
... diffstat follows ...
So...
next prev parent reply other threads:[~2020-06-03 19:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-03 12:46 The commit-msg hook is not invoked by git-merge as specified in documentation Kalle Kromann
2020-06-03 19:28 ` Junio C Hamano [this message]
2020-06-04 8:27 ` Kalle Kromann
2020-06-04 15:11 ` Junio C Hamano
2020-06-04 15:14 ` Kalle Kromann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq367crlti.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=kalle.kromann@man-es.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).