3 test_description
='test smart fetching over http via http-backend'
6 if test -n "$NO_CURL"; then
7 skip_all
='skipping test, git built without http support'
11 LIB_HTTPD_PORT
=${LIB_HTTPD_PORT-'5551'}
12 .
"$TEST_DIRECTORY"/lib-httpd.sh
15 test_expect_success
'setup repository' '
16 git config push.default matching &&
22 test_expect_success
'create http-accessible bare repository' '
23 mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
24 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
27 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
28 git push public master:master
34 > GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
36 > Accept-Encoding: gzip
40 < Cache-Control: no-cache, max-age=0, must-revalidate
41 < Content-Type: application/x-git-upload-pack-advertisement
42 > POST /smart/repo.git/git-upload-pack HTTP/1.1
43 > Accept-Encoding: gzip
44 > Content-Type: application/x-git-upload-pack-request
45 > Accept: application/x-git-upload-pack-result
49 < Cache-Control: no-cache, max-age=0, must-revalidate
50 < Content-Type: application/x-git-upload-pack-result
52 test_expect_success
'clone http repository' '
53 GIT_CURL_VERBOSE=1 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
54 test_cmp file clone/file &&
55 tr '\''\015'\'' Q <err |
69 /^> Accept: [*]\\/[*]/d
71 s/^> Content-Length: .*/> Content-Length: xxx/
78 /^< Content-Length: /d
79 /^< Transfer-Encoding: /d
84 test_expect_success
'fetch changes via http' '
85 echo content >>file &&
86 git commit -a -m two &&
88 (cd clone && git pull) &&
89 test_cmp file clone/file
93 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
94 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
95 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
96 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
98 test_expect_success
'used upload-pack service' '
104 " >act <"$HTTPD_ROOT_PATH"/access.log &&
108 test_expect_success
'follow redirects (301)' '
109 git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
112 test_expect_success
'follow redirects (302)' '
113 git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
116 test_expect_success
'redirects re-root further requests' '
117 git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
120 test_expect_success
'clone from password-protected repository' '
122 set_askpass user@host &&
123 git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
124 expect_askpass both user@host &&
125 git --git-dir=smart-auth log -1 --format=%s >actual &&
126 test_cmp expect actual
129 test_expect_success
'clone from auth-only-for-push repository' '
132 git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
133 expect_askpass none &&
134 git --git-dir=smart-noauth log -1 --format=%s >actual &&
135 test_cmp expect actual
138 test_expect_success
'clone from auth-only-for-objects repository' '
140 set_askpass user@host &&
141 git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
142 expect_askpass both user@host &&
143 git --git-dir=half-auth log -1 --format=%s >actual &&
144 test_cmp expect actual
147 test_expect_success
'no-op half-auth fetch does not require a password' '
149 git --git-dir=half-auth fetch &&
153 test_expect_success
'redirects send auth to new location' '
154 set_askpass user@host &&
155 git -c credential.useHttpPath=true \
156 clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth &&
157 expect_askpass both user@host auth/smart/repo.git
160 test_expect_success
'disable dumb http on server' '
161 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
162 config http.getanyfile false
165 test_expect_success
'GIT_SMART_HTTP can disable smart http' '
167 export GIT_SMART_HTTP &&
169 test_must_fail git fetch)
172 test_expect_success
'invalid Content-Type rejected' '
173 test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual
174 grep "not valid:" actual
177 test_expect_success
'create namespaced refs' '
178 test_commit namespaced &&
179 git push public HEAD:refs/namespaces/ns/refs/heads/master &&
180 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
181 symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/master
184 test_expect_success
'smart clone respects namespace' '
185 git clone "$HTTPD_URL/smart_namespace/repo.git" ns-smart &&
186 echo namespaced >expect &&
187 git --git-dir=ns-smart/.git log -1 --format=%s >actual &&
188 test_cmp expect actual
191 test_expect_success
'dumb clone via http-backend respects namespace' '
192 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
193 config http.getanyfile true &&
194 GIT_SMART_HTTP=0 git clone \
195 "$HTTPD_URL/smart_namespace/repo.git" ns-dumb &&
196 echo namespaced >expect &&
197 git --git-dir=ns-dumb/.git log -1 --format=%s >actual &&
198 test_cmp expect actual
201 test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE
203 test_expect_success EXPENSIVE
'create 50,000 tags in the repo' '
205 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
206 for i in `test_seq 50000`
208 echo "commit refs/heads/too-many-refs"
210 echo "committer git <git@example.com> $i +0000"
212 echo "M 644 inline bla.txt"
215 # make every commit dangling by always
216 # rewinding the branch after each commit
217 echo "reset refs/heads/too-many-refs"
219 done | git fast-import --export-marks=marks &&
221 # now assign tags to all the dangling commits we created above
222 tag=$("$PERL_PATH" -e "print \"bla\" x 30") &&
223 sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
227 test_expect_success EXPENSIVE
'clone the 50,000 tag repo to check OS command line overflow' '
228 git clone $HTTPD_URL/smart/repo.git too-many-refs 2>err &&
229 test_line_count = 0 err &&
232 test $(git for-each-ref refs/tags | wc -l) = 50000