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

[PATCH] post-merge hook and related tests

From
JEJosh England <jjengla@sandia.gov>
Date
Sep 25, 2007, 22:49 UTC
Message-ID
<1190760563-32453-2-git-send-email-jjengla@sandia.gov>
In-Reply-To
<1190760563-32453-1-git-send-email-jjengla@sandia.gov>
Signed-off-by: Josh England <jjengla@sandia.gov>
---
 git-merge.sh               |   13 ++++++++++
 t/t5402-post-merge-hook.sh |   56 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+), 0 deletions(-)
 create mode 100644 t/t5402-post-merge-hook.sh
diff --git a/git-merge.sh b/git-merge.sh
index 3a01db0..66e48b3 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -97,6 +97,19 @@ finish () {
 		fi
 		;;
 	esac
+
+	# Run a post-merge hook
+        if test -x "$GIT_DIR"/hooks/post-merge
+        then
+	    case "$squash" in
+	    t)
+                "$GIT_DIR"/hooks/post-merge 1
+		;;
+	    '')
+                "$GIT_DIR"/hooks/post-merge 0
+		;;
+	    esac
+        fi
 }
 
 merge_name () {
diff --git a/t/t5402-post-merge-hook.sh b/t/t5402-post-merge-hook.sh
new file mode 100644
index 0000000..2a7a097
--- /dev/null
+++ b/t/t5402-post-merge-hook.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+#
+# Copyright (c) 2006 Josh England
+#
+
+test_description='Test the post-merge hook.'
+. ./test-lib.sh
+
+test_expect_success setup '
+	echo Data for commit0. >a &&
+	git update-index --add a &&
+	tree0=$(git write-tree) &&
+	commit0=$(echo setup | git commit-tree $tree0) &&
+	echo Changed data for commit1. >a &&
+	git update-index a &&
+	tree1=$(git write-tree) &&
+	commit1=$(echo modify | git commit-tree $tree1 -p $commit0) &&
+        git update-ref refs/heads/master $commit0 &&     
+	git-clone ./. clone1 &&
+	GIT_DIR=clone1/.git git update-index --add a &&
+	git-clone ./. clone2 &&
+	GIT_DIR=clone2/.git git update-index --add a
+'
+
+for clone in 1 2; do 
+    cat >clone${clone}/.git/hooks/post-merge <<'EOF'
+#!/bin/sh
+echo $@ >> $GIT_DIR/post-merge.args
+EOF
+    chmod u+x clone${clone}/.git/hooks/post-merge
+done
+
+test_expect_failure 'post-merge does not run for up-to-date ' '
+        GIT_DIR=clone1/.git git merge $commit0 &&
+ 	test -e clone1/.git/post-merge.args
+'
+
+test_expect_success 'post-merge runs as expected ' '
+        GIT_DIR=clone1/.git git merge $commit1 &&
+ 	test -e clone1/.git/post-merge.args
+'
+
+test_expect_success 'post-merge from normal merge receives the right argument ' '
+        grep 0 clone1/.git/post-merge.args
+'
+
+test_expect_success 'post-merge from squash merge runs as expected ' '
+        GIT_DIR=clone2/.git git merge --squash $commit1 &&
+ 	test -e clone2/.git/post-merge.args
+'
+
+test_expect_success 'post-merge from squash merge receives the right argument ' '
+        grep 1 clone2/.git/post-merge.args
+'
+
+test_done
-- 
1.5.3.2.89.g296e
Previous: Josh EnglandNext: Josh England
Message 2 of 6 in “post-checkout hooks and related tests”
  1. post-checkout hooks and related testsJosh England, Sep 25, 2007
  2. post-merge hook and related testsJosh England, Sep 25, 2007
  3. Documentation for post-checkout and post-merge hooksJosh England, Sep 25, 2007
  4. Junio C HamanoSep 25, 2007
  5. Junio C HamanoSep 25, 2007
  6. Josh EnglandSep 26, 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.