Merge branch 'rs/commit-graph-code-simplification'
[git/debian.git] / t / t5700-protocol-v1.sh
blob022901b9eb6fdcaf3ff625b0db8056047946aa1a
1 #!/bin/sh
3 test_description='test git wire-protocol transition'
5 TEST_NO_CREATE_REPO=1
7 # This is a protocol-specific test.
8 GIT_TEST_PROTOCOL_VERSION=0
9 export GIT_TEST_PROTOCOL_VERSION
11 . ./test-lib.sh
13 # Test protocol v1 with 'git://' transport
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
19 test_expect_success 'create repo to be served by git-daemon' '
20 git init "$daemon_parent" &&
21 test_commit -C "$daemon_parent" one
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 &&
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 &&
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
38 test_expect_success 'fetch with git:// using protocol v1' '
39 test_commit -C "$daemon_parent" two &&
41 GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=1 \
42 fetch 2>log &&
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 &&
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
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 &&
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 &&
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
68 test_expect_success 'push with git:// using protocol v1' '
69 test_commit -C daemon_child three &&
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 &&
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 &&
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
86 stop_git_daemon
88 # Test protocol v1 with 'file://' transport
90 test_expect_success 'create repo to be served by file:// transport' '
91 git init file_parent &&
92 test_commit -C file_parent one
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 &&
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 &&
103 # Server responded using protocol v1
104 grep "clone< version 1" log
107 test_expect_success 'fetch with file:// using protocol v1' '
108 test_commit -C file_parent two &&
110 GIT_TRACE_PACKET=1 git -C file_child -c protocol.version=1 \
111 fetch 2>log &&
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 &&
117 # Server responded using protocol v1
118 grep "fetch< version 1" log
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 &&
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 &&
129 # Server responded using protocol v1
130 grep "fetch< version 1" log
133 test_expect_success 'push with file:// using protocol v1' '
134 test_commit -C file_child three &&
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 &&
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 &&
145 # Server responded using protocol v1
146 grep "push< version 1" log
149 # Test protocol v1 with 'ssh://' transport
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
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)
166 test_expect_success 'create repo to be served by ssh:// transport' '
167 git init ssh_parent &&
168 test_commit -C ssh_parent one
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 &&
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 &&
180 # Server responded using protocol v1
181 grep "clone< version 1" log
184 test_expect_success 'fetch with ssh:// using protocol v1' '
185 test_commit -C ssh_parent two &&
187 GIT_TRACE_PACKET=1 git -C ssh_child -c protocol.version=1 \
188 fetch 2>log &&
189 expect_ssh git-upload-pack &&
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 &&
195 # Server responded using protocol v1
196 grep "fetch< version 1" log
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 &&
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 &&
208 # Server responded using protocol v1
209 grep "fetch< version 1" log
212 test_expect_success 'push with ssh:// using protocol v1' '
213 test_commit -C ssh_child three &&
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 &&
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 &&
225 # Server responded using protocol v1
226 grep "push< version 1" log
229 # Test protocol v1 with 'http://' transport
231 . "$TEST_DIRECTORY"/lib-httpd.sh
232 start_httpd
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
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 &&
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 &&
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
254 test_expect_success 'fetch with http:// using protocol v1' '
255 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two &&
257 GIT_TRACE_PACKET=1 git -C http_child -c protocol.version=1 \
258 fetch 2>log &&
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 &&
264 # Server responded using protocol v1
265 grep "git< version 1" log
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 &&
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 &&
276 # Server responded using protocol v1
277 grep "git< version 1" log
280 test_expect_success 'push with http:// using protocol v1' '
281 test_commit -C http_child three &&
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 &&
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 &&
292 # Server responded using protocol v1
293 grep "git< version 1" log
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.
299 test_done