{"thread":{"id":"8979","subject":"[PATCH] git-merge: run commit hooks when making merge commits","startedAt":"2007-07-11T10:32:00Z","lastAt":"2007-07-12T08:03:44Z","messageCount":4,"participants":["Sam Vilain","Junio C Hamano","Andy Parkins"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"47020","messageId":"11841499201242-git-send-email-sam.vilain@catalyst.net.nz","threadId":"8979","inReplyTo":null,"subject":"[PATCH] git-merge: run commit hooks when making merge commits","fromName":"Sam Vilain","fromEmail":"sam.vilain@catalyst.net.nz","sentAt":"2007-07-11T10:32:00Z","receivedAt":"2007-07-11T10:32:00Z","isPatch":true,"sender":{"key":"sam@vilain.net","avatar":"https://gravatar.com/avatar/8fc840ca854dbf6f7065b4335e3b934951c1dca3b11db688e95e471901f8f4a8?d=mp&s=160"},"body":"git-merge.sh was not running the commit hooks, so run them in the two\nplaces where we go to commit.\n\nSigned-off-by: Sam Vilain <sam.vilain@catalyst.net.nz>\n---\n   Not sure if it should call these or some specialist hooks, like\n   git-am does.\n\n git-merge.sh |   27 +++++++++++++++++++++++++++\n 1 files changed, 27 insertions(+), 0 deletions(-)\n\ndiff --git a/git-merge.sh b/git-merge.sh\nindex 981d69d..ef4f51b 100755\n--- a/git-merge.sh\n+++ b/git-merge.sh\n@@ -117,6 +117,29 @@ merge_name () {\n \tfi\n }\n \n+call_pre_hooks () {\n+\tmessage=\"$1\"\n+\tif test -x \"$GIT_DIR\"/hooks/pre-commit\n+\tthen\n+\t\t\"$GIT_DIR\"/hooks/pre-commit || exit 1\n+\tfi\n+\tif test -x \"$GIT_DIR\"/hooks/commit-msg\n+\tthen\n+\t\tprintf '%s\\n' \"$message\" > \"$GIT_DIR\"/MERGE_MSG\n+\t\t\"$GIT_DIR\"/hooks/commit-msg \"$GIT_DIR\"/MERGE_MSG || exit 1\n+\t\tcat \"$GIT_DIR\"/MERGE_MSG\n+\telse\n+\t\techo \"$message\"\n+\tfi\n+}\n+\n+call_post_hook () {\n+\tif test -x \"$GIT_DIR\"/hooks/post-commit\n+\tthen\n+\t\t\"$GIT_DIR\"/hooks/post-commit\n+\tfi\n+}\n+\n case \"$#\" in 0) usage ;; esac\n \n have_message=\n@@ -334,11 +357,13 @@ f,*)\n \t\t   result_tree=$(git-write-tree)\n \t\tthen\n \t\t\techo \"Wonderful.\"\n+\t\t\tmerge_msg=$(call_pre_hooks \"$merge_msg\")\n \t\t\tresult_commit=$(\n \t\t\t\tprintf '%s\\n' \"$merge_msg\" |\n \t\t\t\tgit-commit-tree $result_tree -p HEAD -p \"$1\"\n \t\t\t) || exit\n \t\t\tfinish \"$result_commit\" \"In-index merge\"\n+\t\t\tcall_post_hook\n \t\t\tdropsave\n \t\t\texit 0\n \t\tfi\n@@ -440,8 +465,10 @@ done\n if test '' != \"$result_tree\"\n then\n     parents=$(git-show-branch --independent \"$head\" \"$@\" | sed -e 's/^/-p /')\n+    merge_msg=$(call_pre_hooks \"$merge_msg\")\n     result_commit=$(printf '%s\\n' \"$merge_msg\" | git-commit-tree $result_tree $parents) || exit\n     finish \"$result_commit\" \"Merge made by $wt_strategy.\"\n+    call_post_hook\n     dropsave\n     exit 0\n fi\n-- \n1.5.2.1.1131.g3b90\n"},{"id":"47077","messageId":"7vd4yy4opa.fsf@assigned-by-dhcp.cox.net","threadId":"8979","inReplyTo":"11841499201242-git-send-email-sam.vilain@catalyst.net.nz","subject":"Re: [PATCH] git-merge: run commit hooks when making merge commits","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-11T21:26:09Z","receivedAt":"2007-07-11T21:26:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sam Vilain <sam.vilain@catalyst.net.nz> writes:\n\n> git-merge.sh was not running the commit hooks, so run them in the two\n> places where we go to commit.\n>\n> Signed-off-by: Sam Vilain <sam.vilain@catalyst.net.nz>\n> ---\n>    Not sure if it should call these or some specialist hooks, like\n>    git-am does.\n\nI suspect some people have pre-commit scripts that have been\nmeant to catch style errors for their own commits, and invoking\nthat on merge would wreak havoc --- there is not much you can do\nif you want to get the work done by somebody else at that point.\nIntroducing a new pre-merge-commit hook would probably be safer;\nif one wants to use the same check as one's pre-commit does, the\nnew hook in the repository can exec $GIT_DIR/hooks/pre-commit.\n\nThe commit-msg hook I have no clue what people usually use it\nfor in the real world, but a merge commit message tends to be\nquite different from the message you would give to your own\nstraight line commits, so custom reformatting rules people have\nin commit-msg hook may not apply to merge commit messages.\n\nSame for post-commit, but probably to lessor extent, as I\nsuspect people use that mostly for per-commit notification\nmechanism.\n"},{"id":"47095","messageId":"469565FF.5040103@vilain.net","threadId":"8979","inReplyTo":"7vd4yy4opa.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-merge: run commit hooks when making merge commits","fromName":"Sam Vilain","fromEmail":"sam@vilain.net","sentAt":"2007-07-11T23:21:35Z","receivedAt":"2007-07-11T23:21:35Z","isPatch":true,"sender":{"key":"sam@vilain.net","avatar":"https://gravatar.com/avatar/8fc840ca854dbf6f7065b4335e3b934951c1dca3b11db688e95e471901f8f4a8?d=mp&s=160"},"body":"Junio C Hamano wrote:\n> Sam Vilain <sam.vilain@catalyst.net.nz> writes:\n> \n>> git-merge.sh was not running the commit hooks, so run them in the two\n>> places where we go to commit.\n>>\n>> Signed-off-by: Sam Vilain <sam.vilain@catalyst.net.nz>\n>> ---\n>>    Not sure if it should call these or some specialist hooks, like\n>>    git-am does.\n> \n> I suspect some people have pre-commit scripts that have been\n> meant to catch style errors for their own commits, and invoking\n> that on merge would wreak havoc --- there is not much you can do\n> if you want to get the work done by somebody else at that point.\n> Introducing a new pre-merge-commit hook would probably be safer;\n> if one wants to use the same check as one's pre-commit does, the\n> new hook in the repository can exec $GIT_DIR/hooks/pre-commit.\n> \n> The commit-msg hook I have no clue what people usually use it\n> for in the real world, but a merge commit message tends to be\n> quite different from the message you would give to your own\n> straight line commits, so custom reformatting rules people have\n> in commit-msg hook may not apply to merge commit messages.\n\nTrue.  OTOH, if you commit with `git commit` after a merge which failed\nor was called with --no-commit, then it will call the commit hook.  So\nthose scripts would have to deal with that case anyway.\n\nSo, should `git commit` detect it is committing a merge and call the\nmerge-hooks, should we use the same hooks, or, should this be something\nlike hooks/*-automerge ?\n\nSam.\n"},{"id":"47128","messageId":"200707120903.46538.andyparkins@gmail.com","threadId":"8979","inReplyTo":"7vd4yy4opa.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-merge: run commit hooks when making merge commits","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2007-07-12T08:03:44Z","receivedAt":"2007-07-12T08:03:44Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"On Wednesday 2007 July 11, Junio C Hamano wrote:\n\n> The commit-msg hook I have no clue what people usually use it\n> for in the real world, but a merge commit message tends to be\n\nI use it for adding my Signed-Off-By automatically in my git repository.  Of \ncourse that's only valid for the likes of me because I can be sure that I \nonly ever commit my own patches, rather than integrating other people's.\n\n\n\nAndy\n\n-- \nDr Andy Parkins, M Eng (hons), MIET\nandyparkins@gmail.com\n"}]}