summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael J Gruber <git@drmicha.warpmail.net>2017-09-22 14:04:15 +0200
committerJunio C Hamano <gitster@pobox.com>2017-09-24 10:43:39 +0900
commitb7bc132ef39ae12bb31065486236d8fdb17d4e61 (patch)
tree806cd75a0380ba8cd1430f416ffca3b2cec86da3
parent3a658ae9f4dcde8964370afe52187a0dca50a133 (diff)
downloadgit-mg/merge-pre-merge-hook.tar.gz
t7503: add tests for pre-merge-hookmg/merge-pre-merge-hook
Add tests which make sure that the pre-merge-hook is called when present, allows/disallows merge commits depending on its return value and is suppressed by "--no-verify". Signed-off-by: Michael J Gruber <git@grubix.eu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rwxr-xr-xt/t7503-pre-commit-hook.sh66
1 files changed, 65 insertions, 1 deletions
diff --git a/t/t7503-pre-commit-hook.sh b/t/t7503-pre-commit-hook.sh
index 984889b39d..36ae87f7ef 100755
--- a/t/t7503-pre-commit-hook.sh
+++ b/t/t7503-pre-commit-hook.sh
@@ -1,9 +1,22 @@
#!/bin/sh
-test_description='pre-commit hook'
+test_description='pre-commit and pre-merge hooks'
. ./test-lib.sh
+test_expect_success 'root commit' '
+
+ echo "root" > file &&
+ git add file &&
+ git commit -m "zeroth" &&
+ git checkout -b side &&
+ echo "foo" > foo &&
+ git add foo &&
+ git commit -m "make it non-ff" &&
+ git checkout master
+
+'
+
test_expect_success 'with no hook' '
echo "foo" > file &&
@@ -12,6 +25,14 @@ test_expect_success 'with no hook' '
'
+test_expect_success 'with no hook (merge)' '
+
+ git checkout side &&
+ git merge -m "merge master" master &&
+ git checkout master
+
+'
+
test_expect_success '--no-verify with no hook' '
echo "bar" > file &&
@@ -20,15 +41,25 @@ test_expect_success '--no-verify with no hook' '
'
+test_expect_success '--no-verify with no hook (merge)' '
+
+ git checkout side &&
+ git merge --no-verify -m "merge master" master &&
+ git checkout master
+
+'
+
# now install hook that always succeeds
HOOKDIR="$(git rev-parse --git-dir)/hooks"
HOOK="$HOOKDIR/pre-commit"
+MERGEHOOK="$HOOKDIR/pre-merge"
mkdir -p "$HOOKDIR"
cat > "$HOOK" <<EOF
#!/bin/sh
exit 0
EOF
chmod +x "$HOOK"
+cp -p "$HOOK" "$MERGEHOOK"
test_expect_success 'with succeeding hook' '
@@ -38,6 +69,14 @@ test_expect_success 'with succeeding hook' '
'
+test_expect_success 'with succeeding hook (merge)' '
+
+ git checkout side &&
+ git merge -m "merge master" master &&
+ git checkout master
+
+'
+
test_expect_success '--no-verify with succeeding hook' '
echo "even more" >> file &&
@@ -46,11 +85,20 @@ test_expect_success '--no-verify with succeeding hook' '
'
+test_expect_success '--no-verify with succeeding hook (merge)' '
+
+ git checkout side &&
+ git merge --no-verify -m "merge master" master &&
+ git checkout master
+
+'
+
# now a hook that fails
cat > "$HOOK" <<EOF
#!/bin/sh
exit 1
EOF
+cp -p "$HOOK" "$MERGEHOOK"
test_expect_success 'with failing hook' '
@@ -68,6 +116,22 @@ test_expect_success '--no-verify with failing hook' '
'
+test_expect_success 'with failing hook (merge)' '
+
+ git checkout side &&
+ test_must_fail git merge -m "merge master" master &&
+ git checkout master
+
+'
+
+test_expect_success '--no-verify with failing hook (merge)' '
+
+ git checkout side &&
+ git merge --no-verify -m "merge master" master &&
+ git checkout master
+
+'
+
chmod -x "$HOOK"
test_expect_success POSIXPERM 'with non-executable hook' '