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 &&
50 strip_access_log >act &&
54 test_expect_success 'clone remote repository' '
55 rm -rf test_repo_clone &&
56 git clone $HTTPD_URL/smart/test_repo.git test_repo_clone &&
58 cd test_repo_clone && git config push.default matching
62 test_expect_success 'push to remote repository (standard)' '
63 cd "$ROOT_PATH"/test_repo_clone &&
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))
76 test_expect_success 'push already up-to-date' '
80 test_expect_success 'create and delete remote branch' '
81 cd "$ROOT_PATH"/test_repo_clone &&
82 git checkout -b dev &&
87 git push origin dev &&
88 git push origin :dev &&
89 test_must_fail git show-ref --verify refs/remotes/origin/dev
92 cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<EOF
96 chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
99 remote: error: hook declined to update refs/heads/dev2
100 To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
101 ! [remote rejected] dev2 -> dev2 (hook declined)
102 error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'
105 test_expect_success 'rejected update prints status' '
106 cd "$ROOT_PATH"/test_repo_clone &&
107 git checkout -b dev2 &&
111 git commit -m dev2 &&
112 test_must_fail git push origin dev2 2>act &&
113 sed -e "/^remote: /s/ *$//" <act >cmp &&
116 rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
119 GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
120 POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
121 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
122 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
123 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
124 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
125 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
126 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
127 POST /smart/test_repo.git/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
131 test_expect_success 'used receive-pack service' '
132 strip_access_log >act &&
136 test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
137 "$ROOT_PATH"/test_repo_clone master success
139 test_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 &&
144 echo "change changed" > path2 &&
145 git commit -a -m path2 --amend &&
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'
151 test_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
156 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: our output' '
157 test_i18ngrep "Updates were rejected because" \
161 test_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))
172 test_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
179 test_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
186 test_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
195 test_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
204 test_expect_success TTY 'push shows progress when stderr is a tty' '
205 cd "$ROOT_PATH"/test_repo_clone &&
207 test_terminal git push >output 2>&1 &&
208 test_i18ngrep "^Writing objects" output
211 test_expect_success TTY 'push --quiet silences status and progress' '
212 cd "$ROOT_PATH"/test_repo_clone &&
214 test_terminal git push --quiet >output 2>&1 &&
215 test_cmp /dev/null output
218 test_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"
226 test_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
234 test_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
244 test_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
254 test_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
266 test_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
278 test_expect_success 'create repo without http.receivepack set' '
280 git init half-auth &&
285 git clone --bare half-auth "$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git"
288 test_expect_success 'clone via half-auth-complete does not need password' '
291 git clone "$HTTPD_URL"/half-auth-complete/smart/half-auth.git \
296 test_expect_success 'push into half-auth-complete requires password' '
297 cd "$ROOT_PATH/half-auth-clone" &&
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
308 test_expect_success CMDLINE_LIMIT 'push 2000 tags over http' '
309 sha1=$(git rev-parse HEAD) &&
312 sed "s|.*|$sha1 refs/tags/really-long-tag-name-&|" \
314 run_with_limited_cmdline git push --mirror
317 test_expect_success GPG 'push with post-receive to inspect certificate' '
319 cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
321 write_script hooks/post-receive <<-\EOF &&
322 # discard the update list
324 # record the push certificate
325 if test -n "${GIT_PUSH_CERT-}"
327 git cat-file blob $GIT_PUSH_CERT >../push-cert
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}
338 git config receive.certnonceseed sekrit &&
339 git config receive.certnonceslop 30
341 cd "$ROOT_PATH/test_repo_clone" &&
342 test_commit cert-test &&
343 git push --signed "$HTTPD_URL/smart/test_repo.git" &&
345 cd "$HTTPD_DOCUMENT_ROOT_PATH" &&
347 SIGNER=C O Mitter <committer@example.com>
352 sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" push-cert
354 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH/push-cert-status"
357 test_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