3 test_description='test git wire-protocol version 2'
9 # Test protocol v2 with 'git://' transport
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
15 test_expect_success 'create repo to be served by git-daemon' '
16 git init "$daemon_parent" &&
17 test_commit -C "$daemon_parent" one
20 test_expect_success 'list refs with git:// using protocol v2' '
21 GIT_TRACE_PACKET=1 git -c protocol.version=2 \
22 ls-remote --symref "$GIT_DAEMON_URL/parent" >actual 2>log &&
24 # Client requested to use protocol v2
25 grep "git> .*\\\0\\\0version=2\\\0$" log &&
26 # Server responded using protocol v2
27 grep "git< version 2" log &&
29 git ls-remote --symref "$GIT_DAEMON_URL/parent" >expect &&
30 test_cmp actual expect
33 test_expect_success 'ref advertisment is filtered with ls-remote using protocol v2' '
34 GIT_TRACE_PACKET=1 git -c protocol.version=2 \
35 ls-remote "$GIT_DAEMON_URL/parent" master 2>log &&
37 grep "ref-pattern master" log &&
38 ! grep "refs/tags/" log
41 test_expect_success 'clone with git:// using protocol v2' '
42 GIT_TRACE_PACKET=1 git -c protocol.version=2 \
43 clone "$GIT_DAEMON_URL/parent" daemon_child 2>log &&
45 git -C daemon_child log -1 --format=%s >actual &&
46 git -C "$daemon_parent" log -1 --format=%s >expect &&
47 test_cmp expect actual &&
49 # Client requested to use protocol v2
50 grep "clone> .*\\\0\\\0version=2\\\0$" log &&
51 # Server responded using protocol v2
52 grep "clone< version 2" log
55 test_expect_success 'fetch with git:// using protocol v2' '
56 test_commit -C "$daemon_parent" two &&
58 GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=2 \
61 git -C daemon_child log -1 --format=%s origin/master >actual &&
62 git -C "$daemon_parent" log -1 --format=%s >expect &&
63 test_cmp expect actual &&
65 # Client requested to use protocol v2
66 grep "fetch> .*\\\0\\\0version=2\\\0$" log &&
67 # Server responded using protocol v2
68 grep "fetch< version 2" log
71 test_expect_success 'pull with git:// using protocol v2' '
72 GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=2 \
75 git -C daemon_child log -1 --format=%s >actual &&
76 git -C "$daemon_parent" log -1 --format=%s >expect &&
77 test_cmp expect actual &&
79 # Client requested to use protocol v2
80 grep "fetch> .*\\\0\\\0version=2\\\0$" log &&
81 # Server responded using protocol v2
82 grep "fetch< version 2" log
85 test_expect_success 'push with git:// and a config of v2 does not request v2' '
86 # Till v2 for push is designed, make sure that if a client has
87 # protocol.version configured to use v2, that the client instead falls
90 test_commit -C daemon_child three &&
92 # Push to another branch, as the target repository has the
93 # master branch checked out and we cannot push into it.
94 GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=2 \
95 push origin HEAD:client_branch 2>log &&
97 git -C daemon_child log -1 --format=%s >actual &&
98 git -C "$daemon_parent" log -1 --format=%s client_branch >expect &&
99 test_cmp expect actual &&
101 # Client requested to use protocol v2
102 ! grep "push> .*\\\0\\\0version=2\\\0$" log &&
103 # Server responded using protocol v2
104 ! grep "push< version 2" log
109 # Test protocol v2 with 'file://' transport
111 test_expect_success 'create repo to be served by file:// transport' '
112 git init file_parent &&
113 test_commit -C file_parent one
116 test_expect_success 'list refs with file:// using protocol v2' '
117 GIT_TRACE_PACKET=1 git -c protocol.version=2 \
118 ls-remote --symref "file://$(pwd)/file_parent" >actual 2>log &&
120 # Server responded using protocol v2
121 grep "git< version 2" log &&
123 git ls-remote --symref "file://$(pwd)/file_parent" >expect &&
124 test_cmp actual expect
127 test_expect_success 'ref advertisment is filtered with ls-remote using protocol v2' '
128 GIT_TRACE_PACKET=1 git -c protocol.version=2 \
129 ls-remote "file://$(pwd)/file_parent" master 2>log &&
131 grep "ref-pattern master" log &&
132 ! grep "refs/tags/" log
135 test_expect_success 'clone with file:// using protocol v2' '
136 GIT_TRACE_PACKET=1 git -c protocol.version=2 \
137 clone "file://$(pwd)/file_parent" file_child 2>log &&
139 git -C file_child log -1 --format=%s >actual &&
140 git -C file_parent log -1 --format=%s >expect &&
141 test_cmp expect actual &&
143 # Server responded using protocol v2
144 grep "clone< version 2" log
147 test_expect_success 'fetch with file:// using protocol v2' '
148 test_commit -C file_parent two &&
150 GIT_TRACE_PACKET=1 git -C file_child -c protocol.version=2 \
151 fetch origin 2>log &&
153 git -C file_child log -1 --format=%s origin/master >actual &&
154 git -C file_parent log -1 --format=%s >expect &&
155 test_cmp expect actual &&
157 # Server responded using protocol v2
158 grep "fetch< version 2" log
161 test_expect_success 'ref advertisment is filtered during fetch using protocol v2' '
162 test_commit -C file_parent three &&
164 GIT_TRACE_PACKET=1 git -C file_child -c protocol.version=2 \
165 fetch origin master 2>log &&
167 git -C file_child log -1 --format=%s origin/master >actual &&
168 git -C file_parent log -1 --format=%s >expect &&
169 test_cmp expect actual &&
171 grep "ref-pattern master" log &&
172 ! grep "refs/tags/" log
175 # Test protocol v2 with 'http://' transport
177 . "$TEST_DIRECTORY"/lib-httpd.sh
180 test_expect_success 'create repo to be served by http:// transport' '
181 git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
182 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config http.receivepack true &&
183 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one
186 test_expect_success 'clone with http:// using protocol v2' '
187 GIT_TRACE_PACKET=1 GIT_TRACE_CURL=1 git -c protocol.version=2 \
188 clone "$HTTPD_URL/smart/http_parent" http_child 2>log &&
190 git -C http_child log -1 --format=%s >actual &&
191 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
192 test_cmp expect actual &&
194 # Client requested to use protocol v2
195 grep "Git-Protocol: version=2" log &&
196 # Server responded using protocol v2
197 grep "git< version 2" log
200 test_expect_success 'fetch with http:// using protocol v2' '
201 test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two &&
203 GIT_TRACE_PACKET=1 git -C http_child -c protocol.version=2 \
206 git -C http_child log -1 --format=%s origin/master >actual &&
207 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
208 test_cmp expect actual &&
210 # Server responded using protocol v2
211 grep "git< version 2" log
214 test_expect_success 'push with http:// and a config of v2 does not request v2' '
215 # Till v2 for push is designed, make sure that if a client has
216 # protocol.version configured to use v2, that the client instead falls
219 test_commit -C http_child three &&
221 # Push to another branch, as the target repository has the
222 # master branch checked out and we cannot push into it.
223 GIT_TRACE_PACKET=1 git -C http_child -c protocol.version=1 \
224 push origin HEAD:client_branch && 2>log &&
226 git -C http_child log -1 --format=%s >actual &&
227 git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s client_branch >expect &&
228 test_cmp expect actual &&
230 # Client didnt request to use protocol v2
231 ! grep "Git-Protocol: version=2" log &&
232 # Server didnt respond using protocol v2
233 ! grep "git< version 2" log