]>
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' ' |
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 | ||
58 | test_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 | 66 | test_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 | ||
80 | test_expect_success 'push already up-to-date' ' | |
81 | git push | |
82 | ' | |
83 | ||
84 | test_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 |
96 | cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<EOF |
97 | #!/bin/sh | |
98 | exit 1 | |
99 | EOF | |
100 | chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" | |
101 | ||
102 | cat >exp <<EOF | |
103 | remote: error: hook declined to update refs/heads/dev2 | |
104 | To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git | |
105 | ! [remote rejected] dev2 -> dev2 (hook declined) | |
d202a513 | 106 | error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git' |
5238cbf6 SP |
107 | EOF |
108 | ||
109 | test_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 | ' |
120 | rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" | |
121 | ||
7da4e228 SP |
122 | cat >exp <<EOF |
123 | GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200 | |
124 | POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200 | |
125 | GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 | |
126 | POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200 | |
127 | GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 | |
128 | GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 | |
129 | POST /smart/test_repo.git/git-receive-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 | |
5238cbf6 SP |
132 | GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 |
133 | POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200 | |
7da4e228 SP |
134 | EOF |
135 | test_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 | 144 | test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ |
05c1eb10 | 145 | "$ROOT_PATH"/test_repo_clone master success |
19452374 | 146 | |
08d63a42 | 147 | test_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 | 159 | test_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 | 164 | test_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 |
169 | test_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 | ||
02f79147 JK |
180 | test_expect_success 'push --all can push to empty repo' ' |
181 | d=$HTTPD_DOCUMENT_ROOT_PATH/empty-all.git && | |
182 | git init --bare "$d" && | |
183 | git --git-dir="$d" config http.receivepack true && | |
184 | git push --all "$HTTPD_URL"/smart/empty-all.git | |
185 | ' | |
186 | ||
187 | test_expect_success 'push --mirror can push to empty repo' ' | |
188 | d=$HTTPD_DOCUMENT_ROOT_PATH/empty-mirror.git && | |
189 | git init --bare "$d" && | |
190 | git --git-dir="$d" config http.receivepack true && | |
191 | git push --mirror "$HTTPD_URL"/smart/empty-mirror.git | |
192 | ' | |
193 | ||
194 | test_expect_success 'push --all to repo with alternates' ' | |
195 | s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git && | |
196 | d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-all.git && | |
197 | git clone --bare --shared "$s" "$d" && | |
198 | git --git-dir="$d" config http.receivepack true && | |
199 | git --git-dir="$d" repack -adl && | |
200 | git push --all "$HTTPD_URL"/smart/alternates-all.git | |
201 | ' | |
202 | ||
203 | test_expect_success 'push --mirror to repo with alternates' ' | |
204 | s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git && | |
205 | d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-mirror.git && | |
206 | git clone --bare --shared "$s" "$d" && | |
207 | git --git-dir="$d" config http.receivepack true && | |
208 | git --git-dir="$d" repack -adl && | |
209 | git push --mirror "$HTTPD_URL"/smart/alternates-mirror.git | |
210 | ' | |
211 | ||
e304aeba JK |
212 | test_expect_success TTY 'push shows progress when stderr is a tty' ' |
213 | cd "$ROOT_PATH"/test_repo_clone && | |
214 | test_commit noisy && | |
215 | test_terminal git push >output 2>&1 && | |
415c7dd0 | 216 | test_i18ngrep "^Writing objects" output |
e304aeba JK |
217 | ' |
218 | ||
219 | test_expect_success TTY 'push --quiet silences status and progress' ' | |
c207e34f CB |
220 | cd "$ROOT_PATH"/test_repo_clone && |
221 | test_commit quiet && | |
e304aeba | 222 | test_terminal git push --quiet >output 2>&1 && |
ec21ac8c | 223 | test_must_be_empty output |
c207e34f CB |
224 | ' |
225 | ||
e304aeba JK |
226 | test_expect_success TTY 'push --no-progress silences progress but not status' ' |
227 | cd "$ROOT_PATH"/test_repo_clone && | |
228 | test_commit no-progress && | |
229 | test_terminal git push --no-progress >output 2>&1 && | |
415c7dd0 | 230 | test_i18ngrep "^To http" output && |
8cdef01c | 231 | test_i18ngrep ! "^Writing objects" output |
e304aeba JK |
232 | ' |
233 | ||
234 | test_expect_success 'push --progress shows progress to non-tty' ' | |
235 | cd "$ROOT_PATH"/test_repo_clone && | |
236 | test_commit progress && | |
237 | git push --progress >output 2>&1 && | |
415c7dd0 VA |
238 | test_i18ngrep "^To http" output && |
239 | test_i18ngrep "^Writing objects" output | |
e304aeba JK |
240 | ' |
241 | ||
e32a4581 JK |
242 | test_expect_success 'http push gives sane defaults to reflog' ' |
243 | cd "$ROOT_PATH"/test_repo_clone && | |
244 | test_commit reflog-test && | |
245 | git push "$HTTPD_URL"/smart/test_repo.git && | |
246 | git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \ | |
247 | log -g -1 --format="%gn <%ge>" >actual && | |
248 | echo "anonymous <anonymous@http.127.0.0.1>" >expect && | |
249 | test_cmp expect actual | |
250 | ' | |
251 | ||
252 | test_expect_success 'http push respects GIT_COMMITTER_* in reflog' ' | |
253 | cd "$ROOT_PATH"/test_repo_clone && | |
254 | test_commit custom-reflog-test && | |
255 | git push "$HTTPD_URL"/smart_custom_env/test_repo.git && | |
256 | git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \ | |
257 | log -g -1 --format="%gn <%ge>" >actual && | |
258 | echo "Custom User <custom@example.com>" >expect && | |
259 | test_cmp expect actual | |
260 | ' | |
261 | ||
6ac2b3ae JK |
262 | test_expect_success 'push over smart http with auth' ' |
263 | cd "$ROOT_PATH/test_repo_clone" && | |
264 | echo push-auth-test >expect && | |
265 | test_commit push-auth-test && | |
afbf5ca5 | 266 | set_askpass user@host pass@host && |
6ac2b3ae JK |
267 | git push "$HTTPD_URL"/auth/smart/test_repo.git && |
268 | git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \ | |
269 | log -1 --format=%s >actual && | |
270 | expect_askpass both user@host && | |
271 | test_cmp expect actual | |
272 | ' | |
273 | ||
b81401c1 | 274 | test_expect_success 'push to auth-only-for-push repo' ' |
4c71009d JK |
275 | cd "$ROOT_PATH/test_repo_clone" && |
276 | echo push-half-auth >expect && | |
277 | test_commit push-half-auth && | |
afbf5ca5 | 278 | set_askpass user@host pass@host && |
4c71009d JK |
279 | git push "$HTTPD_URL"/auth-push/smart/test_repo.git && |
280 | git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \ | |
281 | log -1 --format=%s >actual && | |
282 | expect_askpass both user@host && | |
283 | test_cmp expect actual | |
284 | ' | |
285 | ||
b0808819 JK |
286 | test_expect_success 'create repo without http.receivepack set' ' |
287 | cd "$ROOT_PATH" && | |
288 | git init half-auth && | |
289 | ( | |
290 | cd half-auth && | |
291 | test_commit one | |
292 | ) && | |
293 | git clone --bare half-auth "$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git" | |
294 | ' | |
295 | ||
296 | test_expect_success 'clone via half-auth-complete does not need password' ' | |
297 | cd "$ROOT_PATH" && | |
298 | set_askpass wrong && | |
299 | git clone "$HTTPD_URL"/half-auth-complete/smart/half-auth.git \ | |
300 | half-auth-clone && | |
301 | expect_askpass none | |
302 | ' | |
303 | ||
304 | test_expect_success 'push into half-auth-complete requires password' ' | |
305 | cd "$ROOT_PATH/half-auth-clone" && | |
306 | echo two >expect && | |
307 | test_commit two && | |
afbf5ca5 | 308 | set_askpass user@host pass@host && |
b0808819 JK |
309 | git push "$HTTPD_URL/half-auth-complete/smart/half-auth.git" && |
310 | git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git" \ | |
311 | log -1 --format=%s >actual && | |
312 | expect_askpass both user@host && | |
313 | test_cmp expect actual | |
314 | ' | |
315 | ||
26be19ba JK |
316 | test_expect_success CMDLINE_LIMIT 'push 2000 tags over http' ' |
317 | sha1=$(git rev-parse HEAD) && | |
318 | test_seq 2000 | | |
319 | sort | | |
320 | sed "s|.*|$sha1 refs/tags/really-long-tag-name-&|" \ | |
321 | >.git/packed-refs && | |
322 | run_with_limited_cmdline git push --mirror | |
323 | ' | |
324 | ||
0ea47f9d JH |
325 | test_expect_success GPG 'push with post-receive to inspect certificate' ' |
326 | ( | |
327 | cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && | |
328 | mkdir -p hooks && | |
329 | write_script hooks/post-receive <<-\EOF && | |
330 | # discard the update list | |
331 | cat >/dev/null | |
332 | # record the push certificate | |
333 | if test -n "${GIT_PUSH_CERT-}" | |
334 | then | |
335 | git cat-file blob $GIT_PUSH_CERT >../push-cert | |
336 | fi && | |
337 | cat >../push-cert-status <<E_O_F | |
338 | SIGNER=${GIT_PUSH_CERT_SIGNER-nobody} | |
339 | KEY=${GIT_PUSH_CERT_KEY-nokey} | |
340 | STATUS=${GIT_PUSH_CERT_STATUS-nostatus} | |
5732373d JH |
341 | NONCE_STATUS=${GIT_PUSH_CERT_NONCE_STATUS-nononcestatus} |
342 | NONCE=${GIT_PUSH_CERT_NONCE-nononce} | |
0ea47f9d JH |
343 | E_O_F |
344 | EOF | |
345 | ||
5732373d JH |
346 | git config receive.certnonceseed sekrit && |
347 | git config receive.certnonceslop 30 | |
0ea47f9d JH |
348 | ) && |
349 | cd "$ROOT_PATH/test_repo_clone" && | |
350 | test_commit cert-test && | |
351 | git push --signed "$HTTPD_URL/smart/test_repo.git" && | |
352 | ( | |
353 | cd "$HTTPD_DOCUMENT_ROOT_PATH" && | |
5732373d | 354 | cat <<-\EOF && |
0ea47f9d JH |
355 | SIGNER=C O Mitter <committer@example.com> |
356 | KEY=13B6F51ECDDE430D | |
357 | STATUS=G | |
5732373d | 358 | NONCE_STATUS=OK |
0ea47f9d | 359 | EOF |
5732373d | 360 | sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" push-cert |
0ea47f9d JH |
361 | ) >expect && |
362 | test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH/push-cert-status" | |
363 | ' | |
364 | ||
882d49ca | 365 | test_expect_success 'push status output scrubs password' ' |
68f3c079 JK |
366 | cd "$ROOT_PATH/test_repo_clone" && |
367 | git push --porcelain \ | |
368 | "$HTTPD_URL_USER_PASS/smart/test_repo.git" \ | |
369 | +HEAD:scrub >status && | |
882d49ca JK |
370 | # should have been scrubbed down to vanilla URL |
371 | grep "^To $HTTPD_URL/smart/test_repo.git" status | |
372 | ' | |
373 | ||
8301266a JS |
374 | test_expect_success 'colorize errors/hints' ' |
375 | cd "$ROOT_PATH"/test_repo_clone && | |
376 | test_must_fail git -c color.transport=always -c color.advice=always \ | |
377 | -c color.push=always \ | |
378 | push origin origin/master^:master 2>act && | |
379 | test_decode_color <act >decoded && | |
380 | test_i18ngrep "<RED>.*rejected.*<RESET>" decoded && | |
381 | test_i18ngrep "<RED>error: failed to push some refs" decoded && | |
382 | test_i18ngrep "<YELLOW>hint: " decoded && | |
383 | test_i18ngrep ! "^hint: " decoded | |
384 | ' | |
385 | ||
7da4e228 | 386 | test_done |