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 'http auth can use user/pass in URL' '
47 git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none &&
51 test_expect_success 'http auth can use just user in URL' '
52 set_askpass wrong pass@host &&
53 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass &&
54 expect_askpass pass user@host
57 test_expect_success 'http auth respects credential helper config' '
58 test_config_global credential.helper "!f() {
60 echo username=user@host
61 echo password=pass@host
64 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
68 test_expect_success 'http auth can get username from config' '
69 test_config_global "credential.$HTTPD_URL.username" user@host &&
70 set_askpass wrong pass@host &&
71 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user &&
72 expect_askpass pass user@host
75 test_expect_success 'configured username does not override URL' '
76 test_config_global "credential.$HTTPD_URL.username" wrong &&
77 set_askpass wrong pass@host &&
78 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 &&
79 expect_askpass pass user@host
82 test_expect_success 'fetch changes via http' '
83 echo content >>file &&
84 git commit -a -m two &&
86 (cd clone && git pull) &&
87 test_cmp file clone/file
90 test_expect_success 'fetch changes via manual http-fetch' '
91 cp -R clone-tmpl clone2 &&
93 HEAD=$(git rev-parse --verify HEAD) &&
95 git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
96 git checkout master-new &&
97 test $HEAD = $(git rev-parse --verify HEAD)) &&
98 test_cmp file clone2/file
101 test_expect_success 'http remote detects correct HEAD' '
102 git push public master:other &&
104 git remote set-head origin -d &&
105 git remote set-head origin -a &&
106 git symbolic-ref refs/remotes/origin/HEAD > output &&
107 echo refs/remotes/origin/master > expect &&
108 test_cmp expect output
112 test_expect_success 'fetch packed objects' '
113 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
114 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
115 git --bare repack -a -d
117 git clone $HTTPD_URL/dumb/repo_pack.git
120 test_expect_success 'fetch notices corrupt pack' '
121 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
122 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
123 p=$(ls objects/pack/pack-*.pack) &&
125 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
127 mkdir repo_bad1.git &&
130 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
131 test 0 = $(ls objects/pack/pack-*.pack | wc -l)
135 test_expect_success 'fetch notices corrupt idx' '
136 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
137 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
138 p=$(ls objects/pack/pack-*.idx) &&
140 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
142 mkdir repo_bad2.git &&
145 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
146 test 0 = $(ls objects/pack | wc -l)
150 test_expect_success 'fetch can handle previously-fetched .idx files' '
151 git checkout --orphan branch1 &&
154 git commit -m base &&
155 git --bare init "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git &&
156 git push "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git branch1 &&
157 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git repack -d &&
158 git checkout -b branch2 branch1 &&
160 git commit -a -m b2 &&
161 git push "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git branch2 &&
162 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git repack -d &&
163 git --bare init clone_packed_branches.git &&
164 git --git-dir=clone_packed_branches.git fetch "$HTTPD_URL"/dumb/repo_packed_branches.git branch1:branch1 &&
165 git --git-dir=clone_packed_branches.git fetch "$HTTPD_URL"/dumb/repo_packed_branches.git branch2:branch2
168 test_expect_success 'did not use upload-pack service' '
169 test_might_fail grep '/git-upload-pack' <"$HTTPD_ROOT_PATH"/access.log >act &&
174 test_expect_success 'git client shows text/plain errors' '
175 test_must_fail git clone "$HTTPD_URL/error/text" 2>stderr &&
176 grep "this is the error message" stderr
179 test_expect_success 'git client does not show html errors' '
180 test_must_fail git clone "$HTTPD_URL/error/html" 2>stderr &&
181 ! grep "this is the error message" stderr
184 test_expect_success 'git client shows text/plain with a charset' '
185 test_must_fail git clone "$HTTPD_URL/error/charset" 2>stderr &&
186 grep "this is the error message" stderr
189 test_expect_success 'http error messages are reencoded' '
190 test_must_fail git clone "$HTTPD_URL/error/utf16" 2>stderr &&
191 grep "this is the error message" stderr
194 test_expect_success 'reencoding is robust to whitespace oddities' '
195 test_must_fail git clone "$HTTPD_URL/error/odd-spacing" 2>stderr &&
196 grep "this is the error message" stderr
205 echo "Accept-Language: $1" >expect
210 git ls-remote "$HTTPD_URL/dumb/repo.git" >output 2>&1 &&
211 tr -d '\015' <output |
213 sed -ne '/^Accept-Language:/ p' >actual &&
214 test_cmp expect actual
217 test_expect_success 'git client sends Accept-Language based on LANGUAGE' '
218 check_language "ko-KR, *;q=0.9" ko_KR.UTF-8'
220 test_expect_success 'git client sends Accept-Language correctly with unordinary LANGUAGE' '
221 check_language "ko-KR, *;q=0.9" "ko_KR:" &&
222 check_language "ko-KR, en-US;q=0.9, *;q=0.8" "ko_KR::en_US" &&
223 check_language "ko-KR, *;q=0.9" ":::ko_KR" &&
224 check_language "ko-KR, en-US;q=0.9, *;q=0.8" "ko_KR!!:en_US" &&
225 check_language "ko-KR, ja-JP;q=0.9, *;q=0.8" "ko_KR en_US:ja_JP"'
227 test_expect_success 'git client sends Accept-Language with many preferred languages' '
228 check_language "ko-KR, en-US;q=0.9, fr-CA;q=0.8, de;q=0.7, sr;q=0.6, \
229 ja;q=0.5, zh;q=0.4, sv;q=0.3, pt;q=0.2, *;q=0.1" \
230 ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt &&
231 check_language "ko-KR, en-US;q=0.99, fr-CA;q=0.98, de;q=0.97, sr;q=0.96, \
232 ja;q=0.95, zh;q=0.94, sv;q=0.93, pt;q=0.92, nb;q=0.91, *;q=0.90" \
233 ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt:nb
236 test_expect_success 'git client does not send an empty Accept-Language' '
237 GIT_CURL_VERBOSE=1 LANGUAGE= git ls-remote "$HTTPD_URL/dumb/repo.git" 2>stderr &&
238 ! grep "^Accept-Language:" stderr