3 test_description='test dumb fetching over http via static file'
5 . "$TEST_DIRECTORY"/lib-httpd.sh
8 test_expect_success 'setup repository' '
9 git config push.default matching &&
10 echo content1 >file &&
13 echo content2 >file &&
18 test_expect_success 'create http-accessible bare repository with loose objects' '
19 cp -R .git "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
20 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
21 git config core.bare true &&
23 echo "exec git update-server-info" >hooks/post-update &&
24 chmod +x hooks/post-update &&
27 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
28 git push public master:master
31 test_expect_success 'clone http repository' '
32 git clone $HTTPD_URL/dumb/repo.git clone-tmpl &&
33 cp -R clone-tmpl clone &&
34 test_cmp file clone/file
37 test_expect_success 'create password-protected repository' '
38 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" &&
39 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
40 "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git"
45 test_expect_success 'cloning password-protected repository can fail' '
47 test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-fail &&
48 expect_askpass both wrong
51 test_expect_success 'http auth can use user/pass in URL' '
53 git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none &&
57 test_expect_success 'http auth can use just user in URL' '
58 set_askpass wrong pass@host &&
59 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass &&
60 expect_askpass pass user@host
63 test_expect_success 'http auth can request both user and pass' '
64 set_askpass user@host pass@host &&
65 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both &&
66 expect_askpass both user@host
69 test_expect_success 'http auth respects credential helper config' '
70 test_config_global credential.helper "!f() {
72 echo username=user@host
73 echo password=pass@host
76 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
80 test_expect_success 'http auth can get username from config' '
81 test_config_global "credential.$HTTPD_URL.username" user@host &&
82 set_askpass wrong pass@host &&
83 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user &&
84 expect_askpass pass user@host
87 test_expect_success 'configured username does not override URL' '
88 test_config_global "credential.$HTTPD_URL.username" wrong &&
89 set_askpass wrong pass@host &&
90 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 &&
91 expect_askpass pass user@host
94 test_expect_success 'set up repo with http submodules' '
96 set_askpass user@host pass@host &&
99 git submodule add "$HTTPD_URL/auth/dumb/repo.git" sub &&
100 git commit -m "add submodule"
104 test_expect_success 'cmdline credential config passes to submodule via clone' '
105 set_askpass wrong pass@host &&
106 test_must_fail git clone --recursive super super-clone &&
107 rm -rf super-clone &&
109 set_askpass wrong pass@host &&
110 git -c "credential.$HTTPD_URL.username=user@host" \
111 clone --recursive super super-clone &&
112 expect_askpass pass user@host
115 test_expect_success 'cmdline credential config passes submodule update' '
116 # advance the submodule HEAD so that a fetch is required
117 git commit --allow-empty -m foo &&
118 git push "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git" HEAD &&
119 sha1=$(git rev-parse HEAD) &&
120 git -C super-clone update-index --cacheinfo 160000,$sha1,sub &&
122 set_askpass wrong pass@host &&
123 test_must_fail git -C super-clone submodule update &&
125 set_askpass wrong pass@host &&
127 -c "credential.$HTTPD_URL.username=user@host" \
129 expect_askpass pass user@host
132 test_expect_success 'fetch changes via http' '
133 echo content >>file &&
134 git commit -a -m two &&
136 (cd clone && git pull) &&
137 test_cmp file clone/file
140 test_expect_success 'fetch changes via manual http-fetch' '
141 cp -R clone-tmpl clone2 &&
143 HEAD=$(git rev-parse --verify HEAD) &&
145 git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
146 git checkout master-new &&
147 test $HEAD = $(git rev-parse --verify HEAD)) &&
148 test_cmp file clone2/file
151 test_expect_success 'http remote detects correct HEAD' '
152 git push public master:other &&
154 git remote set-head origin -d &&
155 git remote set-head origin -a &&
156 git symbolic-ref refs/remotes/origin/HEAD > output &&
157 echo refs/remotes/origin/master > expect &&
158 test_cmp expect output
162 test_expect_success 'fetch packed objects' '
163 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
164 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
165 git --bare repack -a -d
167 git clone $HTTPD_URL/dumb/repo_pack.git
170 test_expect_success 'fetch notices corrupt pack' '
171 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
172 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
173 p=$(ls objects/pack/pack-*.pack) &&
175 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
177 mkdir repo_bad1.git &&
180 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
181 test 0 = $(ls objects/pack/pack-*.pack | wc -l)
185 test_expect_success 'fetch notices corrupt idx' '
186 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
187 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
188 p=$(ls objects/pack/pack-*.idx) &&
190 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
192 mkdir repo_bad2.git &&
195 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
196 test 0 = $(ls objects/pack | wc -l)
200 test_expect_success 'fetch can handle previously-fetched .idx files' '
201 git checkout --orphan branch1 &&
204 git commit -m base &&
205 git --bare init "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git &&
206 git push "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git branch1 &&
207 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git repack -d &&
208 git checkout -b branch2 branch1 &&
210 git commit -a -m b2 &&
211 git push "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git branch2 &&
212 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git repack -d &&
213 git --bare init clone_packed_branches.git &&
214 git --git-dir=clone_packed_branches.git fetch "$HTTPD_URL"/dumb/repo_packed_branches.git branch1:branch1 &&
215 git --git-dir=clone_packed_branches.git fetch "$HTTPD_URL"/dumb/repo_packed_branches.git branch2:branch2
218 test_expect_success 'did not use upload-pack service' '
219 test_might_fail grep '/git-upload-pack' <"$HTTPD_ROOT_PATH"/access.log >act &&
224 test_expect_success 'git client shows text/plain errors' '
225 test_must_fail git clone "$HTTPD_URL/error/text" 2>stderr &&
226 grep "this is the error message" stderr
229 test_expect_success 'git client does not show html errors' '
230 test_must_fail git clone "$HTTPD_URL/error/html" 2>stderr &&
231 ! grep "this is the error message" stderr
234 test_expect_success 'git client shows text/plain with a charset' '
235 test_must_fail git clone "$HTTPD_URL/error/charset" 2>stderr &&
236 grep "this is the error message" stderr
239 test_expect_success 'http error messages are reencoded' '
240 test_must_fail git clone "$HTTPD_URL/error/utf16" 2>stderr &&
241 grep "this is the error message" stderr
244 test_expect_success 'reencoding is robust to whitespace oddities' '
245 test_must_fail git clone "$HTTPD_URL/error/odd-spacing" 2>stderr &&
246 grep "this is the error message" stderr
255 echo "Accept-Language: $1" >expect
260 git ls-remote "$HTTPD_URL/dumb/repo.git" >output 2>&1 &&
261 tr -d '\015' <output |
263 sed -ne '/^Accept-Language:/ p' >actual &&
264 test_cmp expect actual
267 test_expect_success 'git client sends Accept-Language based on LANGUAGE' '
268 check_language "ko-KR, *;q=0.9" ko_KR.UTF-8'
270 test_expect_success 'git client sends Accept-Language correctly with unordinary LANGUAGE' '
271 check_language "ko-KR, *;q=0.9" "ko_KR:" &&
272 check_language "ko-KR, en-US;q=0.9, *;q=0.8" "ko_KR::en_US" &&
273 check_language "ko-KR, *;q=0.9" ":::ko_KR" &&
274 check_language "ko-KR, en-US;q=0.9, *;q=0.8" "ko_KR!!:en_US" &&
275 check_language "ko-KR, ja-JP;q=0.9, *;q=0.8" "ko_KR en_US:ja_JP"'
277 test_expect_success 'git client sends Accept-Language with many preferred languages' '
278 check_language "ko-KR, en-US;q=0.9, fr-CA;q=0.8, de;q=0.7, sr;q=0.6, \
279 ja;q=0.5, zh;q=0.4, sv;q=0.3, pt;q=0.2, *;q=0.1" \
280 ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt &&
281 check_language "ko-KR, en-US;q=0.99, fr-CA;q=0.98, de;q=0.97, sr;q=0.96, \
282 ja;q=0.95, zh;q=0.94, sv;q=0.93, pt;q=0.92, nb;q=0.91, *;q=0.90" \
283 ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt:nb
286 test_expect_success 'git client does not send an empty Accept-Language' '
287 GIT_CURL_VERBOSE=1 LANGUAGE= git ls-remote "$HTTPD_URL/dumb/repo.git" 2>stderr &&
288 ! grep "^Accept-Language:" stderr