commit-graph: when incompatible with graphs, indicate why
[git] / t / t5700-protocol-v1.sh
1 #!/bin/sh
2
3 test_description='test git wire-protocol transition'
4
5 TEST_NO_CREATE_REPO=1
6
7 # This is a protocol-specific test.
8 GIT_TEST_PROTOCOL_VERSION=0
9 export GIT_TEST_PROTOCOL_VERSION
10
11 . ./test-lib.sh
12
13 # Test protocol v1 with 'git://' transport
14 #
15 . "$TEST_DIRECTORY"/lib-git-daemon.sh
16 start_git_daemon --export-all --enable=receive-pack
17 daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent
18
19 test_expect_success 'create repo to be served by git-daemon' '
20         git init "$daemon_parent" &&
21         test_commit -C "$daemon_parent" one
22 '
23
24 test_expect_success 'clone with git:// using protocol v1' '
25         GIT_TRACE_PACKET=1 git -c protocol.version=1 \
26                 clone "$GIT_DAEMON_URL/parent" daemon_child 2>log &&
27
28         git -C daemon_child log -1 --format=%s >actual &&
29         git -C "$daemon_parent" log -1 --format=%s >expect &&
30         test_cmp expect actual &&
31
32         # Client requested to use protocol v1
33         grep "clone> .*\\\0\\\0version=1\\\0$" log &&
34         # Server responded using protocol v1
35         grep "clone< version 1" log
36 '
37
38 test_expect_success 'fetch with git:// using protocol v1' '
39         test_commit -C "$daemon_parent" two &&
40
41         GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=1 \
42                 fetch 2>log &&
43
44         git -C daemon_child log -1 --format=%s origin/master >actual &&
45         git -C "$daemon_parent" log -1 --format=%s >expect &&
46         test_cmp expect actual &&
47
48         # Client requested to use protocol v1
49         grep "fetch> .*\\\0\\\0version=1\\\0$" log &&
50         # Server responded using protocol v1
51         grep "fetch< version 1" log
52 '
53
54 test_expect_success 'pull with git:// using protocol v1' '
55         GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=1 \
56                 pull 2>log &&
57
58         git -C daemon_child log -1 --format=%s >actual &&
59         git -C "$daemon_parent" log -1 --format=%s >expect &&
60         test_cmp expect actual &&
61
62         # Client requested to use protocol v1
63         grep "fetch> .*\\\0\\\0version=1\\\0$" log &&
64         # Server responded using protocol v1
65         grep "fetch< version 1" log
66 '
67
68 test_expect_success 'push with git:// using protocol v1' '
69         test_commit -C daemon_child three &&
70
71         # Push to another branch, as the target repository has the
72         # master branch checked out and we cannot push into it.
73         GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=1 \
74                 push origin HEAD:client_branch 2>log &&
75
76         git -C daemon_child log -1 --format=%s >actual &&
77         git -C "$daemon_parent" log -1 --format=%s client_branch >expect &&
78         test_cmp expect actual &&
79
80         # Client requested to use protocol v1
81         grep "push> .*\\\0\\\0version=1\\\0$" log &&
82         # Server responded using protocol v1
83         grep "push< version 1" log
84 '
85
86 stop_git_daemon
87
88 # Test protocol v1 with 'file://' transport
89 #
90 test_expect_success 'create repo to be served by file:// transport' '
91         git init file_parent &&
92         test_commit -C file_parent one
93 '
94
95 test_expect_success 'clone with file:// using protocol v1' '
96         GIT_TRACE_PACKET=1 git -c protocol.version=1 \
97                 clone "file://$(pwd)/file_parent" file_child 2>log &&
98
99         git -C file_child log -1 --format=%s >actual &&
100         git -C file_parent log -1 --format=%s >expect &&
101         test_cmp expect actual &&
102
103         # Server responded using protocol v1
104         grep "clone< version 1" log
105 '
106
107 test_expect_success 'fetch with file:// using protocol v1' '
108         test_commit -C file_parent two &&
109
110         GIT_TRACE_PACKET=1 git -C file_child -c protocol.version=1 \
111                 fetch 2>log &&
112
113         git -C file_child log -1 --format=%s origin/master >actual &&
114         git -C file_parent log -1 --format=%s >expect &&
115         test_cmp expect actual &&
116
117         # Server responded using protocol v1
118         grep "fetch< version 1" log
119 '
120
121 test_expect_success 'pull with file:// using protocol v1' '
122         GIT_TRACE_PACKET=1 git -C file_child -c protocol.version=1 \
123                 pull 2>log &&
124
125         git -C file_child log -1 --format=%s >actual &&
126         git -C file_parent log -1 --format=%s >expect &&
127         test_cmp expect actual &&
128
129         # Server responded using protocol v1
130         grep "fetch< version 1" log
131 '
132
133 test_expect_success 'push with file:// using protocol v1' '
134         test_commit -C file_child three &&
135
136         # Push to another branch, as the target repository has the
137         # master branch checked out and we cannot push into it.
138         GIT_TRACE_PACKET=1 git -C file_child -c protocol.version=1 \
139                 push origin HEAD:client_branch 2>log &&
140
141         git -C file_child log -1 --format=%s >actual &&
142         git -C file_parent log -1 --format=%s client_branch >expect &&
143         test_cmp expect actual &&
144
145         # Server responded using protocol v1
146         grep "push< version 1" log
147 '
148
149 # Test protocol v1 with 'ssh://' transport
150 #
151 test_expect_success 'setup ssh wrapper' '
152         GIT_SSH="$GIT_BUILD_DIR/t/helper/test-fake-ssh" &&
153         export GIT_SSH &&
154         GIT_SSH_VARIANT=ssh &&
155         export GIT_SSH_VARIANT &&
156         export TRASH_DIRECTORY &&
157         >"$TRASH_DIRECTORY"/ssh-output
158 '
159
160 expect_ssh () {
161         test_when_finished '(cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)' &&
162         echo "ssh: -o SendEnv=GIT_PROTOCOL myhost $1 '$PWD/ssh_parent'" >"$TRASH_DIRECTORY/ssh-expect" &&
163         (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output)
164 }
165
166 test_expect_success 'create repo to be served by ssh:// transport' '
167         git init ssh_parent &&
168         test_commit -C ssh_parent one
169 '
170
171 test_expect_success 'clone with ssh:// using protocol v1' '
172         GIT_TRACE_PACKET=1 git -c protocol.version=1 \
173                 clone "ssh://myhost:$(pwd)/ssh_parent" ssh_child 2>log &&
174         expect_ssh git-upload-pack &&
175
176         git -C ssh_child log -1 --format=%s >actual &&
177         git -C ssh_parent log -1 --format=%s >expect &&
178         test_cmp expect actual &&
179
180         # Server responded using protocol v1
181         grep "clone< version 1" log
182 '
183
184 test_expect_success 'fetch with ssh:// using protocol v1' '
185         test_commit -C ssh_parent two &&
186
187         GIT_TRACE_PACKET=1 git -C ssh_child -c protocol.version=1 \
188                 fetch 2>log &&
189         expect_ssh git-upload-pack &&
190
191         git -C ssh_child log -1 --format=%s origin/master >actual &&
192         git -C ssh_parent log -1 --format=%s >expect &&
193         test_cmp expect actual &&
194
195         # Server responded using protocol v1
196         grep "fetch< version 1" log
197 '
198
199 test_expect_success 'pull with ssh:// using protocol v1' '
200         GIT_TRACE_PACKET=1 git -C ssh_child -c protocol.version=1 \
201                 pull 2>log &&
202         expect_ssh git-upload-pack &&
203
204         git -C ssh_child log -1 --format=%s >actual &&
205         git -C ssh_parent log -1 --format=%s >expect &&
206         test_cmp expect actual &&
207
208         # Server responded using protocol v1
209         grep "fetch< version 1" log
210 '
211
212 test_expect_success 'push with ssh:// using protocol v1' '
213         test_commit -C ssh_child three &&
214
215         # Push to another branch, as the target repository has the
216         # master branch checked out and we cannot push into it.
217         GIT_TRACE_PACKET=1 git -C ssh_child -c protocol.version=1 \
218                 push origin HEAD:client_branch 2>log &&
219         expect_ssh git-receive-pack &&
220
221         git -C ssh_child log -1 --format=%s >actual &&
222         git -C ssh_parent log -1 --format=%s client_branch >expect &&
223         test_cmp expect actual &&
224
225         # Server responded using protocol v1
226         grep "push< version 1" log
227 '
228
229 # Test protocol v1 with 'http://' transport
230 #
231 . "$TEST_DIRECTORY"/lib-httpd.sh
232 start_httpd
233
234 test_expect_success 'create repo to be served by http:// transport' '
235         git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
236         git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config http.receivepack true &&
237         test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one
238 '
239
240 test_expect_success 'clone with http:// using protocol v1' '
241         GIT_TRACE_PACKET=1 GIT_TRACE_CURL=1 git -c protocol.version=1 \
242                 clone "$HTTPD_URL/smart/http_parent" http_child 2>log &&
243
244         git -C http_child log -1 --format=%s >actual &&
245         git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
246         test_cmp expect actual &&
247
248         # Client requested to use protocol v1
249         grep "Git-Protocol: version=1" log &&
250         # Server responded using protocol v1
251         grep "git< version 1" log
252 '
253
254 test_expect_success 'fetch with http:// using protocol v1' '
255         test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two &&
256
257         GIT_TRACE_PACKET=1 git -C http_child -c protocol.version=1 \
258                 fetch 2>log &&
259
260         git -C http_child log -1 --format=%s origin/master >actual &&
261         git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
262         test_cmp expect actual &&
263
264         # Server responded using protocol v1
265         grep "git< version 1" log
266 '
267
268 test_expect_success 'pull with http:// using protocol v1' '
269         GIT_TRACE_PACKET=1 git -C http_child -c protocol.version=1 \
270                 pull 2>log &&
271
272         git -C http_child log -1 --format=%s >actual &&
273         git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
274         test_cmp expect actual &&
275
276         # Server responded using protocol v1
277         grep "git< version 1" log
278 '
279
280 test_expect_success 'push with http:// using protocol v1' '
281         test_commit -C http_child three &&
282
283         # Push to another branch, as the target repository has the
284         # master branch checked out and we cannot push into it.
285         GIT_TRACE_PACKET=1 git -C http_child -c protocol.version=1 \
286                 push origin HEAD:client_branch && #2>log &&
287
288         git -C http_child log -1 --format=%s >actual &&
289         git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s client_branch >expect &&
290         test_cmp expect actual &&
291
292         # Server responded using protocol v1
293         grep "git< version 1" log
294 '
295
296 # DO NOT add non-httpd-specific tests here, because the last part of this
297 # test script is only executed when httpd is available and enabled.
298
299 test_done