@matheusbsbs / matheus-bagliano / commits / 46232915d5
Fork 0

Add post-merge hook, related documentation, and tests.

The post-merge hook enables one to hook in for `git pull` operations in order to check and/or change attributes of a work tree from the hook. As an example, it can be used in combination with a pre-commit hook to save/restore file ownership and permissions data (or file ACLs) within the repository and transparently update the working tree after a `git pull` operation. Signed-off-by: Josh England <jjengla@sandia.gov> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Josh England committed Sep 11, 2007 at 10:59 UTC 46232915d5ac84fb033ad395bbf161c9645c42c9
3 files changed +81
Documentation/hooks.txt
+12
@@ -87,6 +87,18 @@ parameter, and is invoked after a commit is made.
87 This hook is meant primarily for notification, and cannot affect
88 the outcome of `git-commit`.
89
90 +post-merge
91 +-----------
92 +
93 +This hook is invoked by `git-merge`, which happens when a `git pull`
94 +is done on a local repository. The hook takes a single parameter, a status
95 +flag specifying whether or not the merge being done was a squash merge.
96 +This hook cannot affect the outcome of `git-merge`.
97 +
98 +This hook can be used in conjunction with a corresponding pre-commit hook to
99 +save and restore any form of metadata associated with the working tree
100 +(eg: permissions/ownership, ACLS, etc).
101 +
102 [[pre-receive]]
103 pre-receive
104 -----------
git-merge.sh
+13
@@ -97,6 +97,19 @@ finish () {
97 fi
98 ;;
99 esac
100 +
101 + # Run a post-merge hook
102 + if test -x "$GIT_DIR"/hooks/post-merge
103 + then
104 + case "$squash" in
105 + t)
106 + "$GIT_DIR"/hooks/post-merge 1
107 + ;;
108 + '')
109 + "$GIT_DIR"/hooks/post-merge 0
110 + ;;
111 + esac
112 + fi
113 }
114
115 merge_name () {
t/t5402-post-merge-hook.sh new
+56
@@ -0,0 +1,56 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2006 Josh England
4 +#
5 +
6 +test_description='Test the post-merge hook.'
7 +. ./test-lib.sh
8 +
9 +test_expect_success setup '
10 + echo Data for commit0. >a &&
11 + git update-index --add a &&
12 + tree0=$(git write-tree) &&
13 + commit0=$(echo setup | git commit-tree $tree0) &&
14 + echo Changed data for commit1. >a &&
15 + git update-index a &&
16 + tree1=$(git write-tree) &&
17 + commit1=$(echo modify | git commit-tree $tree1 -p $commit0) &&
18 + git update-ref refs/heads/master $commit0 &&
19 + git-clone ./. clone1 &&
20 + GIT_DIR=clone1/.git git update-index --add a &&
21 + git-clone ./. clone2 &&
22 + GIT_DIR=clone2/.git git update-index --add a
23 +'
24 +
25 +for clone in 1 2; do
26 + cat >clone${clone}/.git/hooks/post-merge <<'EOF'
27 +#!/bin/sh
28 +echo $@ >> $GIT_DIR/post-merge.args
29 +EOF
30 + chmod u+x clone${clone}/.git/hooks/post-merge
31 +done
32 +
33 +test_expect_failure 'post-merge does not run for up-to-date ' '
34 + GIT_DIR=clone1/.git git merge $commit0 &&
35 + test -e clone1/.git/post-merge.args
36 +'
37 +
38 +test_expect_success 'post-merge runs as expected ' '
39 + GIT_DIR=clone1/.git git merge $commit1 &&
40 + test -e clone1/.git/post-merge.args
41 +'
42 +
43 +test_expect_success 'post-merge from normal merge receives the right argument ' '
44 + grep 0 clone1/.git/post-merge.args
45 +'
46 +
47 +test_expect_success 'post-merge from squash merge runs as expected ' '
48 + GIT_DIR=clone2/.git git merge --squash $commit1 &&
49 + test -e clone2/.git/post-merge.args
50 +'
51 +
52 +test_expect_success 'post-merge from squash merge receives the right argument ' '
53 + grep 1 clone2/.git/post-merge.args
54 +'
55 +
56 +test_done