Brandon Williams | e52449b | 2018-03-15 10:31:21 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test git wire-protocol version 2' |
| 4 | |
| 5 | TEST_NO_CREATE_REPO=1 |
| 6 | |
| 7 | . ./test-lib.sh |
| 8 | |
| 9 | # Test protocol v2 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 'list refs with git:// using protocol v2' ' |
| 21 | test_when_finished "rm -f log" && |
| 22 | |
| 23 | GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \ |
| 24 | ls-remote --symref "$GIT_DAEMON_URL/parent" >actual && |
| 25 | |
| 26 | # Client requested to use protocol v2 |
| 27 | grep "git> .*\\\0\\\0version=2\\\0$" log && |
| 28 | # Server responded using protocol v2 |
| 29 | grep "git< version 2" log && |
| 30 | |
| 31 | git ls-remote --symref "$GIT_DAEMON_URL/parent" >expect && |
| 32 | test_cmp actual expect |
| 33 | ' |
| 34 | |
Brandon Williams | b4be741 | 2018-03-15 10:31:24 -0700 | [diff] [blame] | 35 | test_expect_success 'ref advertisment is filtered with ls-remote using protocol v2' ' |
| 36 | test_when_finished "rm -f log" && |
| 37 | |
| 38 | GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \ |
| 39 | ls-remote "$GIT_DAEMON_URL/parent" master >actual && |
| 40 | |
| 41 | cat >expect <<-EOF && |
| 42 | $(git -C "$daemon_parent" rev-parse refs/heads/master)$(printf "\t")refs/heads/master |
| 43 | EOF |
| 44 | |
| 45 | test_cmp actual expect |
| 46 | ' |
| 47 | |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 48 | test_expect_success 'clone with git:// using protocol v2' ' |
| 49 | test_when_finished "rm -f log" && |
| 50 | |
| 51 | GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \ |
| 52 | clone "$GIT_DAEMON_URL/parent" daemon_child && |
| 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 v2 |
| 59 | grep "clone> .*\\\0\\\0version=2\\\0$" log && |
| 60 | # Server responded using protocol v2 |
| 61 | grep "clone< version 2" log |
| 62 | ' |
| 63 | |
| 64 | test_expect_success 'fetch with git:// using protocol v2' ' |
| 65 | test_when_finished "rm -f log" && |
| 66 | |
| 67 | test_commit -C "$daemon_parent" two && |
| 68 | |
| 69 | GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \ |
| 70 | fetch && |
| 71 | |
| 72 | git -C daemon_child log -1 --format=%s origin/master >actual && |
| 73 | git -C "$daemon_parent" log -1 --format=%s >expect && |
| 74 | test_cmp expect actual && |
| 75 | |
| 76 | # Client requested to use protocol v2 |
| 77 | grep "fetch> .*\\\0\\\0version=2\\\0$" log && |
| 78 | # Server responded using protocol v2 |
| 79 | grep "fetch< version 2" log |
| 80 | ' |
| 81 | |
| 82 | test_expect_success 'pull with git:// using protocol v2' ' |
| 83 | test_when_finished "rm -f log" && |
| 84 | |
| 85 | GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \ |
| 86 | pull && |
| 87 | |
| 88 | git -C daemon_child log -1 --format=%s >actual && |
| 89 | git -C "$daemon_parent" log -1 --format=%s >expect && |
| 90 | test_cmp expect actual && |
| 91 | |
| 92 | # Client requested to use protocol v2 |
| 93 | grep "fetch> .*\\\0\\\0version=2\\\0$" log && |
| 94 | # Server responded using protocol v2 |
| 95 | grep "fetch< version 2" log |
| 96 | ' |
| 97 | |
Brandon Williams | 1aa8dded | 2018-03-15 10:31:31 -0700 | [diff] [blame] | 98 | test_expect_success 'push with git:// and a config of v2 does not request v2' ' |
| 99 | test_when_finished "rm -f log" && |
| 100 | |
| 101 | # Till v2 for push is designed, make sure that if a client has |
| 102 | # protocol.version configured to use v2, that the client instead falls |
| 103 | # back and uses v0. |
| 104 | |
| 105 | test_commit -C daemon_child three && |
| 106 | |
| 107 | # Push to another branch, as the target repository has the |
| 108 | # master branch checked out and we cannot push into it. |
| 109 | GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \ |
| 110 | push origin HEAD:client_branch && |
| 111 | |
| 112 | git -C daemon_child log -1 --format=%s >actual && |
| 113 | git -C "$daemon_parent" log -1 --format=%s client_branch >expect && |
| 114 | test_cmp expect actual && |
| 115 | |
| 116 | # Client requested to use protocol v2 |
| 117 | ! grep "push> .*\\\0\\\0version=2\\\0$" log && |
| 118 | # Server responded using protocol v2 |
| 119 | ! grep "push< version 2" log |
| 120 | ' |
| 121 | |
Brandon Williams | e52449b | 2018-03-15 10:31:21 -0700 | [diff] [blame] | 122 | stop_git_daemon |
| 123 | |
| 124 | # Test protocol v2 with 'file://' transport |
| 125 | # |
| 126 | test_expect_success 'create repo to be served by file:// transport' ' |
| 127 | git init file_parent && |
| 128 | test_commit -C file_parent one |
| 129 | ' |
| 130 | |
| 131 | test_expect_success 'list refs with file:// using protocol v2' ' |
| 132 | test_when_finished "rm -f log" && |
| 133 | |
| 134 | GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \ |
| 135 | ls-remote --symref "file://$(pwd)/file_parent" >actual && |
| 136 | |
| 137 | # Server responded using protocol v2 |
| 138 | grep "git< version 2" log && |
| 139 | |
| 140 | git ls-remote --symref "file://$(pwd)/file_parent" >expect && |
| 141 | test_cmp actual expect |
| 142 | ' |
| 143 | |
Brandon Williams | b4be741 | 2018-03-15 10:31:24 -0700 | [diff] [blame] | 144 | test_expect_success 'ref advertisment is filtered with ls-remote using protocol v2' ' |
| 145 | test_when_finished "rm -f log" && |
| 146 | |
| 147 | GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \ |
| 148 | ls-remote "file://$(pwd)/file_parent" master >actual && |
| 149 | |
| 150 | cat >expect <<-EOF && |
| 151 | $(git -C file_parent rev-parse refs/heads/master)$(printf "\t")refs/heads/master |
| 152 | EOF |
| 153 | |
| 154 | test_cmp actual expect |
| 155 | ' |
| 156 | |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 157 | test_expect_success 'clone with file:// using protocol v2' ' |
| 158 | test_when_finished "rm -f log" && |
| 159 | |
| 160 | GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \ |
| 161 | clone "file://$(pwd)/file_parent" file_child && |
| 162 | |
| 163 | git -C file_child log -1 --format=%s >actual && |
| 164 | git -C file_parent log -1 --format=%s >expect && |
| 165 | test_cmp expect actual && |
| 166 | |
| 167 | # Server responded using protocol v2 |
| 168 | grep "clone< version 2" log |
| 169 | ' |
| 170 | |
| 171 | test_expect_success 'fetch with file:// using protocol v2' ' |
| 172 | test_when_finished "rm -f log" && |
| 173 | |
| 174 | test_commit -C file_parent two && |
| 175 | |
| 176 | GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \ |
| 177 | fetch origin && |
| 178 | |
| 179 | git -C file_child log -1 --format=%s origin/master >actual && |
| 180 | git -C file_parent log -1 --format=%s >expect && |
| 181 | test_cmp expect actual && |
| 182 | |
| 183 | # Server responded using protocol v2 |
| 184 | grep "fetch< version 2" log |
| 185 | ' |
| 186 | |
| 187 | test_expect_success 'ref advertisment is filtered during fetch using protocol v2' ' |
| 188 | test_when_finished "rm -f log" && |
| 189 | |
| 190 | test_commit -C file_parent three && |
| 191 | |
| 192 | GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \ |
| 193 | fetch origin master && |
| 194 | |
| 195 | git -C file_child log -1 --format=%s origin/master >actual && |
| 196 | git -C file_parent log -1 --format=%s >expect && |
| 197 | test_cmp expect actual && |
| 198 | |
| 199 | ! grep "refs/tags/one" log && |
| 200 | ! grep "refs/tags/two" log && |
| 201 | ! grep "refs/tags/three" log |
| 202 | ' |
| 203 | |
Brandon Williams | dcc73cf | 2018-05-16 16:48:22 -0700 | [diff] [blame^] | 204 | test_expect_success 'default refspec is used to filter ref when fetchcing' ' |
| 205 | test_when_finished "rm -f log" && |
| 206 | |
| 207 | GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \ |
| 208 | fetch origin && |
| 209 | |
| 210 | git -C file_child log -1 --format=%s three >actual && |
| 211 | git -C file_parent log -1 --format=%s three >expect && |
| 212 | test_cmp expect actual && |
| 213 | |
| 214 | grep "ref-prefix refs/heads/" log && |
| 215 | grep "ref-prefix refs/tags/" log |
| 216 | ' |
| 217 | |
Brandon Williams | 0f1dc53 | 2018-03-15 10:31:41 -0700 | [diff] [blame] | 218 | # Test protocol v2 with 'http://' transport |
| 219 | # |
| 220 | . "$TEST_DIRECTORY"/lib-httpd.sh |
| 221 | start_httpd |
| 222 | |
| 223 | test_expect_success 'create repo to be served by http:// transport' ' |
| 224 | git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && |
| 225 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config http.receivepack true && |
| 226 | test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one |
| 227 | ' |
| 228 | |
| 229 | test_expect_success 'clone with http:// using protocol v2' ' |
| 230 | test_when_finished "rm -f log" && |
| 231 | |
| 232 | GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \ |
| 233 | clone "$HTTPD_URL/smart/http_parent" http_child && |
| 234 | |
| 235 | git -C http_child log -1 --format=%s >actual && |
| 236 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect && |
| 237 | test_cmp expect actual && |
| 238 | |
| 239 | # Client requested to use protocol v2 |
| 240 | grep "Git-Protocol: version=2" log && |
| 241 | # Server responded using protocol v2 |
| 242 | grep "git< version 2" log |
| 243 | ' |
| 244 | |
| 245 | test_expect_success 'fetch with http:// using protocol v2' ' |
| 246 | test_when_finished "rm -f log" && |
| 247 | |
| 248 | test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two && |
| 249 | |
| 250 | GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \ |
| 251 | fetch && |
| 252 | |
| 253 | git -C http_child log -1 --format=%s origin/master >actual && |
| 254 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect && |
| 255 | test_cmp expect actual && |
| 256 | |
| 257 | # Server responded using protocol v2 |
| 258 | grep "git< version 2" log |
| 259 | ' |
| 260 | |
Brandon Williams | a4d78ce | 2018-03-15 10:31:42 -0700 | [diff] [blame] | 261 | test_expect_success 'push with http:// and a config of v2 does not request v2' ' |
| 262 | test_when_finished "rm -f log" && |
| 263 | # Till v2 for push is designed, make sure that if a client has |
| 264 | # protocol.version configured to use v2, that the client instead falls |
| 265 | # back and uses v0. |
| 266 | |
| 267 | test_commit -C http_child three && |
| 268 | |
| 269 | # Push to another branch, as the target repository has the |
| 270 | # master branch checked out and we cannot push into it. |
| 271 | GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \ |
| 272 | push origin HEAD:client_branch && |
| 273 | |
| 274 | git -C http_child log -1 --format=%s >actual && |
| 275 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s client_branch >expect && |
| 276 | test_cmp expect actual && |
| 277 | |
| 278 | # Client didnt request to use protocol v2 |
| 279 | ! grep "Git-Protocol: version=2" log && |
| 280 | # Server didnt respond using protocol v2 |
| 281 | ! grep "git< version 2" log |
| 282 | ' |
| 283 | |
| 284 | |
Brandon Williams | 0f1dc53 | 2018-03-15 10:31:41 -0700 | [diff] [blame] | 285 | stop_httpd |
| 286 | |
Brandon Williams | e52449b | 2018-03-15 10:31:21 -0700 | [diff] [blame] | 287 | test_done |