Merge branch 'mg/status-in-progress-info' into pu
[git] / t / t5702-protocol-v2.sh
1 #!/bin/sh
2
3 test_description='test git wire-protocol version 2'
4
5 TEST_NO_CREATE_REPO=1
6
7 . ./test-lib.sh
8
9 # Test protocol v2 with 'git://' transport
10 #
11 . "$TEST_DIRECTORY"/lib-git-daemon.sh
12 start_git_daemon --export-all --enable=receive-pack
13 daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent
14
15 test_expect_success 'create repo to be served by git-daemon' '
16         git init "$daemon_parent" &&
17         test_commit -C "$daemon_parent" one
18 '
19
20 test_expect_success 'list refs with git:// using protocol v2' '
21         GIT_TRACE_PACKET=1 git -c protocol.version=2 \
22                 ls-remote --symref "$GIT_DAEMON_URL/parent" >actual 2>log &&
23
24         # Client requested to use protocol v2
25         grep "git> .*\\\0\\\0version=2\\\0$" log &&
26         # Server responded using protocol v2
27         grep "git< version 2" log &&
28
29         git ls-remote --symref "$GIT_DAEMON_URL/parent" >expect &&
30         test_cmp actual expect
31 '
32
33 test_expect_success 'ref advertisment is filtered with ls-remote using protocol v2' '
34         GIT_TRACE_PACKET=1 git -c protocol.version=2 \
35                 ls-remote "$GIT_DAEMON_URL/parent" master 2>log &&
36
37         grep "ref-pattern master" log &&
38         ! grep "refs/tags/" log
39 '
40
41 test_expect_success 'clone with git:// using protocol v2' '
42         GIT_TRACE_PACKET=1 git -c protocol.version=2 \
43                 clone "$GIT_DAEMON_URL/parent" daemon_child 2>log &&
44
45         git -C daemon_child log -1 --format=%s >actual &&
46         git -C "$daemon_parent" log -1 --format=%s >expect &&
47         test_cmp expect actual &&
48
49         # Client requested to use protocol v2
50         grep "clone> .*\\\0\\\0version=2\\\0$" log &&
51         # Server responded using protocol v2
52         grep "clone< version 2" log
53 '
54
55 test_expect_success 'fetch with git:// using protocol v2' '
56         test_commit -C "$daemon_parent" two &&
57
58         GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=2 \
59                 fetch 2>log &&
60
61         git -C daemon_child log -1 --format=%s origin/master >actual &&
62         git -C "$daemon_parent" log -1 --format=%s >expect &&
63         test_cmp expect actual &&
64
65         # Client requested to use protocol v2
66         grep "fetch> .*\\\0\\\0version=2\\\0$" log &&
67         # Server responded using protocol v2
68         grep "fetch< version 2" log
69 '
70
71 test_expect_success 'pull with git:// using protocol v2' '
72         GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=2 \
73                 pull 2>log &&
74
75         git -C daemon_child log -1 --format=%s >actual &&
76         git -C "$daemon_parent" log -1 --format=%s >expect &&
77         test_cmp expect actual &&
78
79         # Client requested to use protocol v2
80         grep "fetch> .*\\\0\\\0version=2\\\0$" log &&
81         # Server responded using protocol v2
82         grep "fetch< version 2" log
83 '
84
85 test_expect_success 'push with git:// and a config of v2 does not request v2' '
86         # Till v2 for push is designed, make sure that if a client has
87         # protocol.version configured to use v2, that the client instead falls
88         # back and uses v0.
89
90         test_commit -C daemon_child three &&
91
92         # Push to another branch, as the target repository has the
93         # master branch checked out and we cannot push into it.
94         GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=2 \
95                 push origin HEAD:client_branch 2>log &&
96
97         git -C daemon_child log -1 --format=%s >actual &&
98         git -C "$daemon_parent" log -1 --format=%s client_branch >expect &&
99         test_cmp expect actual &&
100
101         # Client requested to use protocol v2
102         ! grep "push> .*\\\0\\\0version=2\\\0$" log &&
103         # Server responded using protocol v2
104         ! grep "push< version 2" log
105 '
106
107 stop_git_daemon
108
109 # Test protocol v2 with 'file://' transport
110 #
111 test_expect_success 'create repo to be served by file:// transport' '
112         git init file_parent &&
113         test_commit -C file_parent one
114 '
115
116 test_expect_success 'list refs with file:// using protocol v2' '
117         GIT_TRACE_PACKET=1 git -c protocol.version=2 \
118                 ls-remote --symref "file://$(pwd)/file_parent" >actual 2>log &&
119
120         # Server responded using protocol v2
121         grep "git< version 2" log &&
122
123         git ls-remote --symref "file://$(pwd)/file_parent" >expect &&
124         test_cmp actual expect
125 '
126
127 test_expect_success 'ref advertisment is filtered with ls-remote using protocol v2' '
128         GIT_TRACE_PACKET=1 git -c protocol.version=2 \
129                 ls-remote "file://$(pwd)/file_parent" master 2>log &&
130
131         grep "ref-pattern master" log &&
132         ! grep "refs/tags/" log
133 '
134
135 test_expect_success 'clone with file:// using protocol v2' '
136         GIT_TRACE_PACKET=1 git -c protocol.version=2 \
137                 clone "file://$(pwd)/file_parent" file_child 2>log &&
138
139         git -C file_child log -1 --format=%s >actual &&
140         git -C file_parent log -1 --format=%s >expect &&
141         test_cmp expect actual &&
142
143         # Server responded using protocol v2
144         grep "clone< version 2" log
145 '
146
147 test_expect_success 'fetch with file:// using protocol v2' '
148         test_commit -C file_parent two &&
149
150         GIT_TRACE_PACKET=1 git -C file_child -c protocol.version=2 \
151                 fetch origin 2>log &&
152
153         git -C file_child log -1 --format=%s origin/master >actual &&
154         git -C file_parent log -1 --format=%s >expect &&
155         test_cmp expect actual &&
156
157         # Server responded using protocol v2
158         grep "fetch< version 2" log
159 '
160
161 test_expect_success 'ref advertisment is filtered during fetch using protocol v2' '
162         test_commit -C file_parent three &&
163
164         GIT_TRACE_PACKET=1 git -C file_child -c protocol.version=2 \
165                 fetch origin master 2>log &&
166
167         git -C file_child log -1 --format=%s origin/master >actual &&
168         git -C file_parent log -1 --format=%s >expect &&
169         test_cmp expect actual &&
170
171         grep "ref-pattern master" log &&
172         ! grep "refs/tags/" log
173 '
174
175 # Test protocol v2 with 'http://' transport
176 #
177 . "$TEST_DIRECTORY"/lib-httpd.sh
178 start_httpd
179
180 test_expect_success 'create repo to be served by http:// transport' '
181         git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
182         git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config http.receivepack true &&
183         test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one
184 '
185
186 test_expect_success 'clone with http:// using protocol v2' '
187         GIT_TRACE_PACKET=1 GIT_TRACE_CURL=1 git -c protocol.version=2 \
188                 clone "$HTTPD_URL/smart/http_parent" http_child 2>log &&
189
190         git -C http_child log -1 --format=%s >actual &&
191         git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
192         test_cmp expect actual &&
193
194         # Client requested to use protocol v2
195         grep "Git-Protocol: version=2" log &&
196         # Server responded using protocol v2
197         grep "git< version 2" log
198 '
199
200 test_expect_success 'fetch with http:// using protocol v2' '
201         test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two &&
202
203         GIT_TRACE_PACKET=1 git -C http_child -c protocol.version=2 \
204                 fetch 2>log &&
205
206         git -C http_child log -1 --format=%s origin/master >actual &&
207         git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
208         test_cmp expect actual &&
209
210         # Server responded using protocol v2
211         grep "git< version 2" log
212 '
213
214 test_expect_success 'push with http:// and a config of v2 does not request v2' '
215         # Till v2 for push is designed, make sure that if a client has
216         # protocol.version configured to use v2, that the client instead falls
217         # back and uses v0.
218
219         test_commit -C http_child three &&
220
221         # Push to another branch, as the target repository has the
222         # master branch checked out and we cannot push into it.
223         GIT_TRACE_PACKET=1 git -C http_child -c protocol.version=1 \
224                 push origin HEAD:client_branch && 2>log &&
225
226         git -C http_child log -1 --format=%s >actual &&
227         git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s client_branch >expect &&
228         test_cmp expect actual &&
229
230         # Client didnt request to use protocol v2
231         ! grep "Git-Protocol: version=2" log &&
232         # Server didnt respond using protocol v2
233         ! grep "git< version 2" log
234 '
235
236
237 stop_httpd
238
239 test_done