t5541: clean up truncating access log
[git.git] / t / t5541-http-push-smart.sh
blobdc08275b7d467cd49b9c204664a9497f90d5f82f
1 #!/bin/sh
3 # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
6 test_description='test smart pushing over http via http-backend'
7 . ./test-lib.sh
9 ROOT_PATH="$PWD"
10 . "$TEST_DIRECTORY"/lib-gpg.sh
11 . "$TEST_DIRECTORY"/lib-httpd.sh
12 . "$TEST_DIRECTORY"/lib-terminal.sh
13 start_httpd
15 test_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 &&
28 git config core.logallrefupdates true &&
29 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
30 cd - &&
31 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
34 setup_askpass_helper
36 cat >exp <<EOF
37 GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
38 POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
39 EOF
40 test_expect_success 'no empty path components' '
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" &&
45 # In the URL, add a trailing slash, and see if git appends yet another
46 # slash.
47 cd "$ROOT_PATH" &&
48 git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
50 sed -e "
51 s/^.* \"//
52 s/\"//
53 s/ [1-9][0-9]*\$//
54 s/^GET /GET /
55 " >act <"$HTTPD_ROOT_PATH"/access.log &&
56 test_cmp exp act
59 test_expect_success 'clone remote repository' '
60 rm -rf test_repo_clone &&
61 git clone $HTTPD_URL/smart/test_repo.git test_repo_clone &&
63 cd test_repo_clone && git config push.default matching
67 test_expect_success 'push to remote repository (standard)' '
68 cd "$ROOT_PATH"/test_repo_clone &&
69 : >path2 &&
70 git add path2 &&
71 test_tick &&
72 git commit -m path2 &&
73 HEAD=$(git rev-parse --verify HEAD) &&
74 GIT_TRACE_CURL=true git push -v -v 2>err &&
75 ! grep "Expect: 100-continue" err &&
76 grep "POST git-receive-pack ([0-9]* bytes)" err &&
77 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
78 test $HEAD = $(git rev-parse --verify HEAD))
81 test_expect_success 'push already up-to-date' '
82 git push
85 test_expect_success 'create and delete remote branch' '
86 cd "$ROOT_PATH"/test_repo_clone &&
87 git checkout -b dev &&
88 : >path3 &&
89 git add path3 &&
90 test_tick &&
91 git commit -m dev &&
92 git push origin dev &&
93 git push origin :dev &&
94 test_must_fail git show-ref --verify refs/remotes/origin/dev
97 cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<EOF
98 #!/bin/sh
99 exit 1
101 chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
103 cat >exp <<EOF
104 remote: error: hook declined to update refs/heads/dev2
105 To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
106 ! [remote rejected] dev2 -> dev2 (hook declined)
107 error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'
110 test_expect_success 'rejected update prints status' '
111 cd "$ROOT_PATH"/test_repo_clone &&
112 git checkout -b dev2 &&
113 : >path4 &&
114 git add path4 &&
115 test_tick &&
116 git commit -m dev2 &&
117 test_must_fail git push origin dev2 2>act &&
118 sed -e "/^remote: /s/ *$//" <act >cmp &&
119 test_i18ncmp exp cmp
121 rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
123 cat >exp <<EOF
124 GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
125 POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
126 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
127 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
128 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
129 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
130 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
131 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
132 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
133 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
134 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
136 test_expect_success 'used receive-pack service' '
137 sed -e "
138 s/^.* \"//
139 s/\"//
140 s/ [1-9][0-9]*\$//
141 s/^GET /GET /
142 " >act <"$HTTPD_ROOT_PATH"/access.log &&
143 test_cmp exp act
146 test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
147 "$ROOT_PATH"/test_repo_clone master success
149 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
150 # create a dissimilarly-named remote ref so that git is unable to match the
151 # two refs (viz. local, remote) unless an explicit refspec is provided.
152 git push origin master:retsam &&
154 echo "change changed" > path2 &&
155 git commit -a -m path2 --amend &&
157 # push master too; this ensures there is at least one '"'push'"' command to
158 # the remote helper and triggers interaction with the helper.
159 test_must_fail git push -v origin +master master:retsam >output 2>&1'
161 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: remote output' '
162 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
163 grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output
166 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: our output' '
167 test_i18ngrep "Updates were rejected because" \
168 output
171 test_expect_success 'push (chunked)' '
172 git checkout master &&
173 test_commit commit path3 &&
174 HEAD=$(git rev-parse --verify HEAD) &&
175 test_config http.postbuffer 4 &&
176 git push -v -v origin $BRANCH 2>err &&
177 grep "POST git-receive-pack (chunked)" err &&
178 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
179 test $HEAD = $(git rev-parse --verify HEAD))
182 test_expect_success 'push --all can push to empty repo' '
183 d=$HTTPD_DOCUMENT_ROOT_PATH/empty-all.git &&
184 git init --bare "$d" &&
185 git --git-dir="$d" config http.receivepack true &&
186 git push --all "$HTTPD_URL"/smart/empty-all.git
189 test_expect_success 'push --mirror can push to empty repo' '
190 d=$HTTPD_DOCUMENT_ROOT_PATH/empty-mirror.git &&
191 git init --bare "$d" &&
192 git --git-dir="$d" config http.receivepack true &&
193 git push --mirror "$HTTPD_URL"/smart/empty-mirror.git
196 test_expect_success 'push --all to repo with alternates' '
197 s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
198 d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-all.git &&
199 git clone --bare --shared "$s" "$d" &&
200 git --git-dir="$d" config http.receivepack true &&
201 git --git-dir="$d" repack -adl &&
202 git push --all "$HTTPD_URL"/smart/alternates-all.git
205 test_expect_success 'push --mirror to repo with alternates' '
206 s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
207 d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-mirror.git &&
208 git clone --bare --shared "$s" "$d" &&
209 git --git-dir="$d" config http.receivepack true &&
210 git --git-dir="$d" repack -adl &&
211 git push --mirror "$HTTPD_URL"/smart/alternates-mirror.git
214 test_expect_success TTY 'push shows progress when stderr is a tty' '
215 cd "$ROOT_PATH"/test_repo_clone &&
216 test_commit noisy &&
217 test_terminal git push >output 2>&1 &&
218 test_i18ngrep "^Writing objects" output
221 test_expect_success TTY 'push --quiet silences status and progress' '
222 cd "$ROOT_PATH"/test_repo_clone &&
223 test_commit quiet &&
224 test_terminal git push --quiet >output 2>&1 &&
225 test_cmp /dev/null output
228 test_expect_success TTY 'push --no-progress silences progress but not status' '
229 cd "$ROOT_PATH"/test_repo_clone &&
230 test_commit no-progress &&
231 test_terminal git push --no-progress >output 2>&1 &&
232 test_i18ngrep "^To http" output &&
233 test_i18ngrep ! "^Writing objects"
236 test_expect_success 'push --progress shows progress to non-tty' '
237 cd "$ROOT_PATH"/test_repo_clone &&
238 test_commit progress &&
239 git push --progress >output 2>&1 &&
240 test_i18ngrep "^To http" output &&
241 test_i18ngrep "^Writing objects" output
244 test_expect_success 'http push gives sane defaults to reflog' '
245 cd "$ROOT_PATH"/test_repo_clone &&
246 test_commit reflog-test &&
247 git push "$HTTPD_URL"/smart/test_repo.git &&
248 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
249 log -g -1 --format="%gn <%ge>" >actual &&
250 echo "anonymous <anonymous@http.127.0.0.1>" >expect &&
251 test_cmp expect actual
254 test_expect_success 'http push respects GIT_COMMITTER_* in reflog' '
255 cd "$ROOT_PATH"/test_repo_clone &&
256 test_commit custom-reflog-test &&
257 git push "$HTTPD_URL"/smart_custom_env/test_repo.git &&
258 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
259 log -g -1 --format="%gn <%ge>" >actual &&
260 echo "Custom User <custom@example.com>" >expect &&
261 test_cmp expect actual
264 test_expect_success 'push over smart http with auth' '
265 cd "$ROOT_PATH/test_repo_clone" &&
266 echo push-auth-test >expect &&
267 test_commit push-auth-test &&
268 set_askpass user@host pass@host &&
269 git push "$HTTPD_URL"/auth/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
276 test_expect_success 'push to auth-only-for-push repo' '
277 cd "$ROOT_PATH/test_repo_clone" &&
278 echo push-half-auth >expect &&
279 test_commit push-half-auth &&
280 set_askpass user@host pass@host &&
281 git push "$HTTPD_URL"/auth-push/smart/test_repo.git &&
282 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
283 log -1 --format=%s >actual &&
284 expect_askpass both user@host &&
285 test_cmp expect actual
288 test_expect_success 'create repo without http.receivepack set' '
289 cd "$ROOT_PATH" &&
290 git init half-auth &&
292 cd half-auth &&
293 test_commit one
294 ) &&
295 git clone --bare half-auth "$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git"
298 test_expect_success 'clone via half-auth-complete does not need password' '
299 cd "$ROOT_PATH" &&
300 set_askpass wrong &&
301 git clone "$HTTPD_URL"/half-auth-complete/smart/half-auth.git \
302 half-auth-clone &&
303 expect_askpass none
306 test_expect_success 'push into half-auth-complete requires password' '
307 cd "$ROOT_PATH/half-auth-clone" &&
308 echo two >expect &&
309 test_commit two &&
310 set_askpass user@host pass@host &&
311 git push "$HTTPD_URL/half-auth-complete/smart/half-auth.git" &&
312 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git" \
313 log -1 --format=%s >actual &&
314 expect_askpass both user@host &&
315 test_cmp expect actual
318 test_expect_success CMDLINE_LIMIT 'push 2000 tags over http' '
319 sha1=$(git rev-parse HEAD) &&
320 test_seq 2000 |
321 sort |
322 sed "s|.*|$sha1 refs/tags/really-long-tag-name-&|" \
323 >.git/packed-refs &&
324 run_with_limited_cmdline git push --mirror
327 test_expect_success GPG 'push with post-receive to inspect certificate' '
329 cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
330 mkdir -p hooks &&
331 write_script hooks/post-receive <<-\EOF &&
332 # discard the update list
333 cat >/dev/null
334 # record the push certificate
335 if test -n "${GIT_PUSH_CERT-}"
336 then
337 git cat-file blob $GIT_PUSH_CERT >../push-cert
338 fi &&
339 cat >../push-cert-status <<E_O_F
340 SIGNER=${GIT_PUSH_CERT_SIGNER-nobody}
341 KEY=${GIT_PUSH_CERT_KEY-nokey}
342 STATUS=${GIT_PUSH_CERT_STATUS-nostatus}
343 NONCE_STATUS=${GIT_PUSH_CERT_NONCE_STATUS-nononcestatus}
344 NONCE=${GIT_PUSH_CERT_NONCE-nononce}
345 E_O_F
348 git config receive.certnonceseed sekrit &&
349 git config receive.certnonceslop 30
350 ) &&
351 cd "$ROOT_PATH/test_repo_clone" &&
352 test_commit cert-test &&
353 git push --signed "$HTTPD_URL/smart/test_repo.git" &&
355 cd "$HTTPD_DOCUMENT_ROOT_PATH" &&
356 cat <<-\EOF &&
357 SIGNER=C O Mitter <committer@example.com>
358 KEY=13B6F51ECDDE430D
359 STATUS=G
360 NONCE_STATUS=OK
362 sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" push-cert
363 ) >expect &&
364 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH/push-cert-status"
367 test_expect_success 'push status output scrubs password' '
368 cd "$ROOT_PATH/test_repo_clone" &&
369 git push --porcelain \
370 "$HTTPD_URL_USER_PASS/smart/test_repo.git" \
371 +HEAD:scrub >status &&
372 # should have been scrubbed down to vanilla URL
373 grep "^To $HTTPD_URL/smart/test_repo.git" status
376 stop_httpd
377 test_done