3 test_description
='test dumb fetching over http via static file'
6 if test -n "$NO_CURL"; then
7 skip_all
='skipping test, git built without http support'
11 .
"$TEST_DIRECTORY"/lib-httpd.sh
14 test_expect_success
'setup repository' '
15 git config push.default matching &&
16 echo content1 >file &&
19 echo content2 >file &&
24 test_expect_success
'create http-accessible bare repository with loose objects' '
25 cp -R .git "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
26 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
27 git config core.bare true &&
29 echo "exec git update-server-info" >hooks/post-update &&
30 chmod +x hooks/post-update &&
33 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
34 git push public master:master
37 test_expect_success
'clone http repository' '
38 git clone $HTTPD_URL/dumb/repo.git clone-tmpl &&
39 cp -R clone-tmpl clone &&
40 test_cmp file clone/file
43 test_expect_success
'create password-protected repository' '
44 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" &&
45 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
46 "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git"
51 test_expect_success
'cloning password-protected repository can fail' '
53 test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-fail &&
54 expect_askpass both wrong
57 test_expect_success
'http auth can use user/pass in URL' '
59 git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none &&
63 test_expect_success
'http auth can use just user in URL' '
64 set_askpass wrong pass@host &&
65 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass &&
66 expect_askpass pass user@host
69 test_expect_success
'http auth can request both user and pass' '
70 set_askpass user@host pass@host &&
71 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both &&
72 expect_askpass both user@host
75 test_expect_success
'http auth respects credential helper config' '
76 test_config_global credential.helper "!f() {
78 echo username=user@host
79 echo password=pass@host
82 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
86 test_expect_success
'http auth can get username from config' '
87 test_config_global "credential.$HTTPD_URL.username" user@host &&
88 set_askpass wrong pass@host &&
89 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user &&
90 expect_askpass pass user@host
93 test_expect_success
'configured username does not override URL' '
94 test_config_global "credential.$HTTPD_URL.username" wrong &&
95 set_askpass wrong pass@host &&
96 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 &&
97 expect_askpass pass user@host
100 test_expect_success
'fetch changes via http' '
101 echo content >>file &&
102 git commit -a -m two &&
104 (cd clone && git pull) &&
105 test_cmp file clone/file
108 test_expect_success
'fetch changes via manual http-fetch' '
109 cp -R clone-tmpl clone2 &&
111 HEAD=$(git rev-parse --verify HEAD) &&
113 git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
114 git checkout master-new &&
115 test $HEAD = $(git rev-parse --verify HEAD)) &&
116 test_cmp file clone2/file
119 test_expect_success
'http remote detects correct HEAD' '
120 git push public master:other &&
122 git remote set-head origin -d &&
123 git remote set-head origin -a &&
124 git symbolic-ref refs/remotes/origin/HEAD > output &&
125 echo refs/remotes/origin/master > expect &&
126 test_cmp expect output
130 test_expect_success
'fetch packed objects' '
131 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
132 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
133 git --bare repack -a -d
135 git clone $HTTPD_URL/dumb/repo_pack.git
138 test_expect_success
'fetch notices corrupt pack' '
139 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
140 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
141 p=`ls objects/pack/pack-*.pack` &&
143 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
145 mkdir repo_bad1.git &&
148 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
149 test 0 = `ls objects/pack/pack-*.pack | wc -l`
153 test_expect_success
'fetch notices corrupt idx' '
154 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
155 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
156 p=`ls objects/pack/pack-*.idx` &&
158 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
160 mkdir repo_bad2.git &&
163 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
164 test 0 = `ls objects/pack | wc -l`
168 test_expect_success
'fetch can handle previously-fetched .idx files' '
169 git checkout --orphan branch1 &&
172 git commit -m base &&
173 git --bare init "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git &&
174 git push "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git branch1 &&
175 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git repack -d &&
176 git checkout -b branch2 branch1 &&
178 git commit -a -m b2 &&
179 git push "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git branch2 &&
180 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git repack -d &&
181 git --bare init clone_packed_branches.git &&
182 git --git-dir=clone_packed_branches.git fetch "$HTTPD_URL"/dumb/repo_packed_branches.git branch1:branch1 &&
183 git --git-dir=clone_packed_branches.git fetch "$HTTPD_URL"/dumb/repo_packed_branches.git branch2:branch2
186 test_expect_success
'did not use upload-pack service' '
187 grep '/git-upload-pack
' <"$HTTPD_ROOT_PATH"/access.log >act
192 test_expect_success
'git client shows text/plain errors' '
193 test_must_fail git clone "$HTTPD_URL/error/text" 2>stderr &&
194 grep "this is the error message" stderr
197 test_expect_success
'git client does not show html errors' '
198 test_must_fail git clone "$HTTPD_URL/error/html" 2>stderr &&
199 ! grep "this is the error message" stderr
202 test_expect_success
'git client shows text/plain with a charset' '
203 test_must_fail git clone "$HTTPD_URL/error/charset" 2>stderr &&
204 grep "this is the error message" stderr
207 test_expect_success ICONV
'http error messages are reencoded' '
208 test_must_fail git clone "$HTTPD_URL/error/utf16" 2>stderr &&
209 grep "this is the error message" stderr
212 test_expect_success ICONV
'reencoding is robust to whitespace oddities' '
213 test_must_fail git clone "$HTTPD_URL/error/odd-spacing" 2>stderr &&
214 grep "this is the error message" stderr
223 echo "Accept-Language: $1" >expect
228 git ls-remote
"$HTTPD_URL/dumb/repo.git" >output
2>&1 &&
229 tr -d '\015' <output |
231 sed -ne '/^Accept-Language:/ p' >actual
&&
232 test_cmp expect actual
235 test_expect_success
'git client sends Accept-Language based on LANGUAGE' '
236 check_language "ko-KR, *;q=0.9" ko_KR.UTF-8'
238 test_expect_success
'git client sends Accept-Language correctly with unordinary LANGUAGE' '
239 check_language "ko-KR, *;q=0.9" "ko_KR:" &&
240 check_language "ko-KR, en-US;q=0.9, *;q=0.8" "ko_KR::en_US" &&
241 check_language "ko-KR, *;q=0.9" ":::ko_KR" &&
242 check_language "ko-KR, en-US;q=0.9, *;q=0.8" "ko_KR!!:en_US" &&
243 check_language "ko-KR, ja-JP;q=0.9, *;q=0.8" "ko_KR en_US:ja_JP"'
245 test_expect_success
'git client sends Accept-Language with many preferred languages' '
246 check_language "ko-KR, en-US;q=0.9, fr-CA;q=0.8, de;q=0.7, sr;q=0.6, \
247 ja;q=0.5, zh;q=0.4, sv;q=0.3, pt;q=0.2, *;q=0.1" \
248 ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt &&
249 check_language "ko-KR, en-US;q=0.99, fr-CA;q=0.98, de;q=0.97, sr;q=0.96, \
250 ja;q=0.95, zh;q=0.94, sv;q=0.93, pt;q=0.92, nb;q=0.91, *;q=0.90" \
251 ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt:nb
254 test_expect_success
'git client does not send an empty Accept-Language' '
255 GIT_CURL_VERBOSE=1 LANGUAGE= git ls-remote "$HTTPD_URL/dumb/repo.git" 2>stderr &&
256 ! grep "^Accept-Language:" stderr