Skip to content

Commit c36c628

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bef805b commit c36c628

File tree

5 files changed

+56
-78
lines changed

5 files changed

+56
-78
lines changed

t/t3412-rebase-root.sh

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@ test_expect_success 'rebase --root fails with too many args' '
3131
'
3232

3333
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
4037
'
4138
cat > expect <<EOF
4239
4
@@ -141,12 +138,9 @@ commit work7~5
141138
EOF
142139

143140
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
150144
'
151145

152146
test_expect_success 'pre-rebase hook stops rebase' '

t/t3413-rebase-hook.sh

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,9 @@ test_expect_success 'rebase -i' '
4141
'
4242

4343
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
5047
'
5148

5249
test_expect_success 'pre-rebase hook gets correct input (1)' '
@@ -102,12 +99,9 @@ test_expect_success 'pre-rebase hook gets correct input (6)' '
10299
'
103100

104101
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
111105
'
112106

113107
test_expect_success 'pre-rebase hook stops rebase (1)' '

t/t5401-update-hooks.sh

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,37 @@ test_expect_success setup '
2020
git clone --bare ./. victim.git &&
2121
GIT_DIR=victim.git git update-ref refs/heads/tofail $commit1 &&
2222
git update-ref refs/heads/main $commit1 &&
23-
git update-ref refs/heads/tofail $commit0
24-
'
23+
git update-ref refs/heads/tofail $commit0 &&
2524
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
3431
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
4439
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
5346
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+
'
6254

6355
test_expect_success push '
6456
test_must_fail git send-pack --force ./victim.git \

t/t5407-post-rewrite-hook.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ test_expect_success 'setup' '
1717
git checkout A^0 &&
1818
test_commit E bar E &&
1919
test_commit F foo F &&
20-
git checkout main
21-
'
20+
git checkout main &&
2221
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+
'
2927

3028
clear_hook_input () {
3129
rm -f post-rewrite.args post-rewrite.data

t/t5541-http-push-smart.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,18 @@ test_expect_success 'create and delete remote branch' '
9696
test_must_fail git show-ref --verify refs/remotes/origin/dev
9797
'
9898

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
104103
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+
'
111111

112112
test_expect_success 'rejected update prints status' '
113113
cd "$ROOT_PATH"/test_repo_clone &&

0 commit comments

Comments
 (0)