Skip to content

Commit 6878ea6

Browse files
committed
Merge branch 'ab/hook-tests'
Test modernization. * ab/hook-tests: hook tests: use a modern style for "pre-push" tests hook tests: test for exact "pre-push" hook input
2 parents ae59346 + 4454015 commit 6878ea6

File tree

1 file changed

+53
-41
lines changed

1 file changed

+53
-41
lines changed

t/t5571-pre-push-hook.sh

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ HOOKDIR="$(git rev-parse --git-dir)/hooks"
1111
HOOK="$HOOKDIR/pre-push"
1212
mkdir -p "$HOOKDIR"
1313
write_script "$HOOK" <<EOF
14-
cat >/dev/null
14+
cat >actual
1515
exit 0
1616
EOF
1717

@@ -20,10 +20,16 @@ test_expect_success 'setup' '
2020
git init --bare repo1 &&
2121
git remote add parent1 repo1 &&
2222
test_commit one &&
23-
git push parent1 HEAD:foreign
23+
cat >expect <<-EOF &&
24+
HEAD $(git rev-parse HEAD) refs/heads/foreign $(test_oid zero)
25+
EOF
26+
27+
test_when_finished "rm actual" &&
28+
git push parent1 HEAD:foreign &&
29+
test_cmp expect actual
2430
'
2531
write_script "$HOOK" <<EOF
26-
cat >/dev/null
32+
cat >actual
2733
exit 1
2834
EOF
2935

@@ -32,11 +38,18 @@ export COMMIT1
3238

3339
test_expect_success 'push with failing hook' '
3440
test_commit two &&
35-
test_must_fail git push parent1 HEAD
41+
cat >expect <<-EOF &&
42+
HEAD $(git rev-parse HEAD) refs/heads/main $(test_oid zero)
43+
EOF
44+
45+
test_when_finished "rm actual" &&
46+
test_must_fail git push parent1 HEAD &&
47+
test_cmp expect actual
3648
'
3749

3850
test_expect_success '--no-verify bypasses hook' '
39-
git push --no-verify parent1 HEAD
51+
git push --no-verify parent1 HEAD &&
52+
test_path_is_missing actual
4053
'
4154

4255
COMMIT2="$(git rev-parse HEAD)"
@@ -48,15 +61,15 @@ echo "$2" >>actual
4861
cat >>actual
4962
EOF
5063

51-
cat >expected <<EOF
52-
parent1
53-
repo1
54-
refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1
55-
EOF
56-
5764
test_expect_success 'push with hook' '
65+
cat >expect <<-EOF &&
66+
parent1
67+
repo1
68+
refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1
69+
EOF
70+
5871
git push parent1 main:foreign &&
59-
diff expected actual
72+
test_cmp expect actual
6073
'
6174

6275
test_expect_success 'add a branch' '
@@ -67,49 +80,48 @@ test_expect_success 'add a branch' '
6780
COMMIT3="$(git rev-parse HEAD)"
6881
export COMMIT3
6982

70-
cat >expected <<EOF
71-
parent1
72-
repo1
73-
refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2
74-
EOF
75-
7683
test_expect_success 'push to default' '
84+
cat >expect <<-EOF &&
85+
parent1
86+
repo1
87+
refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2
88+
EOF
7789
git push &&
78-
diff expected actual
90+
test_cmp expect actual
7991
'
8092

81-
cat >expected <<EOF
82-
parent1
83-
repo1
84-
refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID
85-
HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID
86-
EOF
87-
8893
test_expect_success 'push non-branches' '
94+
cat >expect <<-EOF &&
95+
parent1
96+
repo1
97+
refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID
98+
HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID
99+
EOF
100+
89101
git push parent1 one:tag1 HEAD~:refs/heads/prev &&
90-
diff expected actual
102+
test_cmp expect actual
91103
'
92104

93-
cat >expected <<EOF
94-
parent1
95-
repo1
96-
(delete) $ZERO_OID refs/heads/prev $COMMIT2
97-
EOF
98-
99105
test_expect_success 'push delete' '
106+
cat >expect <<-EOF &&
107+
parent1
108+
repo1
109+
(delete) $ZERO_OID refs/heads/prev $COMMIT2
110+
EOF
111+
100112
git push parent1 :prev &&
101-
diff expected actual
113+
test_cmp expect actual
102114
'
103115

104-
cat >expected <<EOF
105-
repo1
106-
repo1
107-
HEAD $COMMIT3 refs/heads/other $ZERO_OID
108-
EOF
109-
110116
test_expect_success 'push to URL' '
117+
cat >expect <<-EOF &&
118+
repo1
119+
repo1
120+
HEAD $COMMIT3 refs/heads/other $ZERO_OID
121+
EOF
122+
111123
git push repo1 HEAD &&
112-
diff expected actual
124+
test_cmp expect actual
113125
'
114126

115127
test_expect_success 'set up many-ref tests' '

0 commit comments

Comments
 (0)