]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tests: use "test_hook" for misc "mkdir -p" and "chmod" cases
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Thu, 17 Mar 2022 10:13:15 +0000 (11:13 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 17 Mar 2022 15:40:26 +0000 (08:40 -0700)
Make use of "test_hook" in various cases that didn't fit neatly into
preceding commits. Here we need to indent blocks in addition to
changing the test code, or to make other small cosmetic changes.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t3412-rebase-root.sh
t/t3413-rebase-hook.sh
t/t5401-update-hooks.sh
t/t5407-post-rewrite-hook.sh
t/t5541-http-push-smart.sh

index 1e9f7833dd691a8b6ee769158c4684745dd4a8d4..58371d8a5477f47d53384a84ad0dae14457128d9 100755 (executable)
@@ -31,12 +31,9 @@ test_expect_success 'rebase --root fails with too many args' '
 '
 
 test_expect_success 'setup pre-rebase hook' '
-       mkdir -p .git/hooks &&
-       cat >.git/hooks/pre-rebase <<EOF &&
-#!$SHELL_PATH
-echo "\$1,\$2" >.git/PRE-REBASE-INPUT
-EOF
-       chmod +x .git/hooks/pre-rebase
+       test_hook --setup pre-rebase <<-\EOF
+       echo "$1,$2" >.git/PRE-REBASE-INPUT
+       EOF
 '
 cat > expect <<EOF
 4
@@ -141,12 +138,9 @@ commit work7~5
 EOF
 
 test_expect_success 'setup pre-rebase hook that fails' '
-       mkdir -p .git/hooks &&
-       cat >.git/hooks/pre-rebase <<EOF &&
-#!$SHELL_PATH
-false
-EOF
-       chmod +x .git/hooks/pre-rebase
+       test_hook --setup --clobber pre-rebase <<-\EOF
+       false
+       EOF
 '
 
 test_expect_success 'pre-rebase hook stops rebase' '
index b4acb3be5cf6f1d12521faf29a8c2afc6d3ff8e2..9fab0d779bb6cf32dbc0ece0a69ad2c2821a598e 100755 (executable)
@@ -41,12 +41,9 @@ test_expect_success 'rebase -i' '
 '
 
 test_expect_success 'setup pre-rebase hook' '
-       mkdir -p .git/hooks &&
-       cat >.git/hooks/pre-rebase <<EOF &&
-#!$SHELL_PATH
-echo "\$1,\$2" >.git/PRE-REBASE-INPUT
-EOF
-       chmod +x .git/hooks/pre-rebase
+       test_hook --setup pre-rebase <<-\EOF
+       echo "$1,$2" >.git/PRE-REBASE-INPUT
+       EOF
 '
 
 test_expect_success 'pre-rebase hook gets correct input (1)' '
@@ -102,12 +99,9 @@ test_expect_success 'pre-rebase hook gets correct input (6)' '
 '
 
 test_expect_success 'setup pre-rebase hook that fails' '
-       mkdir -p .git/hooks &&
-       cat >.git/hooks/pre-rebase <<EOF &&
-#!$SHELL_PATH
-false
-EOF
-       chmod +x .git/hooks/pre-rebase
+       test_hook --setup --clobber pre-rebase <<-\EOF
+       false
+       EOF
 '
 
 test_expect_success 'pre-rebase hook stops rebase (1)' '
index 799349a416c90ec37781332bf25981bbb925923d..001b7a17ad2bb93610198ebf134ccbedc2781f00 100755 (executable)
@@ -20,45 +20,37 @@ test_expect_success setup '
        git clone --bare ./. victim.git &&
        GIT_DIR=victim.git git update-ref refs/heads/tofail $commit1 &&
        git update-ref refs/heads/main $commit1 &&
-       git update-ref refs/heads/tofail $commit0
-'
+       git update-ref refs/heads/tofail $commit0 &&
 
-cat >victim.git/hooks/pre-receive <<'EOF'
-#!/bin/sh
-printf %s "$@" >>$GIT_DIR/pre-receive.args
-cat - >$GIT_DIR/pre-receive.stdin
-echo STDOUT pre-receive
-echo STDERR pre-receive >&2
-EOF
-chmod u+x victim.git/hooks/pre-receive
+       test_hook --setup -C victim.git pre-receive <<-\EOF &&
+       printf %s "$@" >>$GIT_DIR/pre-receive.args
+       cat - >$GIT_DIR/pre-receive.stdin
+       echo STDOUT pre-receive
+       echo STDERR pre-receive >&2
+       EOF
 
-cat >victim.git/hooks/update <<'EOF'
-#!/bin/sh
-echo "$@" >>$GIT_DIR/update.args
-read x; printf %s "$x" >$GIT_DIR/update.stdin
-echo STDOUT update $1
-echo STDERR update $1 >&2
-test "$1" = refs/heads/main || exit
-EOF
-chmod u+x victim.git/hooks/update
+       test_hook --setup -C victim.git update <<-\EOF &&
+       echo "$@" >>$GIT_DIR/update.args
+       read x; printf %s "$x" >$GIT_DIR/update.stdin
+       echo STDOUT update $1
+       echo STDERR update $1 >&2
+       test "$1" = refs/heads/main || exit
+       EOF
 
-cat >victim.git/hooks/post-receive <<'EOF'
-#!/bin/sh
-printf %s "$@" >>$GIT_DIR/post-receive.args
-cat - >$GIT_DIR/post-receive.stdin
-echo STDOUT post-receive
-echo STDERR post-receive >&2
-EOF
-chmod u+x victim.git/hooks/post-receive
+       test_hook --setup -C victim.git post-receive <<-\EOF &&
+       printf %s "$@" >>$GIT_DIR/post-receive.args
+       cat - >$GIT_DIR/post-receive.stdin
+       echo STDOUT post-receive
+       echo STDERR post-receive >&2
+       EOF
 
-cat >victim.git/hooks/post-update <<'EOF'
-#!/bin/sh
-echo "$@" >>$GIT_DIR/post-update.args
-read x; printf %s "$x" >$GIT_DIR/post-update.stdin
-echo STDOUT post-update
-echo STDERR post-update >&2
-EOF
-chmod u+x victim.git/hooks/post-update
+       test_hook --setup -C victim.git post-update <<-\EOF
+       echo "$@" >>$GIT_DIR/post-update.args
+       read x; printf %s "$x" >$GIT_DIR/post-update.stdin
+       echo STDOUT post-update
+       echo STDERR post-update >&2
+       EOF
+'
 
 test_expect_success push '
        test_must_fail git send-pack --force ./victim.git \
index 6da8d760e288dc4b4c75e661f99d2a4850320587..5f3ff051ca2fa3bba8beabbcb1491d5e69262f34 100755 (executable)
@@ -17,15 +17,13 @@ test_expect_success 'setup' '
        git checkout A^0 &&
        test_commit E bar E &&
        test_commit F foo F &&
-       git checkout main
-'
+       git checkout main &&
 
-cat >.git/hooks/post-rewrite <<EOF
-#!/bin/sh
-echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
-cat > "$TRASH_DIRECTORY"/post-rewrite.data
-EOF
-chmod u+x .git/hooks/post-rewrite
+       test_hook --setup post-rewrite <<-EOF
+       echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
+       cat > "$TRASH_DIRECTORY"/post-rewrite.data
+       EOF
+'
 
 clear_hook_input () {
        rm -f post-rewrite.args post-rewrite.data
index 8ca50f8b18c1ce68b553efffd1daaa57b730de07..ab4b5cfcd1156cccd18b22019592bfb3ccbb2fc3 100755 (executable)
@@ -96,18 +96,18 @@ test_expect_success 'create and delete remote branch' '
        test_must_fail git show-ref --verify refs/remotes/origin/dev
 '
 
-cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<EOF
-#!/bin/sh
-exit 1
-EOF
-chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
+test_expect_success 'setup rejected update hook' '
+       test_hook --setup -C "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" update <<-\EOF &&
+       exit 1
+       EOF
 
-cat >exp <<EOF
-remote: error: hook declined to update refs/heads/dev2
-To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
- ! [remote rejected] dev2 -> dev2 (hook declined)
-error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'
-EOF
+       cat >exp <<-EOF
+       remote: error: hook declined to update refs/heads/dev2
+       To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
+        ! [remote rejected] dev2 -> dev2 (hook declined)
+       error: failed to push some refs to '\''http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'\''
+       EOF
+'
 
 test_expect_success 'rejected update prints status' '
        cd "$ROOT_PATH"/test_repo_clone &&