]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5571-pre-push-hook.sh
tests: fix broken &&-chains in `$(...)` command substitutions
[thirdparty/git.git] / t / t5571-pre-push-hook.sh
CommitLineData
ec55559f
AS
1#!/bin/sh
2
3test_description='check pre-push hooks'
028cb644 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
ec55559f
AS
7. ./test-lib.sh
8
9# Setup hook that always succeeds
10HOOKDIR="$(git rev-parse --git-dir)/hooks"
11HOOK="$HOOKDIR/pre-push"
12mkdir -p "$HOOKDIR"
13write_script "$HOOK" <<EOF
14cat >/dev/null
15exit 0
16EOF
17
18test_expect_success 'setup' '
19 git config push.default upstream &&
20 git init --bare repo1 &&
21 git remote add parent1 repo1 &&
22 test_commit one &&
23 git push parent1 HEAD:foreign
24'
25write_script "$HOOK" <<EOF
26cat >/dev/null
27exit 1
28EOF
29
30COMMIT1="$(git rev-parse HEAD)"
31export COMMIT1
32
33test_expect_success 'push with failing hook' '
34 test_commit two &&
35 test_must_fail git push parent1 HEAD
36'
37
38test_expect_success '--no-verify bypasses hook' '
39 git push --no-verify parent1 HEAD
40'
41
42COMMIT2="$(git rev-parse HEAD)"
43export COMMIT2
44
45write_script "$HOOK" <<'EOF'
46echo "$1" >actual
47echo "$2" >>actual
48cat >>actual
49EOF
50
51cat >expected <<EOF
52parent1
53repo1
028cb644 54refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1
ec55559f
AS
55EOF
56
57test_expect_success 'push with hook' '
028cb644 58 git push parent1 main:foreign &&
ec55559f
AS
59 diff expected actual
60'
61
62test_expect_success 'add a branch' '
63 git checkout -b other parent1/foreign &&
64 test_commit three
65'
66
67COMMIT3="$(git rev-parse HEAD)"
68export COMMIT3
69
70cat >expected <<EOF
71parent1
72repo1
73refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2
74EOF
75
76test_expect_success 'push to default' '
77 git push &&
78 diff expected actual
79'
80
81cat >expected <<EOF
82parent1
83repo1
8125a58b 84refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID
85HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID
ec55559f
AS
86EOF
87
88test_expect_success 'push non-branches' '
89 git push parent1 one:tag1 HEAD~:refs/heads/prev &&
90 diff expected actual
91'
92
93cat >expected <<EOF
94parent1
95repo1
8125a58b 96(delete) $ZERO_OID refs/heads/prev $COMMIT2
ec55559f
AS
97EOF
98
99test_expect_success 'push delete' '
100 git push parent1 :prev &&
101 diff expected actual
102'
103
104cat >expected <<EOF
105repo1
106repo1
8125a58b 107HEAD $COMMIT3 refs/heads/other $ZERO_OID
ec55559f
AS
108EOF
109
110test_expect_success 'push to URL' '
111 git push repo1 HEAD &&
112 diff expected actual
113'
114
af65f68c
CB
115test_expect_success 'set up many-ref tests' '
116 {
117 nr=1000
118 while test $nr -lt 2000
119 do
74d2f569 120 nr=$(( $nr + 1 )) &&
af65f68c
CB
121 echo "create refs/heads/b/$nr $COMMIT3"
122 done
123 } | git update-ref --stdin
124'
125
126test_expect_success 'sigpipe does not cause pre-push hook failure' '
127 echo "exit 0" | write_script "$HOOK" &&
128 git push parent1 "refs/heads/b/*:refs/heads/b/*"
129'
ec55559f
AS
130
131test_done