builtin/fetch.c: reorder function definitions
[git/mingw.git] / t / t5551-http-fetch.sh
blob8196af19f68ac3772a81326828f7cdf83ae399a1
1 #!/bin/sh
3 test_description='test smart fetching over http via http-backend'
4 . ./test-lib.sh
6 if test -n "$NO_CURL"; then
7 skip_all='skipping test, git built without http support'
8 test_done
9 fi
11 LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5551'}
12 . "$TEST_DIRECTORY"/lib-httpd.sh
13 start_httpd
15 test_expect_success 'setup repository' '
16 git config push.default matching &&
17 echo content >file &&
18 git add file &&
19 git commit -m one
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" &&
25 git --bare init
26 ) &&
27 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
28 git push public master:master
31 setup_askpass_helper
33 cat >exp <<EOF
34 > GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
35 > Accept: */*
36 > Accept-Encoding: gzip
37 > Pragma: no-cache
38 < HTTP/1.1 200 OK
39 < Pragma: no-cache
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
46 > Content-Length: xxx
47 < HTTP/1.1 200 OK
48 < Pragma: no-cache
49 < Cache-Control: no-cache, max-age=0, must-revalidate
50 < Content-Type: application/x-git-upload-pack-result
51 EOF
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 |
56 sed -e "
57 s/Q\$//
58 /^[*] /d
59 /^$/d
60 /^< $/d
62 /^[^><]/{
63 s/^/> /
66 /^> User-Agent: /d
67 /^> Host: /d
68 /^> POST /,$ {
69 /^> Accept: [*]\\/[*]/d
71 s/^> Content-Length: .*/> Content-Length: xxx/
72 /^> 00..want /d
73 /^> 00.*done/d
75 /^< Server: /d
76 /^< Expires: /d
77 /^< Date: /d
78 /^< Content-Length: /d
79 /^< Transfer-Encoding: /d
80 " >act &&
81 test_cmp exp act
84 test_expect_success 'fetch changes via http' '
85 echo content >>file &&
86 git commit -a -m two &&
87 git push public
88 (cd clone && git pull) &&
89 test_cmp file clone/file
92 cat >exp <<EOF
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
97 EOF
98 test_expect_success 'used upload-pack service' '
99 sed -e "
100 s/^.* \"//
101 s/\"//
102 s/ [1-9][0-9]*\$//
103 s/^GET /GET /
104 " >act <"$HTTPD_ROOT_PATH"/access.log &&
105 test_cmp exp act
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 'clone from password-protected repository' '
117 echo two >expect &&
118 set_askpass user@host &&
119 git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
120 expect_askpass both user@host &&
121 git --git-dir=smart-auth log -1 --format=%s >actual &&
122 test_cmp expect actual
125 test_expect_success 'clone from auth-only-for-push repository' '
126 echo two >expect &&
127 set_askpass wrong &&
128 git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
129 expect_askpass none &&
130 git --git-dir=smart-noauth log -1 --format=%s >actual &&
131 test_cmp expect actual
134 test_expect_success 'clone from auth-only-for-objects repository' '
135 echo two >expect &&
136 set_askpass user@host &&
137 git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
138 expect_askpass both user@host &&
139 git --git-dir=half-auth log -1 --format=%s >actual &&
140 test_cmp expect actual
143 test_expect_success 'no-op half-auth fetch does not require a password' '
144 set_askpass wrong &&
145 git --git-dir=half-auth fetch &&
146 expect_askpass none
149 test_expect_success 'disable dumb http on server' '
150 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
151 config http.getanyfile false
154 test_expect_success 'GIT_SMART_HTTP can disable smart http' '
155 (GIT_SMART_HTTP=0 &&
156 export GIT_SMART_HTTP &&
157 cd clone &&
158 test_must_fail git fetch)
161 test_expect_success 'invalid Content-Type rejected' '
162 test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual
163 grep "not valid:" actual
166 test_expect_success 'create namespaced refs' '
167 test_commit namespaced &&
168 git push public HEAD:refs/namespaces/ns/refs/heads/master &&
169 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
170 symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/master
173 test_expect_success 'smart clone respects namespace' '
174 git clone "$HTTPD_URL/smart_namespace/repo.git" ns-smart &&
175 echo namespaced >expect &&
176 git --git-dir=ns-smart/.git log -1 --format=%s >actual &&
177 test_cmp expect actual
180 test_expect_success 'dumb clone via http-backend respects namespace' '
181 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
182 config http.getanyfile true &&
183 GIT_SMART_HTTP=0 git clone \
184 "$HTTPD_URL/smart_namespace/repo.git" ns-dumb &&
185 echo namespaced >expect &&
186 git --git-dir=ns-dumb/.git log -1 --format=%s >actual &&
187 test_cmp expect actual
190 cat >cookies.txt <<EOF
191 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
193 cat >expect_cookies.txt <<EOF
195 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
196 127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value
198 test_expect_success 'cookies stored in http.cookiefile when http.savecookies set' '
199 git config http.cookiefile cookies.txt &&
200 git config http.savecookies true &&
201 git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
202 tail -3 cookies.txt > cookies_tail.txt
203 test_cmp expect_cookies.txt cookies_tail.txt
206 test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE
208 test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
210 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
211 for i in `test_seq 50000`
213 echo "commit refs/heads/too-many-refs"
214 echo "mark :$i"
215 echo "committer git <git@example.com> $i +0000"
216 echo "data 0"
217 echo "M 644 inline bla.txt"
218 echo "data 4"
219 echo "bla"
220 # make every commit dangling by always
221 # rewinding the branch after each commit
222 echo "reset refs/heads/too-many-refs"
223 echo "from :1"
224 done | git fast-import --export-marks=marks &&
226 # now assign tags to all the dangling commits we created above
227 tag=$("$PERL_PATH" -e "print \"bla\" x 30") &&
228 sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
232 test_expect_success EXPENSIVE 'clone the 50,000 tag repo to check OS command line overflow' '
233 git clone $HTTPD_URL/smart/repo.git too-many-refs 2>err &&
234 test_line_count = 0 err &&
236 cd too-many-refs &&
237 test $(git for-each-ref refs/tags | wc -l) = 50000
241 stop_httpd
242 test_done