3 # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
6 test_description='test smart pushing over http via http-backend'
10 . "$TEST_DIRECTORY"/lib-gpg.sh
11 . "$TEST_DIRECTORY"/lib-httpd.sh
12 . "$TEST_DIRECTORY"/lib-terminal.sh
15 test_expect_success 'setup remote repository' '
23 git commit -m initial &&
25 git clone --bare test_repo test_repo.git &&
27 git config http.receivepack true &&
28 git config core.logallrefupdates true &&
29 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
31 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
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
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
48 git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
53 test_expect_success 'clone remote repository' '
54 rm -rf test_repo_clone &&
55 git clone $HTTPD_URL/smart/test_repo.git test_repo_clone &&
57 cd test_repo_clone && git config push.default matching
61 test_expect_success 'push to remote repository (standard)' '
62 cd "$ROOT_PATH"/test_repo_clone &&
66 git commit -m path2 &&
67 HEAD=$(git rev-parse --verify HEAD) &&
68 GIT_TRACE_CURL=true git push -v -v 2>err &&
69 ! grep "Expect: 100-continue" err &&
70 grep "POST git-receive-pack ([0-9]* bytes)" err &&
71 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
72 test $HEAD = $(git rev-parse --verify HEAD))
75 test_expect_success 'push already up-to-date' '
79 test_expect_success 'create and delete remote branch' '
80 cd "$ROOT_PATH"/test_repo_clone &&
81 git checkout -b dev &&
86 git push origin dev &&
87 git push origin :dev &&
88 test_must_fail git show-ref --verify refs/remotes/origin/dev
91 cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<EOF
95 chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
98 remote: error: hook declined to update refs/heads/dev2
99 To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
100 ! [remote rejected] dev2 -> dev2 (hook declined)
101 error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'
104 test_expect_success 'rejected update prints status' '
105 cd "$ROOT_PATH"/test_repo_clone &&
106 git checkout -b dev2 &&
110 git commit -m dev2 &&
111 test_must_fail git push origin dev2 2>act &&
112 sed -e "/^remote: /s/ *$//" <act >cmp &&
115 rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
118 GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
119 POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
120 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
121 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
122 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
123 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
124 POST /smart/test_repo.git/git-receive-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 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
130 test_expect_success 'used receive-pack service' '
134 test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
135 "$ROOT_PATH"/test_repo_clone master success
137 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
138 # create a dissimilarly-named remote ref so that git is unable to match the
139 # two refs (viz. local, remote) unless an explicit refspec is provided.
140 git push origin master:retsam &&
142 echo "change changed" > path2 &&
143 git commit -a -m path2 --amend &&
145 # push master too; this ensures there is at least one '"'push'"' command to
146 # the remote helper and triggers interaction with the helper.
147 test_must_fail git push -v origin +master master:retsam >output 2>&1'
149 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: remote output' '
150 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
151 grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output
154 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: our output' '
155 test_i18ngrep "Updates were rejected because" \
159 test_expect_success 'push (chunked)' '
160 git checkout master &&
161 test_commit commit path3 &&
162 HEAD=$(git rev-parse --verify HEAD) &&
163 test_config http.postbuffer 4 &&
164 git push -v -v origin $BRANCH 2>err &&
165 grep "POST git-receive-pack (chunked)" err &&
166 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
167 test $HEAD = $(git rev-parse --verify HEAD))
170 test_expect_success 'push --all can push to empty repo' '
171 d=$HTTPD_DOCUMENT_ROOT_PATH/empty-all.git &&
172 git init --bare "$d" &&
173 git --git-dir="$d" config http.receivepack true &&
174 git push --all "$HTTPD_URL"/smart/empty-all.git
177 test_expect_success 'push --mirror can push to empty repo' '
178 d=$HTTPD_DOCUMENT_ROOT_PATH/empty-mirror.git &&
179 git init --bare "$d" &&
180 git --git-dir="$d" config http.receivepack true &&
181 git push --mirror "$HTTPD_URL"/smart/empty-mirror.git
184 test_expect_success 'push --all to repo with alternates' '
185 s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
186 d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-all.git &&
187 git clone --bare --shared "$s" "$d" &&
188 git --git-dir="$d" config http.receivepack true &&
189 git --git-dir="$d" repack -adl &&
190 git push --all "$HTTPD_URL"/smart/alternates-all.git
193 test_expect_success 'push --mirror to repo with alternates' '
194 s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
195 d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-mirror.git &&
196 git clone --bare --shared "$s" "$d" &&
197 git --git-dir="$d" config http.receivepack true &&
198 git --git-dir="$d" repack -adl &&
199 git push --mirror "$HTTPD_URL"/smart/alternates-mirror.git
202 test_expect_success TTY 'push shows progress when stderr is a tty' '
203 cd "$ROOT_PATH"/test_repo_clone &&
205 test_terminal git push >output 2>&1 &&
206 test_i18ngrep "^Writing objects" output
209 test_expect_success TTY 'push --quiet silences status and progress' '
210 cd "$ROOT_PATH"/test_repo_clone &&
212 test_terminal git push --quiet >output 2>&1 &&
213 test_must_be_empty output
216 test_expect_success TTY 'push --no-progress silences progress but not status' '
217 cd "$ROOT_PATH"/test_repo_clone &&
218 test_commit no-progress &&
219 test_terminal git push --no-progress >output 2>&1 &&
220 test_i18ngrep "^To http" output &&
221 test_i18ngrep ! "^Writing objects" output
224 test_expect_success 'push --progress shows progress to non-tty' '
225 cd "$ROOT_PATH"/test_repo_clone &&
226 test_commit progress &&
227 git push --progress >output 2>&1 &&
228 test_i18ngrep "^To http" output &&
229 test_i18ngrep "^Writing objects" output
232 test_expect_success 'http push gives sane defaults to reflog' '
233 cd "$ROOT_PATH"/test_repo_clone &&
234 test_commit reflog-test &&
235 git push "$HTTPD_URL"/smart/test_repo.git &&
236 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
237 log -g -1 --format="%gn <%ge>" >actual &&
238 echo "anonymous <anonymous@http.127.0.0.1>" >expect &&
239 test_cmp expect actual
242 test_expect_success 'http push respects GIT_COMMITTER_* in reflog' '
243 cd "$ROOT_PATH"/test_repo_clone &&
244 test_commit custom-reflog-test &&
245 git push "$HTTPD_URL"/smart_custom_env/test_repo.git &&
246 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
247 log -g -1 --format="%gn <%ge>" >actual &&
248 echo "Custom User <custom@example.com>" >expect &&
249 test_cmp expect actual
252 test_expect_success 'push over smart http with auth' '
253 cd "$ROOT_PATH/test_repo_clone" &&
254 echo push-auth-test >expect &&
255 test_commit push-auth-test &&
256 set_askpass user@host pass@host &&
257 git push "$HTTPD_URL"/auth/smart/test_repo.git &&
258 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
259 log -1 --format=%s >actual &&
260 expect_askpass both user@host &&
261 test_cmp expect actual
264 test_expect_success 'push to auth-only-for-push repo' '
265 cd "$ROOT_PATH/test_repo_clone" &&
266 echo push-half-auth >expect &&
267 test_commit push-half-auth &&
268 set_askpass user@host pass@host &&
269 git push "$HTTPD_URL"/auth-push/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 'create repo without http.receivepack set' '
278 git init half-auth &&
283 git clone --bare half-auth "$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git"
286 test_expect_success 'clone via half-auth-complete does not need password' '
289 git clone "$HTTPD_URL"/half-auth-complete/smart/half-auth.git \
294 test_expect_success 'push into half-auth-complete requires password' '
295 cd "$ROOT_PATH/half-auth-clone" &&
298 set_askpass user@host pass@host &&
299 git push "$HTTPD_URL/half-auth-complete/smart/half-auth.git" &&
300 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git" \
301 log -1 --format=%s >actual &&
302 expect_askpass both user@host &&
303 test_cmp expect actual
306 test_expect_success CMDLINE_LIMIT 'push 2000 tags over http' '
307 sha1=$(git rev-parse HEAD) &&
310 sed "s|.*|$sha1 refs/tags/really-long-tag-name-&|" \
312 run_with_limited_cmdline git push --mirror
315 test_expect_success GPG 'push with post-receive to inspect certificate' '
317 cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
319 write_script hooks/post-receive <<-\EOF &&
320 # discard the update list
322 # record the push certificate
323 if test -n "${GIT_PUSH_CERT-}"
325 git cat-file blob $GIT_PUSH_CERT >../push-cert
327 cat >../push-cert-status <<E_O_F
328 SIGNER=${GIT_PUSH_CERT_SIGNER-nobody}
329 KEY=${GIT_PUSH_CERT_KEY-nokey}
330 STATUS=${GIT_PUSH_CERT_STATUS-nostatus}
331 NONCE_STATUS=${GIT_PUSH_CERT_NONCE_STATUS-nononcestatus}
332 NONCE=${GIT_PUSH_CERT_NONCE-nononce}
336 git config receive.certnonceseed sekrit &&
337 git config receive.certnonceslop 30
339 cd "$ROOT_PATH/test_repo_clone" &&
340 test_commit cert-test &&
341 git push --signed "$HTTPD_URL/smart/test_repo.git" &&
343 cd "$HTTPD_DOCUMENT_ROOT_PATH" &&
345 SIGNER=C O Mitter <committer@example.com>
350 sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" push-cert
352 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH/push-cert-status"
355 test_expect_success 'push status output scrubs password' '
356 cd "$ROOT_PATH/test_repo_clone" &&
357 git push --porcelain \
358 "$HTTPD_URL_USER_PASS/smart/test_repo.git" \
359 +HEAD:scrub >status &&
360 # should have been scrubbed down to vanilla URL
361 grep "^To $HTTPD_URL/smart/test_repo.git" status
364 test_expect_success 'colorize errors/hints' '
365 cd "$ROOT_PATH"/test_repo_clone &&
366 test_must_fail git -c color.transport=always -c color.advice=always \
367 -c color.push=always \
368 push origin origin/master^:master 2>act &&
369 test_decode_color <act >decoded &&
370 test_i18ngrep "<RED>.*rejected.*<RESET>" decoded &&
371 test_i18ngrep "<RED>error: failed to push some refs" decoded &&
372 test_i18ngrep "<YELLOW>hint: " decoded &&
373 test_i18ngrep ! "^hint: " decoded