]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t7504-commit-msg-hook.sh
Merge branch 'gc/branch-recurse-submodules-fix'
[thirdparty/git.git] / t / t7504-commit-msg-hook.sh
index bba58f04806fdfc247c1b72112ed6805340934c1..a39de8c112674f070f8dc19745e27980b7b52c9c 100755 (executable)
@@ -54,15 +54,11 @@ test_expect_success '--no-verify with no hook (editor)' '
 
 '
 
-# now install hook that always succeeds
-HOOKDIR="$(git rev-parse --git-dir)/hooks"
-HOOK="$HOOKDIR/commit-msg"
-mkdir -p "$HOOKDIR"
-cat > "$HOOK" <<EOF
-#!/bin/sh
-exit 0
-EOF
-chmod +x "$HOOK"
+test_expect_success 'setup: commit-msg hook that always succeeds' '
+       test_hook --setup commit-msg <<-\EOF
+       exit 0
+       EOF
+'
 
 test_expect_success 'with succeeding hook' '
 
@@ -98,11 +94,11 @@ test_expect_success '--no-verify with succeeding hook (editor)' '
 
 '
 
-# now a hook that fails
-cat > "$HOOK" <<EOF
-#!/bin/sh
-exit 1
-EOF
+test_expect_success 'setup: commit-msg hook that always fails' '
+       test_hook --clobber commit-msg <<-\EOF
+       exit 1
+       EOF
+'
 
 commit_msg_is () {
        test "$(git log --pretty=format:%s%b -1)" = "$1"
@@ -176,8 +172,12 @@ test_expect_success 'merge bypasses failing hook with --no-verify' '
        commit_msg_is "Merge branch '\''main'\'' into newbranch"
 '
 
+test_expect_success 'setup: commit-msg hook made non-executable' '
+       git_dir="$(git rev-parse --git-dir)" &&
+       chmod -x "$git_dir/hooks/commit-msg"
+'
+
 
-chmod -x "$HOOK"
 test_expect_success POSIXPERM 'with non-executable hook' '
 
        echo "content" >file &&
@@ -212,13 +212,12 @@ test_expect_success POSIXPERM '--no-verify with non-executable hook (editor)' '
 
 '
 
-# now a hook that edits the commit message
-cat > "$HOOK" <<'EOF'
-#!/bin/sh
-echo "new message" > "$1"
-exit 0
-EOF
-chmod +x "$HOOK"
+test_expect_success 'setup: commit-msg hook that edits the commit message' '
+       test_hook --clobber commit-msg <<-\EOF
+       echo "new message" >"$1"
+       exit 0
+       EOF
+'
 
 test_expect_success 'hook edits commit message' '