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