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