t/lib-httpd: recognize */smart/* repos as smart-http
[git/git.git] / t / t5551-http-fetch.sh
CommitLineData
7da4e228
SP
1#!/bin/sh
2
3test_description='test smart fetching over http via http-backend'
4. ./test-lib.sh
5
6if test -n "$NO_CURL"; then
fadb5156 7 skip_all='skipping test, git built without http support'
7da4e228
SP
8 test_done
9fi
10
11LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5551'}
12. "$TEST_DIRECTORY"/lib-httpd.sh
13start_httpd
14
15test_expect_success 'setup repository' '
16 echo content >file &&
17 git add file &&
18 git commit -m one
19'
20
21test_expect_success 'create http-accessible bare repository' '
22 mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
23 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
24 git --bare init
25 ) &&
26 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
27 git push public master:master
28'
29
30cat >exp <<EOF
31> GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
32> Accept: */*
33> Pragma: no-cache
7da4e228
SP
34< HTTP/1.1 200 OK
35< Pragma: no-cache
36< Cache-Control: no-cache, max-age=0, must-revalidate
37< Content-Type: application/x-git-upload-pack-advertisement
7da4e228
SP
38> POST /smart/repo.git/git-upload-pack HTTP/1.1
39> Accept-Encoding: deflate, gzip
40> Content-Type: application/x-git-upload-pack-request
8efa5f62 41> Accept: application/x-git-upload-pack-result
7da4e228 42> Content-Length: xxx
7da4e228
SP
43< HTTP/1.1 200 OK
44< Pragma: no-cache
45< Cache-Control: no-cache, max-age=0, must-revalidate
46< Content-Type: application/x-git-upload-pack-result
7da4e228
SP
47EOF
48test_expect_success 'clone http repository' '
49 GIT_CURL_VERBOSE=1 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
50 test_cmp file clone/file &&
51 tr '\''\015'\'' Q <err |
52 sed -e "
53 s/Q\$//
54 /^[*] /d
0a8fcbdc
SP
55 /^$/d
56 /^< $/d
7da4e228
SP
57
58 /^[^><]/{
59 s/^/> /
60 }
61
62 /^> User-Agent: /d
63 /^> Host: /d
20366635
SP
64 /^> POST /,$ {
65 /^> Accept: [*]\\/[*]/d
66 }
7da4e228 67 s/^> Content-Length: .*/> Content-Length: xxx/
0a8fcbdc
SP
68 /^> 00..want /d
69 /^> 00.*done/d
7da4e228
SP
70
71 /^< Server: /d
72 /^< Expires: /d
73 /^< Date: /d
74 /^< Content-Length: /d
75 /^< Transfer-Encoding: /d
76 " >act &&
77 test_cmp exp act
78'
79
80test_expect_success 'fetch changes via http' '
81 echo content >>file &&
82 git commit -a -m two &&
83 git push public
84 (cd clone && git pull) &&
85 test_cmp file clone/file
86'
87
88cat >exp <<EOF
89GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
90POST /smart/repo.git/git-upload-pack HTTP/1.1 200
91GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
92POST /smart/repo.git/git-upload-pack HTTP/1.1 200
93EOF
94test_expect_success 'used upload-pack service' '
95 sed -e "
96 s/^.* \"//
97 s/\"//
98 s/ [1-9][0-9]*\$//
99 s/^GET /GET /
100 " >act <"$HTTPD_ROOT_PATH"/access.log &&
101 test_cmp exp act
102'
103
311e2ea0
TRC
104test_expect_success 'follow redirects (301)' '
105 git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
106'
107
108test_expect_success 'follow redirects (302)' '
109 git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
110'
111
7103d254
IT
112test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE
113
114test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
115 (
116 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
117 for i in `seq 50000`
118 do
119 echo "commit refs/heads/too-many-refs"
120 echo "mark :$i"
121 echo "committer git <git@example.com> $i +0000"
122 echo "data 0"
123 echo "M 644 inline bla.txt"
124 echo "data 4"
125 echo "bla"
126 # make every commit dangling by always
127 # rewinding the branch after each commit
128 echo "reset refs/heads/too-many-refs"
129 echo "from :1"
130 done | git fast-import --export-marks=marks &&
131
132 # now assign tags to all the dangling commits we created above
133 tag=$(perl -e "print \"bla\" x 30") &&
134 sed -e "s/^:\(.\+\) \(.\+\)$/\2 refs\/tags\/$tag-\1/" <marks >>packed-refs
135 )
136'
137
138test_expect_success EXPENSIVE 'clone the 50,000 tag repo to check OS command line overflow' '
139 git clone $HTTPD_URL/smart/repo.git too-many-refs 2>err &&
140 test_line_count = 0 err
141'
142
7da4e228
SP
143stop_httpd
144test_done