| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test git wire-protocol transition' |
| 4 | |
| 5 | TEST_NO_CREATE_REPO=1 |
| 6 | |
| 7 | # This is a protocol-specific test. |
| 8 | GIT_TEST_PROTOCOL_VERSION=0 |
| 9 | export GIT_TEST_PROTOCOL_VERSION |
| 10 | |
| 11 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 12 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 13 | |
| 14 | . ./test-lib.sh |
| 15 | |
| 16 | # Test protocol v1 with 'git://' transport |
| 17 | # |
| 18 | . "$TEST_DIRECTORY"/lib-git-daemon.sh |
| 19 | start_git_daemon --export-all --enable=receive-pack |
| 20 | daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent |
| 21 | |
| 22 | test_expect_success 'create repo to be served by git-daemon' ' |
| 23 | git init "$daemon_parent" && |
| 24 | test_commit -C "$daemon_parent" one |
| 25 | ' |
| 26 | |
| 27 | test_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 | test_grep "clone> .*\\\0\\\0version=1\\\0$" log && |
| 37 | # Server responded using protocol v1 |
| 38 | test_grep "clone< version 1" log |
| 39 | ' |
| 40 | |
| 41 | test_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 | |
| 47 | git -C daemon_child log -1 --format=%s origin/main >actual && |
| 48 | git -C "$daemon_parent" log -1 --format=%s >expect && |
| 49 | test_cmp expect actual && |
| 50 | |
| 51 | # Client requested to use protocol v1 |
| 52 | test_grep "fetch> .*\\\0\\\0version=1\\\0$" log && |
| 53 | # Server responded using protocol v1 |
| 54 | test_grep "fetch< version 1" log |
| 55 | ' |
| 56 | |
| 57 | test_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 | test_grep "fetch> .*\\\0\\\0version=1\\\0$" log && |
| 67 | # Server responded using protocol v1 |
| 68 | test_grep "fetch< version 1" log |
| 69 | ' |
| 70 | |
| 71 | test_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 |
| 75 | # main branch checked out and we cannot push into it. |
| 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 | test_grep "push> .*\\\0\\\0version=1\\\0$" log && |
| 85 | # Server responded using protocol v1 |
| 86 | test_grep "push< version 1" log |
| 87 | ' |
| 88 | |
| 89 | stop_git_daemon |
| 90 | |
| 91 | # Test protocol v1 with 'file://' transport |
| 92 | # |
| 93 | test_expect_success 'create repo to be served by file:// transport' ' |
| 94 | git init file_parent && |
| 95 | test_commit -C file_parent one |
| 96 | ' |
| 97 | |
| 98 | test_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 | test_grep "clone< version 1" log |
| 108 | ' |
| 109 | |
| 110 | test_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 | |
| 116 | git -C file_child log -1 --format=%s origin/main >actual && |
| 117 | git -C file_parent log -1 --format=%s >expect && |
| 118 | test_cmp expect actual && |
| 119 | |
| 120 | # Server responded using protocol v1 |
| 121 | test_grep "fetch< version 1" log |
| 122 | ' |
| 123 | |
| 124 | test_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 | test_grep "fetch< version 1" log |
| 134 | ' |
| 135 | |
| 136 | test_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 |
| 140 | # main branch checked out and we cannot push into it. |
| 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 | test_grep "push< version 1" log |
| 150 | ' |
| 151 | |
| 152 | test_expect_success 'cloning branchless tagless but not refless remote' ' |
| 153 | rm -rf server client && |
| 154 | |
| 155 | git -c init.defaultbranch=main init server && |
| 156 | echo foo >server/foo.txt && |
| 157 | git -C server add foo.txt && |
| 158 | git -C server commit -m "message" && |
| 159 | git -C server update-ref refs/notbranch/alsonottag HEAD && |
| 160 | git -C server checkout --detach && |
| 161 | git -C server branch -D main && |
| 162 | git -C server symbolic-ref HEAD refs/heads/nonexistentbranch && |
| 163 | |
| 164 | git -c protocol.version=1 clone "file://$(pwd)/server" client |
| 165 | ' |
| 166 | |
| 167 | # Test protocol v1 with 'ssh://' transport |
| 168 | # |
| 169 | test_expect_success 'setup ssh wrapper' ' |
| 170 | GIT_SSH="$GIT_BUILD_DIR/t/helper/test-fake-ssh" && |
| 171 | export GIT_SSH && |
| 172 | GIT_SSH_VARIANT=ssh && |
| 173 | export GIT_SSH_VARIANT && |
| 174 | export TRASH_DIRECTORY && |
| 175 | >"$TRASH_DIRECTORY"/ssh-output |
| 176 | ' |
| 177 | |
| 178 | expect_ssh () { |
| 179 | test_when_finished '(cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)' && |
| 180 | echo "ssh: -o SendEnv=GIT_PROTOCOL myhost $1 '$PWD/ssh_parent'" >"$TRASH_DIRECTORY/ssh-expect" && |
| 181 | (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output) |
| 182 | } |
| 183 | |
| 184 | test_expect_success 'create repo to be served by ssh:// transport' ' |
| 185 | git init ssh_parent && |
| 186 | test_commit -C ssh_parent one |
| 187 | ' |
| 188 | |
| 189 | test_expect_success 'clone with ssh:// using protocol v1' ' |
| 190 | GIT_TRACE_PACKET=1 git -c protocol.version=1 \ |
| 191 | clone "ssh://myhost:$(pwd)/ssh_parent" ssh_child 2>log && |
| 192 | expect_ssh git-upload-pack && |
| 193 | |
| 194 | git -C ssh_child log -1 --format=%s >actual && |
| 195 | git -C ssh_parent log -1 --format=%s >expect && |
| 196 | test_cmp expect actual && |
| 197 | |
| 198 | # Server responded using protocol v1 |
| 199 | test_grep "clone< version 1" log |
| 200 | ' |
| 201 | |
| 202 | test_expect_success 'fetch with ssh:// using protocol v1' ' |
| 203 | test_commit -C ssh_parent two && |
| 204 | |
| 205 | GIT_TRACE_PACKET=1 git -C ssh_child -c protocol.version=1 \ |
| 206 | fetch 2>log && |
| 207 | expect_ssh git-upload-pack && |
| 208 | |
| 209 | git -C ssh_child log -1 --format=%s origin/main >actual && |
| 210 | git -C ssh_parent log -1 --format=%s >expect && |
| 211 | test_cmp expect actual && |
| 212 | |
| 213 | # Server responded using protocol v1 |
| 214 | test_grep "fetch< version 1" log |
| 215 | ' |
| 216 | |
| 217 | test_expect_success 'pull with ssh:// using protocol v1' ' |
| 218 | GIT_TRACE_PACKET=1 git -C ssh_child -c protocol.version=1 \ |
| 219 | pull 2>log && |
| 220 | expect_ssh git-upload-pack && |
| 221 | |
| 222 | git -C ssh_child log -1 --format=%s >actual && |
| 223 | git -C ssh_parent log -1 --format=%s >expect && |
| 224 | test_cmp expect actual && |
| 225 | |
| 226 | # Server responded using protocol v1 |
| 227 | test_grep "fetch< version 1" log |
| 228 | ' |
| 229 | |
| 230 | test_expect_success 'push with ssh:// using protocol v1' ' |
| 231 | test_commit -C ssh_child three && |
| 232 | |
| 233 | # Push to another branch, as the target repository has the |
| 234 | # main branch checked out and we cannot push into it. |
| 235 | GIT_TRACE_PACKET=1 git -C ssh_child -c protocol.version=1 \ |
| 236 | push origin HEAD:client_branch 2>log && |
| 237 | expect_ssh git-receive-pack && |
| 238 | |
| 239 | git -C ssh_child log -1 --format=%s >actual && |
| 240 | git -C ssh_parent log -1 --format=%s client_branch >expect && |
| 241 | test_cmp expect actual && |
| 242 | |
| 243 | # Server responded using protocol v1 |
| 244 | test_grep "push< version 1" log |
| 245 | ' |
| 246 | |
| 247 | test_expect_success 'clone propagates object-format from empty repo' ' |
| 248 | test_when_finished "rm -fr src256 dst256" && |
| 249 | |
| 250 | echo sha256 >expect && |
| 251 | git init --object-format=sha256 src256 && |
| 252 | git clone --no-local src256 dst256 && |
| 253 | git -C dst256 rev-parse --show-object-format >actual && |
| 254 | |
| 255 | test_cmp expect actual |
| 256 | ' |
| 257 | |
| 258 | # Test protocol v1 with 'http://' transport |
| 259 | # |
| 260 | . "$TEST_DIRECTORY"/lib-httpd.sh |
| 261 | start_httpd |
| 262 | |
| 263 | test_expect_success 'create repos to be served by http:// transport' ' |
| 264 | git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && |
| 265 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config http.receivepack true && |
| 266 | test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one && |
| 267 | git init --object-format=sha256 "$HTTPD_DOCUMENT_ROOT_PATH/sha256" && |
| 268 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/sha256" config http.receivepack true |
| 269 | ' |
| 270 | |
| 271 | test_expect_success 'clone with http:// using protocol v1' ' |
| 272 | GIT_TRACE_PACKET=1 GIT_TRACE_CURL=1 git -c protocol.version=1 \ |
| 273 | clone "$HTTPD_URL/smart/http_parent" http_child 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 | # Client requested to use protocol v1 |
| 280 | test_grep "Git-Protocol: version=1" log && |
| 281 | # Server responded using protocol v1 |
| 282 | test_grep "git< version 1" log |
| 283 | ' |
| 284 | |
| 285 | test_expect_success 'clone with http:// using protocol v1 with empty SHA-256 repo' ' |
| 286 | GIT_TRACE_PACKET=1 GIT_TRACE_CURL=1 git -c protocol.version=1 \ |
| 287 | clone "$HTTPD_URL/smart/sha256" sha256 2>log && |
| 288 | |
| 289 | echo sha256 >expect && |
| 290 | git -C sha256 rev-parse --show-object-format >actual && |
| 291 | test_cmp expect actual && |
| 292 | |
| 293 | # Client requested to use protocol v1 |
| 294 | test_grep "Git-Protocol: version=1" log && |
| 295 | # Server responded using protocol v1 |
| 296 | test_grep "git< version 1" log |
| 297 | ' |
| 298 | |
| 299 | test_expect_success 'fetch with http:// using protocol v1' ' |
| 300 | test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two && |
| 301 | |
| 302 | GIT_TRACE_PACKET=1 git -C http_child -c protocol.version=1 \ |
| 303 | fetch 2>log && |
| 304 | |
| 305 | git -C http_child log -1 --format=%s origin/main >actual && |
| 306 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect && |
| 307 | test_cmp expect actual && |
| 308 | |
| 309 | # Server responded using protocol v1 |
| 310 | test_grep "git< version 1" log |
| 311 | ' |
| 312 | |
| 313 | test_expect_success 'pull with http:// using protocol v1' ' |
| 314 | GIT_TRACE_PACKET=1 git -C http_child -c protocol.version=1 \ |
| 315 | pull 2>log && |
| 316 | |
| 317 | git -C http_child log -1 --format=%s >actual && |
| 318 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect && |
| 319 | test_cmp expect actual && |
| 320 | |
| 321 | # Server responded using protocol v1 |
| 322 | test_grep "git< version 1" log |
| 323 | ' |
| 324 | |
| 325 | test_expect_success 'push with http:// using protocol v1' ' |
| 326 | test_commit -C http_child three && |
| 327 | |
| 328 | # Push to another branch, as the target repository has the |
| 329 | # main branch checked out and we cannot push into it. |
| 330 | GIT_TRACE_PACKET=1 git -C http_child -c protocol.version=1 \ |
| 331 | push origin HEAD:client_branch && #2>log && |
| 332 | |
| 333 | git -C http_child log -1 --format=%s >actual && |
| 334 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s client_branch >expect && |
| 335 | test_cmp expect actual && |
| 336 | |
| 337 | # Server responded using protocol v1 |
| 338 | test_grep "git< version 1" log |
| 339 | ' |
| 340 | |
| 341 | # DO NOT add non-httpd-specific tests here, because the last part of this |
| 342 | # test script is only executed when httpd is available and enabled. |
| 343 | |
| 344 | test_done |