git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-merge: run commit hooks when making merge commits

From
Sam Vilain <sam.vilain@catalyst.net.nz>
Date
Jul 11, 2007, 10:32 UTC
Message-ID
<11841499201242-git-send-email-sam.vilain@catalyst.net.nz>

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
Next: Junio C Hamano
Message 1 of 4 in “git-merge: run commit hooks when making merge commits”
  1. git-merge: run commit hooks when making merge commitsSam Vilain, Jul 11, 2007
  2. Junio C HamanoJul 11, 2007
  3. Sam VilainJul 11, 2007
  4. Andy ParkinsJul 12, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.