* [PATCH] git-merge: run commit hooks when making merge commits
@ 2007-07-11 10:32 Sam Vilain
2007-07-11 21:26 ` Junio C Hamano
0 siblings, 1 reply; 4+ messages in thread
From: Sam Vilain @ 2007-07-11 10:32 UTC (permalink / raw
To: git; +Cc: Sam Vilain
git-merge.sh was not running the commit hooks, so run them in the two
places where we go to commit.
Signed-off-by: Sam Vilain <sam.vilain@catalyst.net.nz>
---
Not sure if it should call these or some specialist hooks, like
git-am does.
git-merge.sh | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/git-merge.sh b/git-merge.sh
index 981d69d..ef4f51b 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -117,6 +117,29 @@ merge_name () {
fi
}
+call_pre_hooks () {
+ message="$1"
+ if test -x "$GIT_DIR"/hooks/pre-commit
+ then
+ "$GIT_DIR"/hooks/pre-commit || exit 1
+ fi
+ if test -x "$GIT_DIR"/hooks/commit-msg
+ then
+ printf '%s\n' "$message" > "$GIT_DIR"/MERGE_MSG
+ "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/MERGE_MSG || exit 1
+ cat "$GIT_DIR"/MERGE_MSG
+ else
+ echo "$message"
+ fi
+}
+
+call_post_hook () {
+ if test -x "$GIT_DIR"/hooks/post-commit
+ then
+ "$GIT_DIR"/hooks/post-commit
+ fi
+}
+
case "$#" in 0) usage ;; esac
have_message=
@@ -334,11 +357,13 @@ f,*)
result_tree=$(git-write-tree)
then
echo "Wonderful."
+ merge_msg=$(call_pre_hooks "$merge_msg")
result_commit=$(
printf '%s\n' "$merge_msg" |
git-commit-tree $result_tree -p HEAD -p "$1"
) || exit
finish "$result_commit" "In-index merge"
+ call_post_hook
dropsave
exit 0
fi
@@ -440,8 +465,10 @@ done
if test '' != "$result_tree"
then
parents=$(git-show-branch --independent "$head" "$@" | sed -e 's/^/-p /')
+ merge_msg=$(call_pre_hooks "$merge_msg")
result_commit=$(printf '%s\n' "$merge_msg" | git-commit-tree $result_tree $parents) || exit
finish "$result_commit" "Merge made by $wt_strategy."
+ call_post_hook
dropsave
exit 0
fi
--
1.5.2.1.1131.g3b90
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] git-merge: run commit hooks when making merge commits
2007-07-11 10:32 [PATCH] git-merge: run commit hooks when making merge commits Sam Vilain
@ 2007-07-11 21:26 ` Junio C Hamano
2007-07-11 23:21 ` Sam Vilain
2007-07-12 8:03 ` Andy Parkins
0 siblings, 2 replies; 4+ messages in thread
From: Junio C Hamano @ 2007-07-11 21:26 UTC (permalink / raw
To: Sam Vilain; +Cc: git
Sam Vilain <sam.vilain@catalyst.net.nz> writes:
> git-merge.sh was not running the commit hooks, so run them in the two
> places where we go to commit.
>
> Signed-off-by: Sam Vilain <sam.vilain@catalyst.net.nz>
> ---
> Not sure if it should call these or some specialist hooks, like
> git-am does.
I suspect some people have pre-commit scripts that have been
meant to catch style errors for their own commits, and invoking
that on merge would wreak havoc --- there is not much you can do
if you want to get the work done by somebody else at that point.
Introducing a new pre-merge-commit hook would probably be safer;
if one wants to use the same check as one's pre-commit does, the
new hook in the repository can exec $GIT_DIR/hooks/pre-commit.
The commit-msg hook I have no clue what people usually use it
for in the real world, but a merge commit message tends to be
quite different from the message you would give to your own
straight line commits, so custom reformatting rules people have
in commit-msg hook may not apply to merge commit messages.
Same for post-commit, but probably to lessor extent, as I
suspect people use that mostly for per-commit notification
mechanism.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] git-merge: run commit hooks when making merge commits
2007-07-11 21:26 ` Junio C Hamano
@ 2007-07-11 23:21 ` Sam Vilain
2007-07-12 8:03 ` Andy Parkins
1 sibling, 0 replies; 4+ messages in thread
From: Sam Vilain @ 2007-07-11 23:21 UTC (permalink / raw
To: Junio C Hamano; +Cc: git
Junio C Hamano wrote:
> Sam Vilain <sam.vilain@catalyst.net.nz> writes:
>
>> git-merge.sh was not running the commit hooks, so run them in the two
>> places where we go to commit.
>>
>> Signed-off-by: Sam Vilain <sam.vilain@catalyst.net.nz>
>> ---
>> Not sure if it should call these or some specialist hooks, like
>> git-am does.
>
> I suspect some people have pre-commit scripts that have been
> meant to catch style errors for their own commits, and invoking
> that on merge would wreak havoc --- there is not much you can do
> if you want to get the work done by somebody else at that point.
> Introducing a new pre-merge-commit hook would probably be safer;
> if one wants to use the same check as one's pre-commit does, the
> new hook in the repository can exec $GIT_DIR/hooks/pre-commit.
>
> The commit-msg hook I have no clue what people usually use it
> for in the real world, but a merge commit message tends to be
> quite different from the message you would give to your own
> straight line commits, so custom reformatting rules people have
> in commit-msg hook may not apply to merge commit messages.
True. OTOH, if you commit with `git commit` after a merge which failed
or was called with --no-commit, then it will call the commit hook. So
those scripts would have to deal with that case anyway.
So, should `git commit` detect it is committing a merge and call the
merge-hooks, should we use the same hooks, or, should this be something
like hooks/*-automerge ?
Sam.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] git-merge: run commit hooks when making merge commits
2007-07-11 21:26 ` Junio C Hamano
2007-07-11 23:21 ` Sam Vilain
@ 2007-07-12 8:03 ` Andy Parkins
1 sibling, 0 replies; 4+ messages in thread
From: Andy Parkins @ 2007-07-12 8:03 UTC (permalink / raw
To: git; +Cc: Junio C Hamano, Sam Vilain
On Wednesday 2007 July 11, Junio C Hamano wrote:
> The commit-msg hook I have no clue what people usually use it
> for in the real world, but a merge commit message tends to be
I use it for adding my Signed-Off-By automatically in my git repository. Of
course that's only valid for the likes of me because I can be sure that I
only ever commit my own patches, rather than integrating other people's.
Andy
--
Dr Andy Parkins, M Eng (hons), MIET
andyparkins@gmail.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-07-12 8:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-11 10:32 [PATCH] git-merge: run commit hooks when making merge commits Sam Vilain
2007-07-11 21:26 ` Junio C Hamano
2007-07-11 23:21 ` Sam Vilain
2007-07-12 8:03 ` Andy Parkins
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).