test smart http fetch and push
[git] / t / t5551-http-fetch.sh
1 #!/bin/sh
2
3 test_description='test smart fetching over http via http-backend'
4 . ./test-lib.sh
5
6 if test -n "$NO_CURL"; then
7         say 'skipping test, git built without http support'
8         test_done
9 fi
10
11 LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5551'}
12 . "$TEST_DIRECTORY"/lib-httpd.sh
13 start_httpd
14
15 test_expect_success 'setup repository' '
16         echo content >file &&
17         git add file &&
18         git commit -m one
19 '
20
21 test_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
30 cat >exp <<EOF
31 > GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
32 > Accept: */*
33 > Pragma: no-cache
34
35 < HTTP/1.1 200 OK
36 < Pragma: no-cache
37 < Cache-Control: no-cache, max-age=0, must-revalidate
38 < Content-Type: application/x-git-upload-pack-advertisement
39
40 > POST /smart/repo.git/git-upload-pack HTTP/1.1
41 > Accept-Encoding: deflate, gzip
42 > Content-Type: application/x-git-upload-pack-request
43 > Accept: application/x-git-upload-pack-response
44 > Content-Length: xxx
45
46 < HTTP/1.1 200 OK
47 < Pragma: no-cache
48 < Cache-Control: no-cache, max-age=0, must-revalidate
49 < Content-Type: application/x-git-upload-pack-result
50
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
60                 /^[^><]/{
61                         s/^/> /
62                 }
63
64                 /^> User-Agent: /d
65                 /^> Host: /d
66                 s/^> Content-Length: .*/> Content-Length: xxx/
67
68                 /^< Server: /d
69                 /^< Expires: /d
70                 /^< Date: /d
71                 /^< Content-Length: /d
72                 /^< Transfer-Encoding: /d
73         " >act &&
74         test_cmp exp act
75 '
76
77 test_expect_success 'fetch changes via http' '
78         echo content >>file &&
79         git commit -a -m two &&
80         git push public
81         (cd clone && git pull) &&
82         test_cmp file clone/file
83 '
84
85 cat >exp <<EOF
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
90 EOF
91 test_expect_success 'used upload-pack service' '
92         sed -e "
93                 s/^.* \"//
94                 s/\"//
95                 s/ [1-9][0-9]*\$//
96                 s/^GET /GET  /
97         " >act <"$HTTPD_ROOT_PATH"/access.log &&
98         test_cmp exp act
99 '
100
101 stop_httpd
102 test_done