3 test_description
='test smart fetching over http via http-backend'
5 .
"$TEST_DIRECTORY"/lib-httpd.sh
8 test_expect_success
'setup repository' '
9 git config push.default matching &&
15 test_expect_success
'create http-accessible bare repository' '
16 mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
17 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
20 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
21 git push public master:master
27 > GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
29 > Accept-Encoding: gzip
33 < Cache-Control: no-cache, max-age=0, must-revalidate
34 < Content-Type: application/x-git-upload-pack-advertisement
35 > POST /smart/repo.git/git-upload-pack HTTP/1.1
36 > Accept-Encoding: gzip
37 > Content-Type: application/x-git-upload-pack-request
38 > Accept: application/x-git-upload-pack-result
42 < Cache-Control: no-cache, max-age=0, must-revalidate
43 < Content-Type: application/x-git-upload-pack-result
45 test_expect_success
'clone http repository' '
46 GIT_CURL_VERBOSE=1 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
47 test_cmp file clone/file &&
48 tr '\''\015'\'' Q <err |
62 /^> Accept: [*]\\/[*]/d
64 s/^> Content-Length: .*/> Content-Length: xxx/
71 /^< Content-Length: /d
72 /^< Transfer-Encoding: /d
77 test_expect_success
'fetch changes via http' '
78 echo content >>file &&
79 git commit -a -m two &&
81 (cd clone && git pull) &&
82 test_cmp file clone/file
86 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
87 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
88 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
89 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
91 test_expect_success
'used upload-pack service' '
97 " >act <"$HTTPD_ROOT_PATH"/access.log &&
101 test_expect_success
'follow redirects (301)' '
102 git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
105 test_expect_success
'follow redirects (302)' '
106 git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
109 test_expect_success
'redirects re-root further requests' '
110 git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
113 test_expect_success
'clone from password-protected repository' '
115 set_askpass user@host pass@host &&
116 git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
117 expect_askpass both user@host &&
118 git --git-dir=smart-auth log -1 --format=%s >actual &&
119 test_cmp expect actual
122 test_expect_success
'clone from auth-only-for-push repository' '
125 git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
126 expect_askpass none &&
127 git --git-dir=smart-noauth log -1 --format=%s >actual &&
128 test_cmp expect actual
131 test_expect_success
'clone from auth-only-for-objects repository' '
133 set_askpass user@host pass@host &&
134 git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
135 expect_askpass both user@host &&
136 git --git-dir=half-auth log -1 --format=%s >actual &&
137 test_cmp expect actual
140 test_expect_success
'no-op half-auth fetch does not require a password' '
142 git --git-dir=half-auth fetch &&
146 test_expect_success
'redirects send auth to new location' '
147 set_askpass user@host pass@host &&
148 git -c credential.useHttpPath=true \
149 clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth &&
150 expect_askpass both user@host auth/smart/repo.git
153 test_expect_success
'disable dumb http on server' '
154 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
155 config http.getanyfile false
158 test_expect_success
'GIT_SMART_HTTP can disable smart http' '
160 export GIT_SMART_HTTP &&
162 test_must_fail git fetch)
165 test_expect_success
'invalid Content-Type rejected' '
166 test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual &&
167 grep "not valid:" actual
170 test_expect_success
'create namespaced refs' '
171 test_commit namespaced &&
172 git push public HEAD:refs/namespaces/ns/refs/heads/master &&
173 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
174 symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/master
177 test_expect_success
'smart clone respects namespace' '
178 git clone "$HTTPD_URL/smart_namespace/repo.git" ns-smart &&
179 echo namespaced >expect &&
180 git --git-dir=ns-smart/.git log -1 --format=%s >actual &&
181 test_cmp expect actual
184 test_expect_success
'dumb clone via http-backend respects namespace' '
185 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
186 config http.getanyfile true &&
187 GIT_SMART_HTTP=0 git clone \
188 "$HTTPD_URL/smart_namespace/repo.git" ns-dumb &&
189 echo namespaced >expect &&
190 git --git-dir=ns-dumb/.git log -1 --format=%s >actual &&
191 test_cmp expect actual
194 cat >cookies.txt
<<EOF
195 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
197 cat >expect_cookies.txt
<<EOF
199 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
200 127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value
202 test_expect_success
'cookies stored in http.cookiefile when http.savecookies set' '
203 git config http.cookiefile cookies.txt &&
204 git config http.savecookies true &&
205 git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
206 tail -3 cookies.txt >cookies_tail.txt &&
207 test_cmp expect_cookies.txt cookies_tail.txt
210 test_expect_success
'transfer.hiderefs works over smart-http' '
211 test_commit hidden &&
212 test_commit visible &&
213 git push public HEAD^:refs/heads/a HEAD:refs/heads/b &&
214 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
215 config transfer.hiderefs refs/heads/a &&
216 git clone --bare "$HTTPD_URL/smart/repo.git" hidden.git &&
217 test_must_fail git -C hidden.git rev-parse --verify a &&
218 git -C hidden.git rev-parse --verify b
221 # create an arbitrary number of tags, numbered from tag-$1 to tag-$2
224 for i
in $
(test_seq
"$1" "$2")
226 # don't use here-doc, because it requires a process
228 echo "commit refs/heads/too-many-refs-$1" &&
230 echo "committer git <git@example.com> $i +0000" &&
232 echo "M 644 inline bla.txt" &&
235 # make every commit dangling by always
236 # rewinding the branch after each commit
237 echo "reset refs/heads/too-many-refs-$1" &&
239 done | git fast-import
--export-marks=marks
&&
241 # now assign tags to all the dangling commits we created above
242 tag
=$
(perl
-e "print \"bla\" x 30") &&
243 sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks
>>packed-refs
246 test_expect_success
'create 2,000 tags in the repo' '
248 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
253 test_expect_success CMDLINE_LIMIT \
254 'clone the 2,000 tag repo to check OS command line overflow' '
255 run_with_limited_cmdline git clone $HTTPD_URL/smart/repo.git too-many-refs &&
258 git for-each-ref refs/tags >actual &&
259 test_line_count = 2000 actual
263 test_expect_success
'large fetch-pack requests can be split across POSTs' '
264 GIT_CURL_VERBOSE=1 git -c http.postbuffer=65536 \
265 clone --bare "$HTTPD_URL/smart/repo.git" split.git 2>err &&
266 grep "^> POST" err >posts &&
267 test_line_count = 2 posts
270 test_expect_success EXPENSIVE
'http can handle enormous ref negotiation' '
272 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
273 create_tags 2001 50000
275 git -C too-many-refs fetch -q --tags &&
277 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
278 create_tags 50001 100000
280 git -C too-many-refs fetch -q --tags &&
281 git -C too-many-refs for-each-ref refs/tags >tags &&
282 test_line_count = 100000 tags
285 test_expect_success
'custom http headers' '
286 test_must_fail git -c http.extraheader="x-magic-two: cadabra" \
287 fetch "$HTTPD_URL/smart_headers/repo.git" &&
288 git -c http.extraheader="x-magic-one: abra" \
289 -c http.extraheader="x-magic-two: cadabra" \
290 fetch "$HTTPD_URL/smart_headers/repo.git" &&
291 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
292 git config -f .gitmodules submodule.sub.path sub &&
293 git config -f .gitmodules submodule.sub.url \
294 "$HTTPD_URL/smart_headers/repo.git" &&
295 git submodule init sub &&
296 test_must_fail git submodule update sub &&
297 git -c http.extraheader="x-magic-one: abra" \
298 -c http.extraheader="x-magic-two: cadabra" \