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