Re: The commit-msg hook is not invoked by git-merge as specified in documentation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Kalle Kromann <kalle.kromann@xxxxxxxxxx> 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...




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux