t5700: only run with protocol version 1
[git/git.git] / t / t5541-http-push-smart.sh
CommitLineData
7da4e228
SP
1#!/bin/sh
2#
3# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
4#
5
6test_description='test smart pushing over http via http-backend'
7. ./test-lib.sh
8
7da4e228 9ROOT_PATH="$PWD"
0ea47f9d 10. "$TEST_DIRECTORY"/lib-gpg.sh
7da4e228 11. "$TEST_DIRECTORY"/lib-httpd.sh
d336572f 12. "$TEST_DIRECTORY"/lib-terminal.sh
7da4e228
SP
13start_httpd
14
15test_expect_success 'setup remote repository' '
16 cd "$ROOT_PATH" &&
17 mkdir test_repo &&
18 cd test_repo &&
19 git init &&
20 : >path1 &&
21 git add path1 &&
22 test_tick &&
23 git commit -m initial &&
24 cd - &&
25 git clone --bare test_repo test_repo.git &&
26 cd test_repo.git &&
27 git config http.receivepack true &&
e32a4581 28 git config core.logallrefupdates true &&
7da4e228
SP
29 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
30 cd - &&
31 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
32'
33
6ac2b3ae
JK
34setup_askpass_helper
35
9ee6bcd3
TRC
36cat >exp <<EOF
37GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
38POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
39EOF
d8fab072 40test_expect_success 'no empty path components' '
a704c643
SG
41 # Clear the log, so that it does not affect the "used receive-pack
42 # service" test which reads the log too.
43 test_when_finished ">\"\$HTTPD_ROOT_PATH\"/access.log" &&
44
9ee6bcd3
TRC
45 # In the URL, add a trailing slash, and see if git appends yet another
46 # slash.
7da4e228 47 cd "$ROOT_PATH" &&
9ee6bcd3
TRC
48 git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
49
e8b3b2e2 50 check_access_log exp
9ee6bcd3
TRC
51'
52
53test_expect_success 'clone remote repository' '
54 rm -rf test_repo_clone &&
f2c2c901
MM
55 git clone $HTTPD_URL/smart/test_repo.git test_repo_clone &&
56 (
57 cd test_repo_clone && git config push.default matching
58 )
7da4e228
SP
59'
60
0cc6330d 61test_expect_success 'push to remote repository (standard)' '
7da4e228
SP
62 cd "$ROOT_PATH"/test_repo_clone &&
63 : >path2 &&
64 git add path2 &&
65 test_tick &&
66 git commit -m path2 &&
67 HEAD=$(git rev-parse --verify HEAD) &&
4eee6c6d 68 GIT_TRACE_CURL=true git push -v -v 2>err &&
0cc6330d
TRC
69 ! grep "Expect: 100-continue" err &&
70 grep "POST git-receive-pack ([0-9]* bytes)" err &&
7da4e228
SP
71 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
72 test $HEAD = $(git rev-parse --verify HEAD))
73'
74
75test_expect_success 'push already up-to-date' '
76 git push
77'
78
79test_expect_success 'create and delete remote branch' '
80 cd "$ROOT_PATH"/test_repo_clone &&
81 git checkout -b dev &&
82 : >path3 &&
83 git add path3 &&
84 test_tick &&
85 git commit -m dev &&
86 git push origin dev &&
87 git push origin :dev &&
88 test_must_fail git show-ref --verify refs/remotes/origin/dev
89'
90
5238cbf6
SP
91cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<EOF
92#!/bin/sh
93exit 1
94EOF
95chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
96
97cat >exp <<EOF
98remote: error: hook declined to update refs/heads/dev2
99To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
100 ! [remote rejected] dev2 -> dev2 (hook declined)
d202a513 101error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'
5238cbf6
SP
102EOF
103
104test_expect_success 'rejected update prints status' '
105 cd "$ROOT_PATH"/test_repo_clone &&
106 git checkout -b dev2 &&
107 : >path4 &&
108 git add path4 &&
109 test_tick &&
110 git commit -m dev2 &&
111 test_must_fail git push origin dev2 2>act &&
112 sed -e "/^remote: /s/ *$//" <act >cmp &&
415c7dd0 113 test_i18ncmp exp cmp
5238cbf6
SP
114'
115rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
116
7da4e228
SP
117cat >exp <<EOF
118GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
119POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
120GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
121POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
122GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
123GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
124POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
125GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
126POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
5238cbf6
SP
127GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
128POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
7da4e228
SP
129EOF
130test_expect_success 'used receive-pack service' '
e8b3b2e2 131 check_access_log exp
7da4e228
SP
132'
133
6cbd6e92 134test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
05c1eb10 135 "$ROOT_PATH"/test_repo_clone master success
19452374 136
08d63a42 137test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
7b69079b
TRC
138 # create a dissimilarly-named remote ref so that git is unable to match the
139 # two refs (viz. local, remote) unless an explicit refspec is provided.
99094a7a 140 git push origin master:retsam &&
7b69079b
TRC
141
142 echo "change changed" > path2 &&
143 git commit -a -m path2 --amend &&
144
145 # push master too; this ensures there is at least one '"'push'"' command to
146 # the remote helper and triggers interaction with the helper.
b32227e7 147 test_must_fail git push -v origin +master master:retsam >output 2>&1'
7b69079b 148
b32227e7 149test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: remote output' '
7b69079b 150 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
b32227e7
ÆAB
151 grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output
152'
7b69079b 153
b3e1900a 154test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: our output' '
0aff719f 155 test_i18ngrep "Updates were rejected because" \
9567f082 156 output
7b69079b
TRC
157'
158
0cc6330d
TRC
159test_expect_success 'push (chunked)' '
160 git checkout master &&
161 test_commit commit path3 &&
162 HEAD=$(git rev-parse --verify HEAD) &&
8677b777 163 test_config http.postbuffer 4 &&
0cc6330d
TRC
164 git push -v -v origin $BRANCH 2>err &&
165 grep "POST git-receive-pack (chunked)" err &&
166 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
167 test $HEAD = $(git rev-parse --verify HEAD))
168'
169
02f79147
JK
170test_expect_success 'push --all can push to empty repo' '
171 d=$HTTPD_DOCUMENT_ROOT_PATH/empty-all.git &&
172 git init --bare "$d" &&
173 git --git-dir="$d" config http.receivepack true &&
174 git push --all "$HTTPD_URL"/smart/empty-all.git
175'
176
177test_expect_success 'push --mirror can push to empty repo' '
178 d=$HTTPD_DOCUMENT_ROOT_PATH/empty-mirror.git &&
179 git init --bare "$d" &&
180 git --git-dir="$d" config http.receivepack true &&
181 git push --mirror "$HTTPD_URL"/smart/empty-mirror.git
182'
183
184test_expect_success 'push --all to repo with alternates' '
185 s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
186 d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-all.git &&
187 git clone --bare --shared "$s" "$d" &&
188 git --git-dir="$d" config http.receivepack true &&
189 git --git-dir="$d" repack -adl &&
190 git push --all "$HTTPD_URL"/smart/alternates-all.git
191'
192
193test_expect_success 'push --mirror to repo with alternates' '
194 s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
195 d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-mirror.git &&
196 git clone --bare --shared "$s" "$d" &&
197 git --git-dir="$d" config http.receivepack true &&
198 git --git-dir="$d" repack -adl &&
199 git push --mirror "$HTTPD_URL"/smart/alternates-mirror.git
200'
201
e304aeba
JK
202test_expect_success TTY 'push shows progress when stderr is a tty' '
203 cd "$ROOT_PATH"/test_repo_clone &&
204 test_commit noisy &&
205 test_terminal git push >output 2>&1 &&
415c7dd0 206 test_i18ngrep "^Writing objects" output
e304aeba
JK
207'
208
209test_expect_success TTY 'push --quiet silences status and progress' '
c207e34f
CB
210 cd "$ROOT_PATH"/test_repo_clone &&
211 test_commit quiet &&
e304aeba 212 test_terminal git push --quiet >output 2>&1 &&
ec21ac8c 213 test_must_be_empty output
c207e34f
CB
214'
215
e304aeba
JK
216test_expect_success TTY 'push --no-progress silences progress but not status' '
217 cd "$ROOT_PATH"/test_repo_clone &&
218 test_commit no-progress &&
219 test_terminal git push --no-progress >output 2>&1 &&
415c7dd0 220 test_i18ngrep "^To http" output &&
8cdef01c 221 test_i18ngrep ! "^Writing objects" output
e304aeba
JK
222'
223
224test_expect_success 'push --progress shows progress to non-tty' '
225 cd "$ROOT_PATH"/test_repo_clone &&
226 test_commit progress &&
227 git push --progress >output 2>&1 &&
415c7dd0
VA
228 test_i18ngrep "^To http" output &&
229 test_i18ngrep "^Writing objects" output
e304aeba
JK
230'
231
e32a4581
JK
232test_expect_success 'http push gives sane defaults to reflog' '
233 cd "$ROOT_PATH"/test_repo_clone &&
234 test_commit reflog-test &&
235 git push "$HTTPD_URL"/smart/test_repo.git &&
236 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
237 log -g -1 --format="%gn <%ge>" >actual &&
238 echo "anonymous <anonymous@http.127.0.0.1>" >expect &&
239 test_cmp expect actual
240'
241
242test_expect_success 'http push respects GIT_COMMITTER_* in reflog' '
243 cd "$ROOT_PATH"/test_repo_clone &&
244 test_commit custom-reflog-test &&
245 git push "$HTTPD_URL"/smart_custom_env/test_repo.git &&
246 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
247 log -g -1 --format="%gn <%ge>" >actual &&
248 echo "Custom User <custom@example.com>" >expect &&
249 test_cmp expect actual
250'
251
6ac2b3ae
JK
252test_expect_success 'push over smart http with auth' '
253 cd "$ROOT_PATH/test_repo_clone" &&
254 echo push-auth-test >expect &&
255 test_commit push-auth-test &&
afbf5ca5 256 set_askpass user@host pass@host &&
6ac2b3ae
JK
257 git push "$HTTPD_URL"/auth/smart/test_repo.git &&
258 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
259 log -1 --format=%s >actual &&
260 expect_askpass both user@host &&
261 test_cmp expect actual
262'
263
b81401c1 264test_expect_success 'push to auth-only-for-push repo' '
4c71009d
JK
265 cd "$ROOT_PATH/test_repo_clone" &&
266 echo push-half-auth >expect &&
267 test_commit push-half-auth &&
afbf5ca5 268 set_askpass user@host pass@host &&
4c71009d
JK
269 git push "$HTTPD_URL"/auth-push/smart/test_repo.git &&
270 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
271 log -1 --format=%s >actual &&
272 expect_askpass both user@host &&
273 test_cmp expect actual
274'
275
b0808819
JK
276test_expect_success 'create repo without http.receivepack set' '
277 cd "$ROOT_PATH" &&
278 git init half-auth &&
279 (
280 cd half-auth &&
281 test_commit one
282 ) &&
283 git clone --bare half-auth "$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git"
284'
285
286test_expect_success 'clone via half-auth-complete does not need password' '
287 cd "$ROOT_PATH" &&
288 set_askpass wrong &&
289 git clone "$HTTPD_URL"/half-auth-complete/smart/half-auth.git \
290 half-auth-clone &&
291 expect_askpass none
292'
293
294test_expect_success 'push into half-auth-complete requires password' '
295 cd "$ROOT_PATH/half-auth-clone" &&
296 echo two >expect &&
297 test_commit two &&
afbf5ca5 298 set_askpass user@host pass@host &&
b0808819
JK
299 git push "$HTTPD_URL/half-auth-complete/smart/half-auth.git" &&
300 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git" \
301 log -1 --format=%s >actual &&
302 expect_askpass both user@host &&
303 test_cmp expect actual
304'
305
26be19ba
JK
306test_expect_success CMDLINE_LIMIT 'push 2000 tags over http' '
307 sha1=$(git rev-parse HEAD) &&
308 test_seq 2000 |
309 sort |
310 sed "s|.*|$sha1 refs/tags/really-long-tag-name-&|" \
311 >.git/packed-refs &&
312 run_with_limited_cmdline git push --mirror
313'
314
0ea47f9d
JH
315test_expect_success GPG 'push with post-receive to inspect certificate' '
316 (
317 cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
318 mkdir -p hooks &&
319 write_script hooks/post-receive <<-\EOF &&
320 # discard the update list
321 cat >/dev/null
322 # record the push certificate
323 if test -n "${GIT_PUSH_CERT-}"
324 then
325 git cat-file blob $GIT_PUSH_CERT >../push-cert
326 fi &&
327 cat >../push-cert-status <<E_O_F
328 SIGNER=${GIT_PUSH_CERT_SIGNER-nobody}
329 KEY=${GIT_PUSH_CERT_KEY-nokey}
330 STATUS=${GIT_PUSH_CERT_STATUS-nostatus}
5732373d
JH
331 NONCE_STATUS=${GIT_PUSH_CERT_NONCE_STATUS-nononcestatus}
332 NONCE=${GIT_PUSH_CERT_NONCE-nononce}
0ea47f9d
JH
333 E_O_F
334 EOF
335
5732373d
JH
336 git config receive.certnonceseed sekrit &&
337 git config receive.certnonceslop 30
0ea47f9d
JH
338 ) &&
339 cd "$ROOT_PATH/test_repo_clone" &&
340 test_commit cert-test &&
341 git push --signed "$HTTPD_URL/smart/test_repo.git" &&
342 (
343 cd "$HTTPD_DOCUMENT_ROOT_PATH" &&
5732373d 344 cat <<-\EOF &&
0ea47f9d
JH
345 SIGNER=C O Mitter <committer@example.com>
346 KEY=13B6F51ECDDE430D
347 STATUS=G
5732373d 348 NONCE_STATUS=OK
0ea47f9d 349 EOF
5732373d 350 sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" push-cert
0ea47f9d
JH
351 ) >expect &&
352 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH/push-cert-status"
353'
354
882d49ca 355test_expect_success 'push status output scrubs password' '
68f3c079
JK
356 cd "$ROOT_PATH/test_repo_clone" &&
357 git push --porcelain \
358 "$HTTPD_URL_USER_PASS/smart/test_repo.git" \
359 +HEAD:scrub >status &&
882d49ca
JK
360 # should have been scrubbed down to vanilla URL
361 grep "^To $HTTPD_URL/smart/test_repo.git" status
362'
363
8301266a
JS
364test_expect_success 'colorize errors/hints' '
365 cd "$ROOT_PATH"/test_repo_clone &&
366 test_must_fail git -c color.transport=always -c color.advice=always \
367 -c color.push=always \
368 push origin origin/master^:master 2>act &&
369 test_decode_color <act >decoded &&
370 test_i18ngrep "<RED>.*rejected.*<RESET>" decoded &&
371 test_i18ngrep "<RED>error: failed to push some refs" decoded &&
372 test_i18ngrep "<YELLOW>hint: " decoded &&
373 test_i18ngrep ! "^hint: " decoded
374'
375
7da4e228
SP
376stop_httpd
377test_done