3 # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
6 test_description='test smart pushing over http via http-backend'
9 if test -n "$NO_CURL"; then
10 skip_all='skipping test, git built without http support'
15 . "$TEST_DIRECTORY"/lib-gpg.sh
16 . "$TEST_DIRECTORY"/lib-httpd.sh
17 . "$TEST_DIRECTORY"/lib-terminal.sh
20 test_expect_success 'setup remote repository' '
28 git commit -m initial &&
30 git clone --bare test_repo test_repo.git &&
32 git config http.receivepack true &&
33 git config core.logallrefupdates true &&
34 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
36 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
42 GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
43 POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
45 test_expect_success 'no empty path components' '
46 # In the URL, add a trailing slash, and see if git appends yet another
49 git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
56 " >act <"$HTTPD_ROOT_PATH"/access.log &&
58 # Clear the log, so that it does not affect the "used receive-pack
59 # service" test which reads the log too.
61 # We do this before the actual comparison to ensure the log is cleared.
62 echo > "$HTTPD_ROOT_PATH"/access.log &&
67 test_expect_success 'clone remote repository' '
68 rm -rf test_repo_clone &&
69 git clone $HTTPD_URL/smart/test_repo.git test_repo_clone &&
71 cd test_repo_clone && git config push.default matching
75 test_expect_success 'push to remote repository (standard)' '
76 cd "$ROOT_PATH"/test_repo_clone &&
80 git commit -m path2 &&
81 HEAD=$(git rev-parse --verify HEAD) &&
82 GIT_CURL_VERBOSE=1 git push -v -v 2>err &&
83 ! grep "Expect: 100-continue" err &&
84 grep "POST git-receive-pack ([0-9]* bytes)" err &&
85 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
86 test $HEAD = $(git rev-parse --verify HEAD))
89 test_expect_success 'push already up-to-date' '
93 test_expect_success 'create and delete remote branch' '
94 cd "$ROOT_PATH"/test_repo_clone &&
95 git checkout -b dev &&
100 git push origin dev &&
101 git push origin :dev &&
102 test_must_fail git show-ref --verify refs/remotes/origin/dev
105 cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<EOF
109 chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
112 remote: error: hook declined to update refs/heads/dev2
113 To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
114 ! [remote rejected] dev2 -> dev2 (hook declined)
115 error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'
118 test_expect_success 'rejected update prints status' '
119 cd "$ROOT_PATH"/test_repo_clone &&
120 git checkout -b dev2 &&
124 git commit -m dev2 &&
125 test_must_fail git push origin dev2 2>act &&
126 sed -e "/^remote: /s/ *$//" <act >cmp &&
129 rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
133 GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
134 POST /smart/test_repo.git/git-upload-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
137 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
138 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
139 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
140 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
141 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
142 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
143 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
145 test_expect_success 'used receive-pack service' '
151 " >act <"$HTTPD_ROOT_PATH"/access.log &&
155 test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
156 "$ROOT_PATH"/test_repo_clone master success
158 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
159 # create a dissimilarly-named remote ref so that git is unable to match the
160 # two refs (viz. local, remote) unless an explicit refspec is provided.
161 git push origin master:retsam &&
163 echo "change changed" > path2 &&
164 git commit -a -m path2 --amend &&
166 # push master too; this ensures there is at least one '"'push'"' command to
167 # the remote helper and triggers interaction with the helper.
168 test_must_fail git push -v origin +master master:retsam >output 2>&1'
170 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: remote output' '
171 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
172 grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output
175 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: our output' '
176 test_i18ngrep "Updates were rejected because" \
180 test_expect_success 'push (chunked)' '
181 git checkout master &&
182 test_commit commit path3 &&
183 HEAD=$(git rev-parse --verify HEAD) &&
184 test_config http.postbuffer 4 &&
185 git push -v -v origin $BRANCH 2>err &&
186 grep "POST git-receive-pack (chunked)" err &&
187 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
188 test $HEAD = $(git rev-parse --verify HEAD))
191 test_expect_success 'push --all can push to empty repo' '
192 d=$HTTPD_DOCUMENT_ROOT_PATH/empty-all.git &&
193 git init --bare "$d" &&
194 git --git-dir="$d" config http.receivepack true &&
195 git push --all "$HTTPD_URL"/smart/empty-all.git
198 test_expect_success 'push --mirror can push to empty repo' '
199 d=$HTTPD_DOCUMENT_ROOT_PATH/empty-mirror.git &&
200 git init --bare "$d" &&
201 git --git-dir="$d" config http.receivepack true &&
202 git push --mirror "$HTTPD_URL"/smart/empty-mirror.git
205 test_expect_success 'push --all to repo with alternates' '
206 s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
207 d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-all.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 --all "$HTTPD_URL"/smart/alternates-all.git
214 test_expect_success 'push --mirror to repo with alternates' '
215 s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
216 d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-mirror.git &&
217 git clone --bare --shared "$s" "$d" &&
218 git --git-dir="$d" config http.receivepack true &&
219 git --git-dir="$d" repack -adl &&
220 git push --mirror "$HTTPD_URL"/smart/alternates-mirror.git
223 test_expect_success TTY 'push shows progress when stderr is a tty' '
224 cd "$ROOT_PATH"/test_repo_clone &&
226 test_terminal git push >output 2>&1 &&
227 grep "^Writing objects" output
230 test_expect_success TTY 'push --quiet silences status and progress' '
231 cd "$ROOT_PATH"/test_repo_clone &&
233 test_terminal git push --quiet >output 2>&1 &&
234 test_cmp /dev/null output
237 test_expect_success TTY 'push --no-progress silences progress but not status' '
238 cd "$ROOT_PATH"/test_repo_clone &&
239 test_commit no-progress &&
240 test_terminal git push --no-progress >output 2>&1 &&
241 grep "^To http" output &&
242 ! grep "^Writing objects"
245 test_expect_success 'push --progress shows progress to non-tty' '
246 cd "$ROOT_PATH"/test_repo_clone &&
247 test_commit progress &&
248 git push --progress >output 2>&1 &&
249 grep "^To http" output &&
250 grep "^Writing objects" output
253 test_expect_success 'http push gives sane defaults to reflog' '
254 cd "$ROOT_PATH"/test_repo_clone &&
255 test_commit reflog-test &&
256 git push "$HTTPD_URL"/smart/test_repo.git &&
257 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
258 log -g -1 --format="%gn <%ge>" >actual &&
259 echo "anonymous <anonymous@http.127.0.0.1>" >expect &&
260 test_cmp expect actual
263 test_expect_success 'http push respects GIT_COMMITTER_* in reflog' '
264 cd "$ROOT_PATH"/test_repo_clone &&
265 test_commit custom-reflog-test &&
266 git push "$HTTPD_URL"/smart_custom_env/test_repo.git &&
267 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
268 log -g -1 --format="%gn <%ge>" >actual &&
269 echo "Custom User <custom@example.com>" >expect &&
270 test_cmp expect actual
273 test_expect_success 'push over smart http with auth' '
274 cd "$ROOT_PATH/test_repo_clone" &&
275 echo push-auth-test >expect &&
276 test_commit push-auth-test &&
277 set_askpass user@host pass@host &&
278 git push "$HTTPD_URL"/auth/smart/test_repo.git &&
279 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
280 log -1 --format=%s >actual &&
281 expect_askpass both user@host &&
282 test_cmp expect actual
285 test_expect_success 'push to auth-only-for-push repo' '
286 cd "$ROOT_PATH/test_repo_clone" &&
287 echo push-half-auth >expect &&
288 test_commit push-half-auth &&
289 set_askpass user@host pass@host &&
290 git push "$HTTPD_URL"/auth-push/smart/test_repo.git &&
291 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
292 log -1 --format=%s >actual &&
293 expect_askpass both user@host &&
294 test_cmp expect actual
297 test_expect_success 'create repo without http.receivepack set' '
299 git init half-auth &&
304 git clone --bare half-auth "$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git"
307 test_expect_success 'clone via half-auth-complete does not need password' '
310 git clone "$HTTPD_URL"/half-auth-complete/smart/half-auth.git \
315 test_expect_success 'push into half-auth-complete requires password' '
316 cd "$ROOT_PATH/half-auth-clone" &&
319 set_askpass user@host pass@host &&
320 git push "$HTTPD_URL/half-auth-complete/smart/half-auth.git" &&
321 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git" \
322 log -1 --format=%s >actual &&
323 expect_askpass both user@host &&
324 test_cmp expect actual
327 test_expect_success CMDLINE_LIMIT 'push 2000 tags over http' '
328 sha1=$(git rev-parse HEAD) &&
331 sed "s|.*|$sha1 refs/tags/really-long-tag-name-&|" \
333 run_with_limited_cmdline git push --mirror
336 test_expect_success GPG 'push with post-receive to inspect certificate' '
338 cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
340 write_script hooks/post-receive <<-\EOF &&
341 # discard the update list
343 # record the push certificate
344 if test -n "${GIT_PUSH_CERT-}"
346 git cat-file blob $GIT_PUSH_CERT >../push-cert
348 cat >../push-cert-status <<E_O_F
349 SIGNER=${GIT_PUSH_CERT_SIGNER-nobody}
350 KEY=${GIT_PUSH_CERT_KEY-nokey}
351 STATUS=${GIT_PUSH_CERT_STATUS-nostatus}
352 NONCE_STATUS=${GIT_PUSH_CERT_NONCE_STATUS-nononcestatus}
353 NONCE=${GIT_PUSH_CERT_NONCE-nononce}
357 git config receive.certnonceseed sekrit &&
358 git config receive.certnonceslop 30
360 cd "$ROOT_PATH/test_repo_clone" &&
361 test_commit cert-test &&
362 git push --signed "$HTTPD_URL/smart/test_repo.git" &&
364 cd "$HTTPD_DOCUMENT_ROOT_PATH" &&
366 SIGNER=C O Mitter <committer@example.com>
371 sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" push-cert
373 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH/push-cert-status"