]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5541-http-push-smart.sh
Merge branch 'js/update-index-ignore-removal-for-skip-worktree'
[thirdparty/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
d790ee17
JT
50 # NEEDSWORK: If the overspecification of the expected result is reduced, we
51 # might be able to run this test in all protocol versions.
52 if test -z "$GIT_TEST_PROTOCOL_VERSION"
53 then
54 check_access_log exp
55 fi
9ee6bcd3
TRC
56'
57
58test_expect_success 'clone remote repository' '
59 rm -rf test_repo_clone &&
f2c2c901
MM
60 git clone $HTTPD_URL/smart/test_repo.git test_repo_clone &&
61 (
62 cd test_repo_clone && git config push.default matching
63 )
7da4e228
SP
64'
65
0cc6330d 66test_expect_success 'push to remote repository (standard)' '
7da4e228
SP
67 cd "$ROOT_PATH"/test_repo_clone &&
68 : >path2 &&
69 git add path2 &&
70 test_tick &&
71 git commit -m path2 &&
72 HEAD=$(git rev-parse --verify HEAD) &&
4eee6c6d 73 GIT_TRACE_CURL=true git push -v -v 2>err &&
0cc6330d
TRC
74 ! grep "Expect: 100-continue" err &&
75 grep "POST git-receive-pack ([0-9]* bytes)" err &&
7da4e228
SP
76 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
77 test $HEAD = $(git rev-parse --verify HEAD))
78'
79
80test_expect_success 'push already up-to-date' '
81 git push
82'
83
84test_expect_success 'create and delete remote branch' '
85 cd "$ROOT_PATH"/test_repo_clone &&
86 git checkout -b dev &&
87 : >path3 &&
88 git add path3 &&
89 test_tick &&
90 git commit -m dev &&
91 git push origin dev &&
92 git push origin :dev &&
93 test_must_fail git show-ref --verify refs/remotes/origin/dev
94'
95
5238cbf6
SP
96cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<EOF
97#!/bin/sh
98exit 1
99EOF
100chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
101
102cat >exp <<EOF
103remote: error: hook declined to update refs/heads/dev2
104To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
105 ! [remote rejected] dev2 -> dev2 (hook declined)
d202a513 106error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'
5238cbf6
SP
107EOF
108
109test_expect_success 'rejected update prints status' '
110 cd "$ROOT_PATH"/test_repo_clone &&
111 git checkout -b dev2 &&
112 : >path4 &&
113 git add path4 &&
114 test_tick &&
115 git commit -m dev2 &&
116 test_must_fail git push origin dev2 2>act &&
117 sed -e "/^remote: /s/ *$//" <act >cmp &&
415c7dd0 118 test_i18ncmp exp cmp
5238cbf6
SP
119'
120rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
121
7da4e228
SP
122cat >exp <<EOF
123GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
124POST /smart/test_repo.git/git-upload-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
127GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
128GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
129POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
130GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
131POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
5238cbf6
SP
132GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
133POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
7da4e228
SP
134EOF
135test_expect_success 'used receive-pack service' '
d790ee17
JT
136 # NEEDSWORK: If the overspecification of the expected result is reduced, we
137 # might be able to run this test in all protocol versions.
138 if test -z "$GIT_TEST_PROTOCOL_VERSION"
139 then
140 check_access_log exp
141 fi
7da4e228
SP
142'
143
6cbd6e92 144test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
05c1eb10 145 "$ROOT_PATH"/test_repo_clone master success
19452374 146
08d63a42 147test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
7b69079b
TRC
148 # create a dissimilarly-named remote ref so that git is unable to match the
149 # two refs (viz. local, remote) unless an explicit refspec is provided.
99094a7a 150 git push origin master:retsam &&
7b69079b
TRC
151
152 echo "change changed" > path2 &&
153 git commit -a -m path2 --amend &&
154
155 # push master too; this ensures there is at least one '"'push'"' command to
156 # the remote helper and triggers interaction with the helper.
b32227e7 157 test_must_fail git push -v origin +master master:retsam >output 2>&1'
7b69079b 158
b32227e7 159test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: remote output' '
7b69079b 160 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
b32227e7
ÆAB
161 grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output
162'
7b69079b 163
b3e1900a 164test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: our output' '
0aff719f 165 test_i18ngrep "Updates were rejected because" \
9567f082 166 output
7b69079b
TRC
167'
168
0cc6330d
TRC
169test_expect_success 'push (chunked)' '
170 git checkout master &&
171 test_commit commit path3 &&
172 HEAD=$(git rev-parse --verify HEAD) &&
8677b777 173 test_config http.postbuffer 4 &&
0cc6330d
TRC
174 git push -v -v origin $BRANCH 2>err &&
175 grep "POST git-receive-pack (chunked)" err &&
176 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
177 test $HEAD = $(git rev-parse --verify HEAD))
178'
179
3bca1e7f
ES
180test_expect_success 'push --atomic also prevents branch creation, reports collateral' '
181 # Setup upstream repo - empty for now
182 d=$HTTPD_DOCUMENT_ROOT_PATH/atomic-branches.git &&
183 git init --bare "$d" &&
184 test_config -C "$d" http.receivepack true &&
185 up="$HTTPD_URL"/smart/atomic-branches.git &&
186
6f119424 187 # Tell "$up" about three branches for now
3bca1e7f
ES
188 test_commit atomic1 &&
189 test_commit atomic2 &&
190 git branch collateral &&
6f119424 191 git branch other &&
192 git push "$up" master collateral other &&
3bca1e7f
ES
193
194 # collateral is a valid push, but should be failed by atomic push
195 git checkout collateral &&
196 test_commit collateral1 &&
197
198 # Make master incompatible with upstream to provoke atomic
199 git checkout master &&
200 git reset --hard HEAD^ &&
201
202 # Add a new branch which should be failed by atomic push. This is a
203 # regression case.
204 git branch atomic &&
205
206 # --atomic should cause entire push to be rejected
207 test_must_fail git push --atomic "$up" master atomic collateral 2>output &&
208
209 # the new branch should not have been created upstream
210 test_must_fail git -C "$d" show-ref --verify refs/heads/atomic &&
211
212 # upstream should still reflect atomic2, the last thing we pushed
213 # successfully
214 git rev-parse atomic2 >expected &&
215 # on master...
216 git -C "$d" rev-parse refs/heads/master >actual &&
217 test_cmp expected actual &&
218 # ...and collateral.
219 git -C "$d" rev-parse refs/heads/collateral >actual &&
220 test_cmp expected actual &&
221
222 # the failed refs should be indicated to the user
223 grep "^ ! .*rejected.* master -> master" output &&
224
225 # the collateral failure refs should be indicated to the user
226 grep "^ ! .*rejected.* atomic -> atomic .*atomic push failed" output &&
227 grep "^ ! .*rejected.* collateral -> collateral .*atomic push failed" output
228'
229
6f119424 230test_expect_success 'push --atomic fails on server-side errors' '
231 # Use previously set up repository
232 d=$HTTPD_DOCUMENT_ROOT_PATH/atomic-branches.git &&
233 test_config -C "$d" http.receivepack true &&
234 up="$HTTPD_URL"/smart/atomic-branches.git &&
235
236 # break ref updates for other on the remote site
237 mkdir "$d/refs/heads/other.lock" &&
238
239 # add the new commit to other
240 git branch -f other collateral &&
241
242 # --atomic should cause entire push to be rejected
243 test_must_fail git push --atomic "$up" atomic other 2>output &&
244
245 # the new branch should not have been created upstream
246 test_must_fail git -C "$d" show-ref --verify refs/heads/atomic &&
247
248 # upstream should still reflect atomic2, the last thing we pushed
249 # successfully
250 git rev-parse atomic2 >expected &&
251 # ...to other.
252 git -C "$d" rev-parse refs/heads/other >actual &&
253 test_cmp expected actual &&
254
255 # the new branch should not have been created upstream
256 test_must_fail git -C "$d" show-ref --verify refs/heads/atomic &&
257
258 # the failed refs should be indicated to the user
259 grep "^ ! .*rejected.* other -> other .*atomic transaction failed" output &&
260
261 # the collateral failure refs should be indicated to the user
262 grep "^ ! .*rejected.* atomic -> atomic .*atomic transaction failed" output
263'
264
02f79147
JK
265test_expect_success 'push --all can push to empty repo' '
266 d=$HTTPD_DOCUMENT_ROOT_PATH/empty-all.git &&
267 git init --bare "$d" &&
268 git --git-dir="$d" config http.receivepack true &&
269 git push --all "$HTTPD_URL"/smart/empty-all.git
270'
271
272test_expect_success 'push --mirror can push to empty repo' '
273 d=$HTTPD_DOCUMENT_ROOT_PATH/empty-mirror.git &&
274 git init --bare "$d" &&
275 git --git-dir="$d" config http.receivepack true &&
276 git push --mirror "$HTTPD_URL"/smart/empty-mirror.git
277'
278
279test_expect_success 'push --all to repo with alternates' '
280 s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
281 d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-all.git &&
282 git clone --bare --shared "$s" "$d" &&
283 git --git-dir="$d" config http.receivepack true &&
284 git --git-dir="$d" repack -adl &&
285 git push --all "$HTTPD_URL"/smart/alternates-all.git
286'
287
288test_expect_success 'push --mirror to repo with alternates' '
289 s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
290 d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-mirror.git &&
291 git clone --bare --shared "$s" "$d" &&
292 git --git-dir="$d" config http.receivepack true &&
293 git --git-dir="$d" repack -adl &&
294 git push --mirror "$HTTPD_URL"/smart/alternates-mirror.git
295'
296
e304aeba
JK
297test_expect_success TTY 'push shows progress when stderr is a tty' '
298 cd "$ROOT_PATH"/test_repo_clone &&
299 test_commit noisy &&
300 test_terminal git push >output 2>&1 &&
bbf47568 301 test_i18ngrep "^Writing objects" output
e304aeba
JK
302'
303
304test_expect_success TTY 'push --quiet silences status and progress' '
c207e34f
CB
305 cd "$ROOT_PATH"/test_repo_clone &&
306 test_commit quiet &&
e304aeba 307 test_terminal git push --quiet >output 2>&1 &&
ec21ac8c 308 test_must_be_empty output
c207e34f
CB
309'
310
e304aeba
JK
311test_expect_success TTY 'push --no-progress silences progress but not status' '
312 cd "$ROOT_PATH"/test_repo_clone &&
313 test_commit no-progress &&
314 test_terminal git push --no-progress >output 2>&1 &&
415c7dd0 315 test_i18ngrep "^To http" output &&
bbf47568 316 test_i18ngrep ! "^Writing objects" output
e304aeba
JK
317'
318
319test_expect_success 'push --progress shows progress to non-tty' '
320 cd "$ROOT_PATH"/test_repo_clone &&
321 test_commit progress &&
322 git push --progress >output 2>&1 &&
415c7dd0 323 test_i18ngrep "^To http" output &&
bbf47568 324 test_i18ngrep "^Writing objects" output
e304aeba
JK
325'
326
e32a4581
JK
327test_expect_success 'http push gives sane defaults to reflog' '
328 cd "$ROOT_PATH"/test_repo_clone &&
329 test_commit reflog-test &&
330 git push "$HTTPD_URL"/smart/test_repo.git &&
331 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
332 log -g -1 --format="%gn <%ge>" >actual &&
333 echo "anonymous <anonymous@http.127.0.0.1>" >expect &&
334 test_cmp expect actual
335'
336
337test_expect_success 'http push respects GIT_COMMITTER_* in reflog' '
338 cd "$ROOT_PATH"/test_repo_clone &&
339 test_commit custom-reflog-test &&
340 git push "$HTTPD_URL"/smart_custom_env/test_repo.git &&
341 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
342 log -g -1 --format="%gn <%ge>" >actual &&
343 echo "Custom User <custom@example.com>" >expect &&
344 test_cmp expect actual
345'
346
6ac2b3ae
JK
347test_expect_success 'push over smart http with auth' '
348 cd "$ROOT_PATH/test_repo_clone" &&
349 echo push-auth-test >expect &&
350 test_commit push-auth-test &&
afbf5ca5 351 set_askpass user@host pass@host &&
6ac2b3ae
JK
352 git push "$HTTPD_URL"/auth/smart/test_repo.git &&
353 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
354 log -1 --format=%s >actual &&
355 expect_askpass both user@host &&
356 test_cmp expect actual
357'
358
b81401c1 359test_expect_success 'push to auth-only-for-push repo' '
4c71009d
JK
360 cd "$ROOT_PATH/test_repo_clone" &&
361 echo push-half-auth >expect &&
362 test_commit push-half-auth &&
afbf5ca5 363 set_askpass user@host pass@host &&
4c71009d
JK
364 git push "$HTTPD_URL"/auth-push/smart/test_repo.git &&
365 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
366 log -1 --format=%s >actual &&
367 expect_askpass both user@host &&
368 test_cmp expect actual
369'
370
b0808819
JK
371test_expect_success 'create repo without http.receivepack set' '
372 cd "$ROOT_PATH" &&
373 git init half-auth &&
374 (
375 cd half-auth &&
376 test_commit one
377 ) &&
378 git clone --bare half-auth "$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git"
379'
380
381test_expect_success 'clone via half-auth-complete does not need password' '
382 cd "$ROOT_PATH" &&
383 set_askpass wrong &&
384 git clone "$HTTPD_URL"/half-auth-complete/smart/half-auth.git \
385 half-auth-clone &&
386 expect_askpass none
387'
388
389test_expect_success 'push into half-auth-complete requires password' '
390 cd "$ROOT_PATH/half-auth-clone" &&
391 echo two >expect &&
392 test_commit two &&
afbf5ca5 393 set_askpass user@host pass@host &&
b0808819
JK
394 git push "$HTTPD_URL/half-auth-complete/smart/half-auth.git" &&
395 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git" \
396 log -1 --format=%s >actual &&
397 expect_askpass both user@host &&
398 test_cmp expect actual
399'
400
26be19ba
JK
401test_expect_success CMDLINE_LIMIT 'push 2000 tags over http' '
402 sha1=$(git rev-parse HEAD) &&
403 test_seq 2000 |
404 sort |
405 sed "s|.*|$sha1 refs/tags/really-long-tag-name-&|" \
406 >.git/packed-refs &&
407 run_with_limited_cmdline git push --mirror
408'
409
0ea47f9d
JH
410test_expect_success GPG 'push with post-receive to inspect certificate' '
411 (
412 cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
413 mkdir -p hooks &&
414 write_script hooks/post-receive <<-\EOF &&
415 # discard the update list
416 cat >/dev/null
417 # record the push certificate
418 if test -n "${GIT_PUSH_CERT-}"
419 then
420 git cat-file blob $GIT_PUSH_CERT >../push-cert
421 fi &&
422 cat >../push-cert-status <<E_O_F
423 SIGNER=${GIT_PUSH_CERT_SIGNER-nobody}
424 KEY=${GIT_PUSH_CERT_KEY-nokey}
425 STATUS=${GIT_PUSH_CERT_STATUS-nostatus}
5732373d
JH
426 NONCE_STATUS=${GIT_PUSH_CERT_NONCE_STATUS-nononcestatus}
427 NONCE=${GIT_PUSH_CERT_NONCE-nononce}
0ea47f9d
JH
428 E_O_F
429 EOF
430
5732373d
JH
431 git config receive.certnonceseed sekrit &&
432 git config receive.certnonceslop 30
0ea47f9d
JH
433 ) &&
434 cd "$ROOT_PATH/test_repo_clone" &&
435 test_commit cert-test &&
436 git push --signed "$HTTPD_URL/smart/test_repo.git" &&
437 (
438 cd "$HTTPD_DOCUMENT_ROOT_PATH" &&
5732373d 439 cat <<-\EOF &&
0ea47f9d
JH
440 SIGNER=C O Mitter <committer@example.com>
441 KEY=13B6F51ECDDE430D
442 STATUS=G
5732373d 443 NONCE_STATUS=OK
0ea47f9d 444 EOF
5732373d 445 sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" push-cert
0ea47f9d
JH
446 ) >expect &&
447 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH/push-cert-status"
448'
449
882d49ca 450test_expect_success 'push status output scrubs password' '
68f3c079
JK
451 cd "$ROOT_PATH/test_repo_clone" &&
452 git push --porcelain \
453 "$HTTPD_URL_USER_PASS/smart/test_repo.git" \
454 +HEAD:scrub >status &&
882d49ca
JK
455 # should have been scrubbed down to vanilla URL
456 grep "^To $HTTPD_URL/smart/test_repo.git" status
457'
458
8301266a
JS
459test_expect_success 'colorize errors/hints' '
460 cd "$ROOT_PATH"/test_repo_clone &&
461 test_must_fail git -c color.transport=always -c color.advice=always \
462 -c color.push=always \
463 push origin origin/master^:master 2>act &&
464 test_decode_color <act >decoded &&
465 test_i18ngrep "<RED>.*rejected.*<RESET>" decoded &&
466 test_i18ngrep "<RED>error: failed to push some refs" decoded &&
467 test_i18ngrep "<YELLOW>hint: " decoded &&
468 test_i18ngrep ! "^hint: " decoded
469'
470
7da4e228 471test_done