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