Josh England | 4623291 | 2007-09-11 10:59:03 -0600 | [diff] [blame] | 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 && |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 19 | git clone ./. clone1 && |
Josh England | 4623291 | 2007-09-11 10:59:03 -0600 | [diff] [blame] | 20 | GIT_DIR=clone1/.git git update-index --add a && |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 21 | git clone ./. clone2 && |
Josh England | 4623291 | 2007-09-11 10:59:03 -0600 | [diff] [blame] | 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 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 33 | test_expect_success 'post-merge does not run for up-to-date ' ' |
Josh England | 4623291 | 2007-09-11 10:59:03 -0600 | [diff] [blame] | 34 | GIT_DIR=clone1/.git git merge $commit0 && |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 35 | ! test -f clone1/.git/post-merge.args |
Josh England | 4623291 | 2007-09-11 10:59:03 -0600 | [diff] [blame] | 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 |