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