tests: use "test_hook" for misc "mkdir -p" and "chmod" cases

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>

Ævar Arnfjörð Bjarmason committed Mar 17, 2022 at 11:13 UTC c36c62859ae59e5ff3cd2a620ab8c906793dc615
5 files changed +56 -78
t/t3412-rebase-root.sh
+6 -12
@@ -31,12 +31,9 @@ test_expect_success 'rebase --root fails with too many args' '
31 '
32
33 test_expect_success 'setup pre-rebase hook' '
34 - mkdir -p .git/hooks &&
35 - cat >.git/hooks/pre-rebase <<EOF &&
36 -#!$SHELL_PATH
37 -echo "\$1,\$2" >.git/PRE-REBASE-INPUT
38 -EOF
39 - chmod +x .git/hooks/pre-rebase
34 + test_hook --setup pre-rebase <<-\EOF
35 + echo "$1,$2" >.git/PRE-REBASE-INPUT
36 + EOF
37 '
38 cat > expect <<EOF
39 4
@@ -141,12 +138,9 @@ commit work7~5
138 EOF
139
140 test_expect_success 'setup pre-rebase hook that fails' '
144 - mkdir -p .git/hooks &&
145 - cat >.git/hooks/pre-rebase <<EOF &&
146 -#!$SHELL_PATH
147 -false
148 -EOF
149 - chmod +x .git/hooks/pre-rebase
141 + test_hook --setup --clobber pre-rebase <<-\EOF
142 + false
143 + EOF
144 '
145
146 test_expect_success 'pre-rebase hook stops rebase' '
t/t3413-rebase-hook.sh
+6 -12
@@ -41,12 +41,9 @@ test_expect_success 'rebase -i' '
41 '
42
43 test_expect_success 'setup pre-rebase hook' '
44 - mkdir -p .git/hooks &&
45 - cat >.git/hooks/pre-rebase <<EOF &&
46 -#!$SHELL_PATH
47 -echo "\$1,\$2" >.git/PRE-REBASE-INPUT
48 -EOF
49 - chmod +x .git/hooks/pre-rebase
44 + test_hook --setup pre-rebase <<-\EOF
45 + echo "$1,$2" >.git/PRE-REBASE-INPUT
46 + EOF
47 '
48
49 test_expect_success 'pre-rebase hook gets correct input (1)' '
@@ -102,12 +99,9 @@ test_expect_success 'pre-rebase hook gets correct input (6)' '
99 '
100
101 test_expect_success 'setup pre-rebase hook that fails' '
105 - mkdir -p .git/hooks &&
106 - cat >.git/hooks/pre-rebase <<EOF &&
107 -#!$SHELL_PATH
108 -false
109 -EOF
110 - chmod +x .git/hooks/pre-rebase
102 + test_hook --setup --clobber pre-rebase <<-\EOF
103 + false
104 + EOF
105 '
106
107 test_expect_success 'pre-rebase hook stops rebase (1)' '
t/t5401-update-hooks.sh
+27 -35
@@ -20,45 +20,37 @@ test_expect_success setup '
20 git clone --bare ./. victim.git &&
21 GIT_DIR=victim.git git update-ref refs/heads/tofail $commit1 &&
22 git update-ref refs/heads/main $commit1 &&
23 - git update-ref refs/heads/tofail $commit0
24 -'
23 + git update-ref refs/heads/tofail $commit0 &&
24
26 -cat >victim.git/hooks/pre-receive <<'EOF'
27 -#!/bin/sh
28 -printf %s "$@" >>$GIT_DIR/pre-receive.args
29 -cat - >$GIT_DIR/pre-receive.stdin
30 -echo STDOUT pre-receive
31 -echo STDERR pre-receive >&2
32 -EOF
33 -chmod u+x victim.git/hooks/pre-receive
25 + test_hook --setup -C victim.git pre-receive <<-\EOF &&
26 + printf %s "$@" >>$GIT_DIR/pre-receive.args
27 + cat - >$GIT_DIR/pre-receive.stdin
28 + echo STDOUT pre-receive
29 + echo STDERR pre-receive >&2
30 + EOF
31
35 -cat >victim.git/hooks/update <<'EOF'
36 -#!/bin/sh
37 -echo "$@" >>$GIT_DIR/update.args
38 -read x; printf %s "$x" >$GIT_DIR/update.stdin
39 -echo STDOUT update $1
40 -echo STDERR update $1 >&2
41 -test "$1" = refs/heads/main || exit
42 -EOF
43 -chmod u+x victim.git/hooks/update
32 + test_hook --setup -C victim.git update <<-\EOF &&
33 + echo "$@" >>$GIT_DIR/update.args
34 + read x; printf %s "$x" >$GIT_DIR/update.stdin
35 + echo STDOUT update $1
36 + echo STDERR update $1 >&2
37 + test "$1" = refs/heads/main || exit
38 + EOF
39
45 -cat >victim.git/hooks/post-receive <<'EOF'
46 -#!/bin/sh
47 -printf %s "$@" >>$GIT_DIR/post-receive.args
48 -cat - >$GIT_DIR/post-receive.stdin
49 -echo STDOUT post-receive
50 -echo STDERR post-receive >&2
51 -EOF
52 -chmod u+x victim.git/hooks/post-receive
40 + test_hook --setup -C victim.git post-receive <<-\EOF &&
41 + printf %s "$@" >>$GIT_DIR/post-receive.args
42 + cat - >$GIT_DIR/post-receive.stdin
43 + echo STDOUT post-receive
44 + echo STDERR post-receive >&2
45 + EOF
46
54 -cat >victim.git/hooks/post-update <<'EOF'
55 -#!/bin/sh
56 -echo "$@" >>$GIT_DIR/post-update.args
57 -read x; printf %s "$x" >$GIT_DIR/post-update.stdin
58 -echo STDOUT post-update
59 -echo STDERR post-update >&2
60 -EOF
61 -chmod u+x victim.git/hooks/post-update
47 + test_hook --setup -C victim.git post-update <<-\EOF
48 + echo "$@" >>$GIT_DIR/post-update.args
49 + read x; printf %s "$x" >$GIT_DIR/post-update.stdin
50 + echo STDOUT post-update
51 + echo STDERR post-update >&2
52 + EOF
53 +'
54
55 test_expect_success push '
56 test_must_fail git send-pack --force ./victim.git \
t/t5407-post-rewrite-hook.sh
+6 -8
@@ -17,15 +17,13 @@ test_expect_success 'setup' '
17 git checkout A^0 &&
18 test_commit E bar E &&
19 test_commit F foo F &&
20 - git checkout main
21 -'
20 + git checkout main &&
21
23 -cat >.git/hooks/post-rewrite <<EOF
24 -#!/bin/sh
25 -echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
26 -cat > "$TRASH_DIRECTORY"/post-rewrite.data
27 -EOF
28 -chmod u+x .git/hooks/post-rewrite
22 + test_hook --setup post-rewrite <<-EOF
23 + echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
24 + cat > "$TRASH_DIRECTORY"/post-rewrite.data
25 + EOF
26 +'
27
28 clear_hook_input () {
29 rm -f post-rewrite.args post-rewrite.data
t/t5541-http-push-smart.sh
+11 -11
@@ -96,18 +96,18 @@ test_expect_success 'create and delete remote branch' '
96 test_must_fail git show-ref --verify refs/remotes/origin/dev
97 '
98
99 -cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<EOF
100 -#!/bin/sh
101 -exit 1
102 -EOF
103 -chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
99 +test_expect_success 'setup rejected update hook' '
100 + test_hook --setup -C "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" update <<-\EOF &&
101 + exit 1
102 + EOF
103
105 -cat >exp <<EOF
106 -remote: error: hook declined to update refs/heads/dev2
107 -To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
108 - ! [remote rejected] dev2 -> dev2 (hook declined)
109 -error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'
110 -EOF
104 + cat >exp <<-EOF
105 + remote: error: hook declined to update refs/heads/dev2
106 + To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
107 + ! [remote rejected] dev2 -> dev2 (hook declined)
108 + error: failed to push some refs to '\''http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'\''
109 + EOF
110 +'
111
112 test_expect_success 'rejected update prints status' '
113 cd "$ROOT_PATH"/test_repo_clone &&