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