]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t7505-prepare-commit-msg-hook.sh
The fifth batch
[thirdparty/git.git] / t / t7505-prepare-commit-msg-hook.sh
index 7a8194ce720ed5d9244caf2bbd882a56f491476c..2128142a61c60da918381f6b6f74ca612ac9227b 100755 (executable)
@@ -16,7 +16,7 @@ test_expect_success 'set up commits for rebasing' '
        test_commit rebase-b b bb &&
        for i in $(test_seq 1 13)
        do
-               test_commit rebase-$i c $i
+               test_commit rebase-$i c $i || return 1
        done &&
        git checkout main &&
 
@@ -47,25 +47,19 @@ test_expect_success 'with no hook' '
 
 '
 
-# set up fake editor for interactive editing
-cat > fake-editor <<'EOF'
-#!/bin/sh
-exit 0
-EOF
-chmod +x fake-editor
-
-## Not using test_set_editor here so we can easily ensure the editor variable
-## is only set for the editor tests
-FAKE_EDITOR="$(pwd)/fake-editor"
-export FAKE_EDITOR
+test_expect_success 'setup fake editor for interactive editing' '
+       write_script fake-editor <<-\EOF &&
+       exit 0
+       EOF
 
-# now install hook that always succeeds and adds a message
-HOOKDIR="$(git rev-parse --git-dir)/hooks"
-HOOK="$HOOKDIR/prepare-commit-msg"
-mkdir -p "$HOOKDIR"
-echo "#!$SHELL_PATH" > "$HOOK"
-cat >> "$HOOK" <<'EOF'
+       ## Not using test_set_editor here so we can easily ensure the editor variable
+       ## is only set for the editor tests
+       FAKE_EDITOR="$(pwd)/fake-editor" &&
+       export FAKE_EDITOR
+'
 
+test_expect_success 'setup prepare-commit-msg hook' '
+       test_hook --setup prepare-commit-msg <<\EOF
 GIT_DIR=$(git rev-parse --git-dir)
 if test -d "$GIT_DIR/rebase-merge"
 then
@@ -103,7 +97,7 @@ else
 fi
 exit 0
 EOF
-chmod +x "$HOOK"
+'
 
 echo dummy template > "$(git rev-parse --git-dir)/template"
 
@@ -250,7 +244,6 @@ test_rebase () {
 }
 
 test_rebase success
-test_have_prereq !REBASE_P || test_rebase success -p
 
 test_expect_success 'with hook (cherry-pick)' '
        test_when_finished "git checkout -f main" &&
@@ -266,10 +259,11 @@ test_expect_success 'with hook and editor (cherry-pick)' '
        test "$(git log -1 --pretty=format:%s)" = merge
 '
 
-cat > "$HOOK" <<'EOF'
-#!/bin/sh
-exit 1
-EOF
+test_expect_success 'setup: commit-msg hook that always fails' '
+       test_hook --setup --clobber prepare-commit-msg <<-\EOF
+       exit 1
+       EOF
+'
 
 test_expect_success 'with failing hook' '
 
@@ -297,9 +291,9 @@ test_expect_success 'with failing hook (merge)' '
        git checkout -B other HEAD@{1} &&
        echo "more" >> file &&
        git add file &&
-       rm -f "$HOOK" &&
+       test_hook --remove prepare-commit-msg &&
        git commit -m other &&
-       write_script "$HOOK" <<-EOF &&
+       test_hook --setup prepare-commit-msg <<-\EOF &&
        exit 1
        EOF
        git checkout - &&