16
17
# Check status report for git-push
18
sed -n \
19
- -e "/^To / { p; n; p; }" \
19
+ -e "/^To / { p; }" \
20
+ -e "/^ ! / { p; }" \
21
<actual >actual-report &&
22
cat >expect <<-EOF &&
23
To <URL/of/upstream.git>
42
test_cmp expect actual
43
'
44
44
-test_expect_success "setup proc-receive hook (hook --die-version, $PROTOCOL)" '
45
+test_expect_success "setup proc-receive hook (hook --die-read-version, $PROTOCOL)" '
46
write_script "$upstream/hooks/proc-receive" <<-EOF
47
printf >&2 "# proc-receive hook\n"
47
- test-tool proc-receive -v --die-version
48
+ test-tool proc-receive -v --die-read-version
49
EOF
50
'
51
52
# Refs of upstream : main(A)
53
# Refs of workbench: main(A) tags/v123
54
# git push : refs/for/main/topic(A)
54
-test_expect_success "proc-receive: bad protocol (hook --die-version, $PROTOCOL)" '
55
+test_expect_success "proc-receive: bad protocol (hook --die-read-version, $PROTOCOL)" '
56
test_must_fail git -C workbench push origin \
57
HEAD:refs/for/main/topic \
58
>out 2>&1 &&
59
+ filter_out_user_friendly_and_stable_output \
60
+ -e "/^To / { p; }" \
61
+ -e "/^ ! / { p; }" \
62
+ <out >actual &&
63
+ cat >expect <<-EOF &&
64
+ To <URL/of/upstream.git>
65
+ ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
66
+ EOF
67
+ test_cmp expect actual &&
68
+ grep "remote: fatal: die with the --die-read-version option" out &&
69
+ grep "remote: error: fail to negotiate version with proc-receive hook" out &&
70
+
71
+ git -C "$upstream" show-ref >out &&
72
make_user_friendly_and_stable_output <out >actual &&
73
+ cat >expect <<-EOF &&
74
+ <COMMIT-A> refs/heads/main
75
+ EOF
76
+ test_cmp expect actual
77
+'
78
+
79
+test_expect_success "setup proc-receive hook (hook --die-write-version, $PROTOCOL)" '
80
+ write_script "$upstream/hooks/proc-receive" <<-EOF
81
+ printf >&2 "# proc-receive hook\n"
82
+ test-tool proc-receive -v --die-write-version
83
+ EOF
84
+'
85
86
+# Refs of upstream : main(A)
87
+# Refs of workbench: main(A) tags/v123
88
+# git push : refs/for/main/topic(A)
89
+test_expect_success "proc-receive: bad protocol (hook --die-write-version, $PROTOCOL)" '
90
+ test_must_fail git -C workbench push origin \
91
+ HEAD:refs/for/main/topic \
92
+ >out 2>&1 &&
93
+ filter_out_user_friendly_and_stable_output \
94
+ -e "/^To / { p; }" \
95
+ -e "/^ ! / { p; }" \
96
+ <out >actual &&
97
+ cat >expect <<-EOF &&
98
+ To <URL/of/upstream.git>
99
+ ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
100
+ EOF
101
+ test_cmp expect actual &&
102
+ grep "remote: fatal: die with the --die-write-version option" out &&
103
+ grep "remote: error: fail to negotiate version with proc-receive hook" out &&
104
+
105
+ git -C "$upstream" show-ref >out &&
106
+ make_user_friendly_and_stable_output <out >actual &&
107
+ cat >expect <<-EOF &&
108
+ <COMMIT-A> refs/heads/main
109
+ EOF
110
+ test_cmp expect actual
111
+'
112
+
113
+test_expect_success "setup proc-receive hook (hook --die-read-commands, $PROTOCOL)" '
114
+ write_script "$upstream/hooks/proc-receive" <<-EOF
115
+ printf >&2 "# proc-receive hook\n"
116
+ test-tool proc-receive -v --die-read-commands
117
+ EOF
118
+'
119
+
120
+# Refs of upstream : main(A)
121
+# Refs of workbench: main(A) tags/v123
122
+# git push : refs/for/main/topic(A)
123
+test_expect_success "proc-receive: bad protocol (hook --die-read-commands, $PROTOCOL)" '
124
+ test_must_fail git -C workbench push origin \
125
+ HEAD:refs/for/main/topic \
126
+ >out 2>&1 &&
127
+ filter_out_user_friendly_and_stable_output \
128
+ -e "/^To / { p; }" \
129
+ -e "/^ ! / { p; }" \
130
+ <out >actual &&
131
cat >expect <<-EOF &&
61
- remote: # pre-receive hook
62
- remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
63
- remote: # proc-receive hook
64
- remote: fatal: bad protocol version: 1
65
- remote: error: proc-receive version "0" is not supported
132
To <URL/of/upstream.git>
133
! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
134
EOF
135
test_cmp expect actual &&
136
+ grep "remote: fatal: die with the --die-read-commands option" out &&
137
138
git -C "$upstream" show-ref >out &&
139
make_user_friendly_and_stable_output <out >actual &&
143
test_cmp expect actual
144
'
145
79
-test_expect_success "setup proc-receive hook (hook --die-readline, $PROTOCOL)" '
146
+test_expect_success "setup proc-receive hook (hook --die-read-push-options, $PROTOCOL)" '
147
write_script "$upstream/hooks/proc-receive" <<-EOF
148
printf >&2 "# proc-receive hook\n"
82
- test-tool proc-receive -v --die-readline
149
+ test-tool proc-receive -v --die-read-push-options
150
EOF
151
'
152
153
# Refs of upstream : main(A)
154
# Refs of workbench: main(A) tags/v123
155
# git push : refs/for/main/topic(A)
89
-test_expect_success "proc-receive: bad protocol (hook --die-readline, $PROTOCOL)" '
156
+test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $PROTOCOL)" '
157
+ git -C "$upstream" config receive.advertisePushOptions true &&
158
test_must_fail git -C workbench push origin \
159
+ -o reviewers=user1,user2 \
160
HEAD:refs/for/main/topic \
161
>out 2>&1 &&
162
+ filter_out_user_friendly_and_stable_output \
163
+ -e "/^To / { p; }" \
164
+ -e "/^ ! / { p; }" \
165
+ <out >actual &&
166
+ cat >expect <<-EOF &&
167
+ To <URL/of/upstream.git>
168
+ ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
169
+ EOF
170
+ test_cmp expect actual &&
171
+ grep "remote: fatal: die with the --die-read-push-options option" out &&
172
+
173
+ git -C "$upstream" show-ref >out &&
174
make_user_friendly_and_stable_output <out >actual &&
175
+ cat >expect <<-EOF &&
176
+ <COMMIT-A> refs/heads/main
177
+ EOF
178
+ test_cmp expect actual
179
+'
180
+
181
+test_expect_success "setup proc-receive hook (hook --die-write-report, $PROTOCOL)" '
182
+ write_script "$upstream/hooks/proc-receive" <<-EOF
183
+ printf >&2 "# proc-receive hook\n"
184
+ test-tool proc-receive -v --die-write-report
185
+ EOF
186
+'
187
95
- grep "remote: fatal: protocol error: expected \"old new ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/main/topic\"" actual &&
188
+# Refs of upstream : main(A)
189
+# Refs of workbench: main(A) tags/v123
190
+# git push : refs/for/main/topic(A)
191
+test_expect_success "proc-receive: bad protocol (hook --die-write-report, $PROTOCOL)" '
192
+ test_must_fail git -C workbench push origin \
193
+ HEAD:refs/for/main/topic \
194
+ >out 2>&1 &&
195
+ filter_out_user_friendly_and_stable_output \
196
+ -e "/^To / { p; }" \
197
+ -e "/^ ! / { p; }" \
198
+ <out >actual &&
199
+ cat >expect <<-EOF &&
200
+ To <URL/of/upstream.git>
201
+ ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
202
+ EOF
203
+ test_cmp expect actual &&
204
+ grep "remote: fatal: die with the --die-write-report option" out &&
205
206
git -C "$upstream" show-ref >out &&
207
make_user_friendly_and_stable_output <out >actual &&
239
! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
240
EOF
241
test_cmp expect actual &&
242
+
243
git -C "$upstream" show-ref >out &&
244
make_user_friendly_and_stable_output <out >actual &&
245
cat >expect <<-EOF &&
283
! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
284
EOF
285
test_cmp expect actual &&
286
+
287
git -C "$upstream" show-ref >out &&
288
make_user_friendly_and_stable_output <out >actual &&
289
cat >expect <<-EOF &&
319
! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
320
EOF
321
test_cmp expect actual &&
322
+
323
git -C "$upstream" show-ref >out &&
324
make_user_friendly_and_stable_output <out >actual &&
325
cat >expect <<-EOF &&