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 | |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 7 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 8 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 9 | |
Brandon Williams | e52449b | 2018-03-15 10:31:21 -0700 | [diff] [blame] | 10 | . ./test-lib.sh |
| 11 | |
| 12 | # Test protocol v2 with 'git://' transport |
| 13 | # |
| 14 | . "$TEST_DIRECTORY"/lib-git-daemon.sh |
| 15 | start_git_daemon --export-all --enable=receive-pack |
| 16 | daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent |
| 17 | |
| 18 | test_expect_success 'create repo to be served by git-daemon' ' |
| 19 | git init "$daemon_parent" && |
| 20 | test_commit -C "$daemon_parent" one |
| 21 | ' |
| 22 | |
| 23 | test_expect_success 'list refs with git:// using protocol v2' ' |
| 24 | test_when_finished "rm -f log" && |
| 25 | |
| 26 | GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \ |
| 27 | ls-remote --symref "$GIT_DAEMON_URL/parent" >actual && |
| 28 | |
| 29 | # Client requested to use protocol v2 |
Ævar Arnfjörð Bjarmason | f58c746 | 2021-08-23 15:17:49 +0200 | [diff] [blame] | 30 | grep "ls-remote> .*\\\0\\\0version=2\\\0$" log && |
Brandon Williams | e52449b | 2018-03-15 10:31:21 -0700 | [diff] [blame] | 31 | # Server responded using protocol v2 |
Ævar Arnfjörð Bjarmason | f58c746 | 2021-08-23 15:17:49 +0200 | [diff] [blame] | 32 | grep "ls-remote< version 2" log && |
Brandon Williams | e52449b | 2018-03-15 10:31:21 -0700 | [diff] [blame] | 33 | |
| 34 | git ls-remote --symref "$GIT_DAEMON_URL/parent" >expect && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 35 | test_cmp expect actual |
Brandon Williams | e52449b | 2018-03-15 10:31:21 -0700 | [diff] [blame] | 36 | ' |
| 37 | |
Elijah Newren | 4dc8b1c | 2019-11-05 17:07:25 +0000 | [diff] [blame] | 38 | test_expect_success 'ref advertisement is filtered with ls-remote using protocol v2' ' |
Brandon Williams | b4be741 | 2018-03-15 10:31:24 -0700 | [diff] [blame] | 39 | test_when_finished "rm -f log" && |
| 40 | |
| 41 | GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \ |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 42 | ls-remote "$GIT_DAEMON_URL/parent" main >actual && |
Brandon Williams | b4be741 | 2018-03-15 10:31:24 -0700 | [diff] [blame] | 43 | |
| 44 | cat >expect <<-EOF && |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 45 | $(git -C "$daemon_parent" rev-parse refs/heads/main)$(printf "\t")refs/heads/main |
Brandon Williams | b4be741 | 2018-03-15 10:31:24 -0700 | [diff] [blame] | 46 | EOF |
| 47 | |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 48 | test_cmp expect actual |
Brandon Williams | b4be741 | 2018-03-15 10:31:24 -0700 | [diff] [blame] | 49 | ' |
| 50 | |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 51 | test_expect_success 'clone with git:// using protocol v2' ' |
| 52 | test_when_finished "rm -f log" && |
| 53 | |
| 54 | GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \ |
| 55 | clone "$GIT_DAEMON_URL/parent" daemon_child && |
| 56 | |
| 57 | git -C daemon_child log -1 --format=%s >actual && |
| 58 | git -C "$daemon_parent" log -1 --format=%s >expect && |
| 59 | test_cmp expect actual && |
| 60 | |
| 61 | # Client requested to use protocol v2 |
| 62 | grep "clone> .*\\\0\\\0version=2\\\0$" log && |
| 63 | # Server responded using protocol v2 |
| 64 | grep "clone< version 2" log |
| 65 | ' |
| 66 | |
| 67 | test_expect_success 'fetch with git:// using protocol v2' ' |
| 68 | test_when_finished "rm -f log" && |
| 69 | |
| 70 | test_commit -C "$daemon_parent" two && |
| 71 | |
| 72 | GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \ |
| 73 | fetch && |
| 74 | |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 75 | git -C daemon_child log -1 --format=%s origin/main >actual && |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 76 | git -C "$daemon_parent" log -1 --format=%s >expect && |
| 77 | test_cmp expect actual && |
| 78 | |
| 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 |
| 83 | ' |
| 84 | |
Jonathan Tan | e70a303 | 2018-09-27 12:24:07 -0700 | [diff] [blame] | 85 | test_expect_success 'fetch by hash without tag following with protocol v2 does not list refs' ' |
| 86 | test_when_finished "rm -f log" && |
| 87 | |
| 88 | test_commit -C "$daemon_parent" two_a && |
| 89 | git -C "$daemon_parent" rev-parse two_a >two_a_hash && |
| 90 | |
| 91 | GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \ |
| 92 | fetch --no-tags origin $(cat two_a_hash) && |
| 93 | |
| 94 | grep "fetch< version 2" log && |
| 95 | ! grep "fetch> command=ls-refs" log |
| 96 | ' |
| 97 | |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 98 | test_expect_success 'pull with git:// using protocol v2' ' |
| 99 | test_when_finished "rm -f log" && |
| 100 | |
| 101 | GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \ |
| 102 | pull && |
| 103 | |
| 104 | git -C daemon_child log -1 --format=%s >actual && |
| 105 | git -C "$daemon_parent" log -1 --format=%s >expect && |
| 106 | test_cmp expect actual && |
| 107 | |
| 108 | # Client requested to use protocol v2 |
| 109 | grep "fetch> .*\\\0\\\0version=2\\\0$" log && |
| 110 | # Server responded using protocol v2 |
| 111 | grep "fetch< version 2" log |
| 112 | ' |
| 113 | |
Brandon Williams | 1aa8dded | 2018-03-15 10:31:31 -0700 | [diff] [blame] | 114 | test_expect_success 'push with git:// and a config of v2 does not request v2' ' |
| 115 | test_when_finished "rm -f log" && |
| 116 | |
| 117 | # Till v2 for push is designed, make sure that if a client has |
| 118 | # protocol.version configured to use v2, that the client instead falls |
| 119 | # back and uses v0. |
| 120 | |
| 121 | test_commit -C daemon_child three && |
| 122 | |
| 123 | # Push to another branch, as the target repository has the |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 124 | # main branch checked out and we cannot push into it. |
Brandon Williams | 1aa8dded | 2018-03-15 10:31:31 -0700 | [diff] [blame] | 125 | GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \ |
| 126 | push origin HEAD:client_branch && |
| 127 | |
| 128 | git -C daemon_child log -1 --format=%s >actual && |
| 129 | git -C "$daemon_parent" log -1 --format=%s client_branch >expect && |
| 130 | test_cmp expect actual && |
| 131 | |
| 132 | # Client requested to use protocol v2 |
| 133 | ! grep "push> .*\\\0\\\0version=2\\\0$" log && |
| 134 | # Server responded using protocol v2 |
| 135 | ! grep "push< version 2" log |
| 136 | ' |
| 137 | |
Brandon Williams | e52449b | 2018-03-15 10:31:21 -0700 | [diff] [blame] | 138 | stop_git_daemon |
| 139 | |
| 140 | # Test protocol v2 with 'file://' transport |
| 141 | # |
| 142 | test_expect_success 'create repo to be served by file:// transport' ' |
| 143 | git init file_parent && |
| 144 | test_commit -C file_parent one |
| 145 | ' |
| 146 | |
| 147 | test_expect_success 'list refs with file:// using protocol v2' ' |
| 148 | test_when_finished "rm -f log" && |
| 149 | |
| 150 | GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \ |
| 151 | ls-remote --symref "file://$(pwd)/file_parent" >actual && |
| 152 | |
| 153 | # Server responded using protocol v2 |
Ævar Arnfjörð Bjarmason | f58c746 | 2021-08-23 15:17:49 +0200 | [diff] [blame] | 154 | grep "ls-remote< version 2" log && |
Brandon Williams | e52449b | 2018-03-15 10:31:21 -0700 | [diff] [blame] | 155 | |
| 156 | git ls-remote --symref "file://$(pwd)/file_parent" >expect && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 157 | test_cmp expect actual |
Brandon Williams | e52449b | 2018-03-15 10:31:21 -0700 | [diff] [blame] | 158 | ' |
| 159 | |
Elijah Newren | 4dc8b1c | 2019-11-05 17:07:25 +0000 | [diff] [blame] | 160 | test_expect_success 'ref advertisement is filtered with ls-remote using protocol v2' ' |
Brandon Williams | b4be741 | 2018-03-15 10:31:24 -0700 | [diff] [blame] | 161 | test_when_finished "rm -f log" && |
| 162 | |
| 163 | GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \ |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 164 | ls-remote "file://$(pwd)/file_parent" main >actual && |
Brandon Williams | b4be741 | 2018-03-15 10:31:24 -0700 | [diff] [blame] | 165 | |
| 166 | cat >expect <<-EOF && |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 167 | $(git -C file_parent rev-parse refs/heads/main)$(printf "\t")refs/heads/main |
Brandon Williams | b4be741 | 2018-03-15 10:31:24 -0700 | [diff] [blame] | 168 | EOF |
| 169 | |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 170 | test_cmp expect actual |
Brandon Williams | b4be741 | 2018-03-15 10:31:24 -0700 | [diff] [blame] | 171 | ' |
| 172 | |
Brandon Williams | ff47322 | 2018-04-23 15:46:23 -0700 | [diff] [blame] | 173 | test_expect_success 'server-options are sent when using ls-remote' ' |
| 174 | test_when_finished "rm -f log" && |
| 175 | |
| 176 | GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \ |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 177 | ls-remote -o hello -o world "file://$(pwd)/file_parent" main >actual && |
Brandon Williams | ff47322 | 2018-04-23 15:46:23 -0700 | [diff] [blame] | 178 | |
| 179 | cat >expect <<-EOF && |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 180 | $(git -C file_parent rev-parse refs/heads/main)$(printf "\t")refs/heads/main |
Brandon Williams | ff47322 | 2018-04-23 15:46:23 -0700 | [diff] [blame] | 181 | EOF |
| 182 | |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 183 | test_cmp expect actual && |
Brandon Williams | ff47322 | 2018-04-23 15:46:23 -0700 | [diff] [blame] | 184 | grep "server-option=hello" log && |
| 185 | grep "server-option=world" log |
| 186 | ' |
| 187 | |
Jonathan Tan | 35eb824 | 2019-04-12 12:51:21 -0700 | [diff] [blame] | 188 | test_expect_success 'warn if using server-option with ls-remote with legacy protocol' ' |
| 189 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -c protocol.version=0 \ |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 190 | ls-remote -o hello -o world "file://$(pwd)/file_parent" main 2>err && |
Jonathan Tan | 35eb824 | 2019-04-12 12:51:21 -0700 | [diff] [blame] | 191 | |
| 192 | test_i18ngrep "see protocol.version in" err && |
| 193 | test_i18ngrep "server options require protocol version 2 or later" err |
| 194 | ' |
Brandon Williams | ff47322 | 2018-04-23 15:46:23 -0700 | [diff] [blame] | 195 | |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 196 | test_expect_success 'clone with file:// using protocol v2' ' |
| 197 | test_when_finished "rm -f log" && |
| 198 | |
| 199 | GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \ |
| 200 | clone "file://$(pwd)/file_parent" file_child && |
| 201 | |
| 202 | git -C file_child log -1 --format=%s >actual && |
| 203 | git -C file_parent log -1 --format=%s >expect && |
| 204 | test_cmp expect actual && |
| 205 | |
| 206 | # Server responded using protocol v2 |
Brandon Williams | 402c47d | 2018-07-20 15:07:54 -0700 | [diff] [blame] | 207 | grep "clone< version 2" log && |
| 208 | |
| 209 | # Client sent ref-prefixes to filter the ref-advertisement |
| 210 | grep "ref-prefix HEAD" log && |
| 211 | grep "ref-prefix refs/heads/" log && |
| 212 | grep "ref-prefix refs/tags/" log |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 213 | ' |
| 214 | |
Jonathan Tan | 4f37d45 | 2021-02-05 12:48:49 -0800 | [diff] [blame] | 215 | test_expect_success 'clone of empty repo propagates name of default branch' ' |
| 216 | test_when_finished "rm -rf file_empty_parent file_empty_child" && |
| 217 | |
| 218 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ |
| 219 | git -c init.defaultBranch=mydefaultbranch init file_empty_parent && |
| 220 | |
| 221 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ |
| 222 | git -c init.defaultBranch=main -c protocol.version=2 \ |
| 223 | clone "file://$(pwd)/file_empty_parent" file_empty_child && |
| 224 | grep "refs/heads/mydefaultbranch" file_empty_child/.git/HEAD |
| 225 | ' |
| 226 | |
| 227 | test_expect_success '...but not if explicitly forbidden by config' ' |
| 228 | test_when_finished "rm -rf file_empty_parent file_empty_child" && |
| 229 | |
| 230 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ |
| 231 | git -c init.defaultBranch=mydefaultbranch init file_empty_parent && |
| 232 | test_config -C file_empty_parent lsrefs.unborn ignore && |
| 233 | |
| 234 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ |
| 235 | git -c init.defaultBranch=main -c protocol.version=2 \ |
| 236 | clone "file://$(pwd)/file_empty_parent" file_empty_child && |
| 237 | ! grep "refs/heads/mydefaultbranch" file_empty_child/.git/HEAD |
| 238 | ' |
| 239 | |
Jeff King | 6b58df5 | 2021-09-20 15:04:10 -0400 | [diff] [blame] | 240 | test_expect_success 'bare clone propagates empty default branch' ' |
| 241 | test_when_finished "rm -rf file_empty_parent file_empty_child.git" && |
| 242 | |
| 243 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ |
| 244 | git -c init.defaultBranch=mydefaultbranch init file_empty_parent && |
| 245 | |
| 246 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ |
| 247 | git -c init.defaultBranch=main -c protocol.version=2 \ |
| 248 | clone --bare \ |
| 249 | "file://$(pwd)/file_empty_parent" file_empty_child.git && |
| 250 | grep "refs/heads/mydefaultbranch" file_empty_child.git/HEAD |
| 251 | ' |
| 252 | |
Jeff King | 3d8314f | 2022-07-07 19:57:45 -0400 | [diff] [blame] | 253 | test_expect_success 'clone propagates unborn HEAD from non-empty repo' ' |
| 254 | test_when_finished "rm -rf file_unborn_parent file_unborn_child" && |
| 255 | |
| 256 | git init file_unborn_parent && |
| 257 | ( |
| 258 | cd file_unborn_parent && |
| 259 | git checkout -b branchwithstuff && |
| 260 | test_commit --no-tag stuff && |
| 261 | git symbolic-ref HEAD refs/heads/mydefaultbranch |
| 262 | ) && |
| 263 | |
| 264 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ |
| 265 | git -c init.defaultBranch=main -c protocol.version=2 \ |
| 266 | clone "file://$(pwd)/file_unborn_parent" \ |
| 267 | file_unborn_child 2>stderr && |
| 268 | grep "refs/heads/mydefaultbranch" file_unborn_child/.git/HEAD && |
| 269 | grep "warning: remote HEAD refers to nonexistent ref" stderr |
| 270 | ' |
| 271 | |
| 272 | test_expect_success 'bare clone propagates unborn HEAD from non-empty repo' ' |
| 273 | test_when_finished "rm -rf file_unborn_parent file_unborn_child.git" && |
| 274 | |
| 275 | git init file_unborn_parent && |
| 276 | ( |
| 277 | cd file_unborn_parent && |
| 278 | git checkout -b branchwithstuff && |
| 279 | test_commit --no-tag stuff && |
| 280 | git symbolic-ref HEAD refs/heads/mydefaultbranch |
| 281 | ) && |
| 282 | |
| 283 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ |
| 284 | git -c init.defaultBranch=main -c protocol.version=2 \ |
| 285 | clone --bare "file://$(pwd)/file_unborn_parent" \ |
| 286 | file_unborn_child.git 2>stderr && |
| 287 | grep "refs/heads/mydefaultbranch" file_unborn_child.git/HEAD && |
| 288 | ! grep "warning:" stderr |
| 289 | ' |
| 290 | |
Jeff King | cc8fcd1 | 2022-07-07 19:59:35 -0400 | [diff] [blame] | 291 | test_expect_success 'defaulted HEAD uses remote branch if available' ' |
| 292 | test_when_finished "rm -rf file_unborn_parent file_unborn_child" && |
| 293 | |
| 294 | git init file_unborn_parent && |
| 295 | ( |
| 296 | cd file_unborn_parent && |
| 297 | git config lsrefs.unborn ignore && |
| 298 | git checkout -b branchwithstuff && |
| 299 | test_commit --no-tag stuff && |
| 300 | git symbolic-ref HEAD refs/heads/mydefaultbranch |
| 301 | ) && |
| 302 | |
| 303 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ |
| 304 | git -c init.defaultBranch=branchwithstuff -c protocol.version=2 \ |
| 305 | clone "file://$(pwd)/file_unborn_parent" \ |
| 306 | file_unborn_child 2>stderr && |
| 307 | grep "refs/heads/branchwithstuff" file_unborn_child/.git/HEAD && |
| 308 | test_path_is_file file_unborn_child/stuff.t && |
| 309 | ! grep "warning:" stderr |
| 310 | ' |
| 311 | |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 312 | test_expect_success 'fetch with file:// using protocol v2' ' |
| 313 | test_when_finished "rm -f log" && |
| 314 | |
| 315 | test_commit -C file_parent two && |
| 316 | |
| 317 | GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \ |
| 318 | fetch origin && |
| 319 | |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 320 | git -C file_child log -1 --format=%s origin/main >actual && |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 321 | git -C file_parent log -1 --format=%s >expect && |
| 322 | test_cmp expect actual && |
| 323 | |
| 324 | # Server responded using protocol v2 |
| 325 | grep "fetch< version 2" log |
| 326 | ' |
| 327 | |
Elijah Newren | 4dc8b1c | 2019-11-05 17:07:25 +0000 | [diff] [blame] | 328 | test_expect_success 'ref advertisement is filtered during fetch using protocol v2' ' |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 329 | test_when_finished "rm -f log" && |
| 330 | |
| 331 | test_commit -C file_parent three && |
Jonathan Tan | 2b55435 | 2018-06-05 14:40:36 -0700 | [diff] [blame] | 332 | git -C file_parent branch unwanted-branch three && |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 333 | |
| 334 | GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \ |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 335 | fetch origin main && |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 336 | |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 337 | git -C file_child log -1 --format=%s origin/main >actual && |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 338 | git -C file_parent log -1 --format=%s >expect && |
| 339 | test_cmp expect actual && |
| 340 | |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 341 | grep "refs/heads/main" log && |
Jonathan Tan | 2b55435 | 2018-06-05 14:40:36 -0700 | [diff] [blame] | 342 | ! grep "refs/heads/unwanted-branch" log |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 343 | ' |
| 344 | |
Brandon Williams | 5e3548e | 2018-04-23 15:46:24 -0700 | [diff] [blame] | 345 | test_expect_success 'server-options are sent when fetching' ' |
| 346 | test_when_finished "rm -f log" && |
| 347 | |
| 348 | test_commit -C file_parent four && |
| 349 | |
| 350 | GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \ |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 351 | fetch -o hello -o world origin main && |
Brandon Williams | 5e3548e | 2018-04-23 15:46:24 -0700 | [diff] [blame] | 352 | |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 353 | git -C file_child log -1 --format=%s origin/main >actual && |
Brandon Williams | 5e3548e | 2018-04-23 15:46:24 -0700 | [diff] [blame] | 354 | git -C file_parent log -1 --format=%s >expect && |
| 355 | test_cmp expect actual && |
| 356 | |
| 357 | grep "server-option=hello" log && |
| 358 | grep "server-option=world" log |
| 359 | ' |
| 360 | |
Jonathan Tan | 35eb824 | 2019-04-12 12:51:21 -0700 | [diff] [blame] | 361 | test_expect_success 'warn if using server-option with fetch with legacy protocol' ' |
| 362 | test_when_finished "rm -rf temp_child" && |
| 363 | |
| 364 | git init temp_child && |
| 365 | |
| 366 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -C temp_child -c protocol.version=0 \ |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 367 | fetch -o hello -o world "file://$(pwd)/file_parent" main 2>err && |
Jonathan Tan | 35eb824 | 2019-04-12 12:51:21 -0700 | [diff] [blame] | 368 | |
| 369 | test_i18ngrep "see protocol.version in" err && |
| 370 | test_i18ngrep "server options require protocol version 2 or later" err |
| 371 | ' |
| 372 | |
Jonathan Tan | 6e98305 | 2019-04-12 12:51:22 -0700 | [diff] [blame] | 373 | test_expect_success 'server-options are sent when cloning' ' |
| 374 | test_when_finished "rm -rf log myclone" && |
| 375 | |
| 376 | GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \ |
| 377 | clone --server-option=hello --server-option=world \ |
| 378 | "file://$(pwd)/file_parent" myclone && |
| 379 | |
| 380 | grep "server-option=hello" log && |
| 381 | grep "server-option=world" log |
| 382 | ' |
| 383 | |
| 384 | test_expect_success 'warn if using server-option with clone with legacy protocol' ' |
| 385 | test_when_finished "rm -rf myclone" && |
| 386 | |
| 387 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -c protocol.version=0 \ |
| 388 | clone --server-option=hello --server-option=world \ |
| 389 | "file://$(pwd)/file_parent" myclone 2>err && |
| 390 | |
| 391 | test_i18ngrep "see protocol.version in" err && |
| 392 | test_i18ngrep "server options require protocol version 2 or later" err |
| 393 | ' |
| 394 | |
Jonathan Tan | 5459268 | 2018-05-03 16:46:55 -0700 | [diff] [blame] | 395 | test_expect_success 'upload-pack respects config using protocol v2' ' |
| 396 | git init server && |
| 397 | write_script server/.git/hook <<-\EOF && |
| 398 | touch hookout |
| 399 | "$@" |
| 400 | EOF |
| 401 | test_commit -C server one && |
| 402 | |
| 403 | test_config_global uploadpack.packobjectshook ./hook && |
| 404 | test_path_is_missing server/.git/hookout && |
| 405 | git -c protocol.version=2 clone "file://$(pwd)/server" client && |
| 406 | test_path_is_file server/.git/hookout |
| 407 | ' |
| 408 | |
Jonathan Tan | ba95710 | 2018-05-03 16:46:56 -0700 | [diff] [blame] | 409 | test_expect_success 'setup filter tests' ' |
| 410 | rm -rf server client && |
| 411 | git init server && |
| 412 | |
| 413 | # 1 commit to create a file, and 1 commit to modify it |
| 414 | test_commit -C server message1 a.txt && |
| 415 | test_commit -C server message2 a.txt && |
| 416 | git -C server config protocol.version 2 && |
| 417 | git -C server config uploadpack.allowfilter 1 && |
| 418 | git -C server config uploadpack.allowanysha1inwant 1 && |
| 419 | git -C server config protocol.version 2 |
| 420 | ' |
| 421 | |
| 422 | test_expect_success 'partial clone' ' |
| 423 | GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 \ |
| 424 | clone --filter=blob:none "file://$(pwd)/server" client && |
| 425 | grep "version 2" trace && |
| 426 | |
| 427 | # Ensure that the old version of the file is missing |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 428 | git -C client rev-list --quiet --objects --missing=print main \ |
Jonathan Tan | ba95710 | 2018-05-03 16:46:56 -0700 | [diff] [blame] | 429 | >observed.oids && |
| 430 | grep "$(git -C server rev-parse message1:a.txt)" observed.oids && |
| 431 | |
| 432 | # Ensure that client passes fsck |
| 433 | git -C client fsck |
| 434 | ' |
| 435 | |
| 436 | test_expect_success 'dynamically fetch missing object' ' |
| 437 | rm "$(pwd)/trace" && |
| 438 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \ |
| 439 | cat-file -p $(git -C server rev-parse message1:a.txt) && |
| 440 | grep "version 2" trace |
| 441 | ' |
| 442 | |
Jonathan Tan | 0177565 | 2018-09-27 12:24:05 -0700 | [diff] [blame] | 443 | test_expect_success 'when dynamically fetching missing object, do not list refs' ' |
| 444 | ! grep "git> command=ls-refs" trace |
| 445 | ' |
| 446 | |
Jonathan Tan | ba95710 | 2018-05-03 16:46:56 -0700 | [diff] [blame] | 447 | test_expect_success 'partial fetch' ' |
| 448 | rm -rf client "$(pwd)/trace" && |
| 449 | git init client && |
| 450 | SERVER="file://$(pwd)/server" && |
Jonathan Tan | ba95710 | 2018-05-03 16:46:56 -0700 | [diff] [blame] | 451 | |
| 452 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \ |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 453 | fetch --filter=blob:none "$SERVER" main:refs/heads/other && |
Jonathan Tan | ba95710 | 2018-05-03 16:46:56 -0700 | [diff] [blame] | 454 | grep "version 2" trace && |
| 455 | |
| 456 | # Ensure that the old version of the file is missing |
Matthew DeVore | 8d6ba49 | 2018-10-05 14:54:07 -0700 | [diff] [blame] | 457 | git -C client rev-list --quiet --objects --missing=print other \ |
Jonathan Tan | ba95710 | 2018-05-03 16:46:56 -0700 | [diff] [blame] | 458 | >observed.oids && |
| 459 | grep "$(git -C server rev-parse message1:a.txt)" observed.oids && |
| 460 | |
| 461 | # Ensure that client passes fsck |
| 462 | git -C client fsck |
| 463 | ' |
| 464 | |
| 465 | test_expect_success 'do not advertise filter if not configured to do so' ' |
| 466 | SERVER="file://$(pwd)/server" && |
| 467 | |
| 468 | rm "$(pwd)/trace" && |
| 469 | git -C server config uploadpack.allowfilter 1 && |
| 470 | GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 \ |
| 471 | ls-remote "$SERVER" && |
| 472 | grep "fetch=.*filter" trace && |
| 473 | |
| 474 | rm "$(pwd)/trace" && |
| 475 | git -C server config uploadpack.allowfilter 0 && |
| 476 | GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 \ |
| 477 | ls-remote "$SERVER" && |
| 478 | grep "fetch=" trace >fetch_capabilities && |
| 479 | ! grep filter fetch_capabilities |
| 480 | ' |
| 481 | |
| 482 | test_expect_success 'partial clone warns if filter is not advertised' ' |
| 483 | rm -rf client && |
| 484 | git -C server config uploadpack.allowfilter 0 && |
| 485 | git -c protocol.version=2 \ |
| 486 | clone --filter=blob:none "file://$(pwd)/server" client 2>err && |
| 487 | test_i18ngrep "filtering not recognized by server, ignoring" err |
| 488 | ' |
| 489 | |
| 490 | test_expect_success 'even with handcrafted request, filter does not work if not advertised' ' |
| 491 | git -C server config uploadpack.allowfilter 0 && |
| 492 | |
| 493 | # Custom request that tries to filter even though it is not advertised. |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 494 | test-tool pkt-line pack >in <<-EOF && |
Jonathan Tan | ba95710 | 2018-05-03 16:46:56 -0700 | [diff] [blame] | 495 | command=fetch |
brian m. carlson | 8fc7003 | 2020-06-19 17:55:56 +0000 | [diff] [blame] | 496 | object-format=$(test_oid algo) |
Jonathan Tan | ba95710 | 2018-05-03 16:46:56 -0700 | [diff] [blame] | 497 | 0001 |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 498 | want $(git -C server rev-parse main) |
Jonathan Tan | ba95710 | 2018-05-03 16:46:56 -0700 | [diff] [blame] | 499 | filter blob:none |
| 500 | 0000 |
| 501 | EOF |
| 502 | |
Johannes Schindelin | b7ce24d | 2019-04-18 06:16:51 -0700 | [diff] [blame] | 503 | test_must_fail test-tool -C server serve-v2 --stateless-rpc \ |
| 504 | <in >/dev/null 2>err && |
Jonathan Tan | ba95710 | 2018-05-03 16:46:56 -0700 | [diff] [blame] | 505 | grep "unexpected line: .filter blob:none." err && |
| 506 | |
| 507 | # Exercise to ensure that if advertised, filter works |
| 508 | git -C server config uploadpack.allowfilter 1 && |
Johannes Schindelin | b7ce24d | 2019-04-18 06:16:51 -0700 | [diff] [blame] | 509 | test-tool -C server serve-v2 --stateless-rpc <in >/dev/null |
Jonathan Tan | ba95710 | 2018-05-03 16:46:56 -0700 | [diff] [blame] | 510 | ' |
| 511 | |
Brandon Williams | dcc73cf | 2018-05-16 16:48:22 -0700 | [diff] [blame] | 512 | test_expect_success 'default refspec is used to filter ref when fetchcing' ' |
| 513 | test_when_finished "rm -f log" && |
| 514 | |
| 515 | GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \ |
| 516 | fetch origin && |
| 517 | |
| 518 | git -C file_child log -1 --format=%s three >actual && |
| 519 | git -C file_parent log -1 --format=%s three >expect && |
| 520 | test_cmp expect actual && |
| 521 | |
| 522 | grep "ref-prefix refs/heads/" log && |
| 523 | grep "ref-prefix refs/tags/" log |
| 524 | ' |
| 525 | |
Jonathan Tan | 15cfc98 | 2018-06-05 14:40:35 -0700 | [diff] [blame] | 526 | test_expect_success 'fetch supports various ways of have lines' ' |
| 527 | rm -rf server client trace && |
| 528 | git init server && |
| 529 | test_commit -C server dwim && |
| 530 | TREE=$(git -C server rev-parse HEAD^{tree}) && |
| 531 | git -C server tag exact \ |
| 532 | $(git -C server commit-tree -m a "$TREE") && |
| 533 | git -C server tag dwim-unwanted \ |
| 534 | $(git -C server commit-tree -m b "$TREE") && |
| 535 | git -C server tag exact-unwanted \ |
| 536 | $(git -C server commit-tree -m c "$TREE") && |
| 537 | git -C server tag prefix1 \ |
| 538 | $(git -C server commit-tree -m d "$TREE") && |
| 539 | git -C server tag prefix2 \ |
| 540 | $(git -C server commit-tree -m e "$TREE") && |
| 541 | git -C server tag fetch-by-sha1 \ |
| 542 | $(git -C server commit-tree -m f "$TREE") && |
| 543 | git -C server tag completely-unrelated \ |
| 544 | $(git -C server commit-tree -m g "$TREE") && |
| 545 | |
| 546 | git init client && |
| 547 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \ |
| 548 | fetch "file://$(pwd)/server" \ |
| 549 | dwim \ |
| 550 | refs/tags/exact \ |
| 551 | refs/tags/prefix*:refs/tags/prefix* \ |
| 552 | "$(git -C server rev-parse fetch-by-sha1)" && |
| 553 | |
| 554 | # Ensure that the appropriate prefixes are sent (using a sample) |
| 555 | grep "fetch> ref-prefix dwim" trace && |
| 556 | grep "fetch> ref-prefix refs/heads/dwim" trace && |
| 557 | grep "fetch> ref-prefix refs/tags/prefix" trace && |
| 558 | |
| 559 | # Ensure that the correct objects are returned |
| 560 | git -C client cat-file -e $(git -C server rev-parse dwim) && |
| 561 | git -C client cat-file -e $(git -C server rev-parse exact) && |
| 562 | git -C client cat-file -e $(git -C server rev-parse prefix1) && |
| 563 | git -C client cat-file -e $(git -C server rev-parse prefix2) && |
| 564 | git -C client cat-file -e $(git -C server rev-parse fetch-by-sha1) && |
| 565 | test_must_fail git -C client cat-file -e \ |
| 566 | $(git -C server rev-parse dwim-unwanted) && |
| 567 | test_must_fail git -C client cat-file -e \ |
| 568 | $(git -C server rev-parse exact-unwanted) && |
| 569 | test_must_fail git -C client cat-file -e \ |
| 570 | $(git -C server rev-parse completely-unrelated) |
| 571 | ' |
| 572 | |
Jonathan Tan | 2b55435 | 2018-06-05 14:40:36 -0700 | [diff] [blame] | 573 | test_expect_success 'fetch supports include-tag and tag following' ' |
| 574 | rm -rf server client trace && |
| 575 | git init server && |
| 576 | |
| 577 | test_commit -C server to_fetch && |
| 578 | git -C server tag -a annotated_tag -m message && |
| 579 | |
| 580 | git init client && |
| 581 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \ |
| 582 | fetch "$(pwd)/server" to_fetch:to_fetch && |
| 583 | |
| 584 | grep "fetch> ref-prefix to_fetch" trace && |
| 585 | grep "fetch> ref-prefix refs/tags/" trace && |
| 586 | grep "fetch> include-tag" trace && |
| 587 | |
| 588 | git -C client cat-file -e $(git -C client rev-parse annotated_tag) |
| 589 | ' |
| 590 | |
Jonathan Tan | d1035ca | 2018-10-18 13:43:29 -0700 | [diff] [blame] | 591 | test_expect_success 'upload-pack respects client shallows' ' |
| 592 | rm -rf server client trace && |
| 593 | |
| 594 | git init server && |
| 595 | test_commit -C server base && |
| 596 | test_commit -C server client_has && |
| 597 | |
| 598 | git clone --depth=1 "file://$(pwd)/server" client && |
| 599 | |
| 600 | # Add extra commits to the client so that the whole fetch takes more |
| 601 | # than 1 request (due to negotiation) |
Jeff King | 9516345 | 2019-06-28 05:41:54 -0400 | [diff] [blame] | 602 | test_commit_bulk -C client --id=c 32 && |
Jonathan Tan | d1035ca | 2018-10-18 13:43:29 -0700 | [diff] [blame] | 603 | |
| 604 | git -C server checkout -b newbranch base && |
| 605 | test_commit -C server client_wants && |
| 606 | |
| 607 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \ |
| 608 | fetch origin newbranch && |
| 609 | # Ensure that protocol v2 is used |
| 610 | grep "fetch< version 2" trace |
| 611 | ' |
| 612 | |
Jonathan Tan | bd0b42a | 2019-01-10 11:36:45 -0800 | [diff] [blame] | 613 | test_expect_success 'ensure that multiple fetches in same process from a shallow repo works' ' |
| 614 | rm -rf server client trace && |
| 615 | |
| 616 | test_create_repo server && |
| 617 | test_commit -C server one && |
| 618 | test_commit -C server two && |
| 619 | test_commit -C server three && |
| 620 | git clone --shallow-exclude two "file://$(pwd)/server" client && |
| 621 | |
| 622 | git -C server tag -a -m "an annotated tag" twotag two && |
| 623 | |
| 624 | # Triggers tag following (thus, 2 fetches in one process) |
| 625 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \ |
| 626 | fetch --shallow-exclude one origin && |
| 627 | # Ensure that protocol v2 is used |
| 628 | grep "fetch< version 2" trace |
| 629 | ' |
| 630 | |
Jonathan Tan | 5056cf4 | 2018-12-18 13:24:35 -0800 | [diff] [blame] | 631 | test_expect_success 'deepen-relative' ' |
| 632 | rm -rf server client trace && |
| 633 | |
| 634 | test_create_repo server && |
| 635 | test_commit -C server one && |
| 636 | test_commit -C server two && |
| 637 | test_commit -C server three && |
| 638 | git clone --depth 1 "file://$(pwd)/server" client && |
| 639 | test_commit -C server four && |
| 640 | |
| 641 | # Sanity check that only "three" is downloaded |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 642 | git -C client log --pretty=tformat:%s main >actual && |
Jonathan Tan | 5056cf4 | 2018-12-18 13:24:35 -0800 | [diff] [blame] | 643 | echo three >expected && |
| 644 | test_cmp expected actual && |
| 645 | |
| 646 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \ |
| 647 | fetch --deepen=1 origin && |
| 648 | # Ensure that protocol v2 is used |
| 649 | grep "fetch< version 2" trace && |
| 650 | |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 651 | git -C client log --pretty=tformat:%s origin/main >actual && |
Jonathan Tan | 5056cf4 | 2018-12-18 13:24:35 -0800 | [diff] [blame] | 652 | cat >expected <<-\EOF && |
| 653 | four |
| 654 | three |
| 655 | two |
| 656 | EOF |
| 657 | test_cmp expected actual |
| 658 | ' |
| 659 | |
Jonathan Tan | 9c1e657 | 2021-05-04 14:16:01 -0700 | [diff] [blame] | 660 | setup_negotiate_only () { |
| 661 | SERVER="$1" |
| 662 | URI="$2" |
| 663 | |
| 664 | rm -rf "$SERVER" client |
| 665 | |
| 666 | git init "$SERVER" |
| 667 | test_commit -C "$SERVER" one |
| 668 | test_commit -C "$SERVER" two |
| 669 | |
| 670 | git clone "$URI" client |
| 671 | test_commit -C client three |
| 672 | } |
| 673 | |
Ævar Arnfjörð Bjarmason | eff4045 | 2021-07-08 12:53:15 +0200 | [diff] [blame] | 674 | test_expect_success 'usage: --negotiate-only without --negotiation-tip' ' |
| 675 | SERVER="server" && |
| 676 | URI="file://$(pwd)/server" && |
| 677 | |
| 678 | setup_negotiate_only "$SERVER" "$URI" && |
| 679 | |
| 680 | cat >err.expect <<-\EOF && |
Robert Coup | 2826ffa | 2022-01-28 14:36:02 +0000 | [diff] [blame] | 681 | fatal: --negotiate-only needs one or more --negotiation-tip=* |
Ævar Arnfjörð Bjarmason | eff4045 | 2021-07-08 12:53:15 +0200 | [diff] [blame] | 682 | EOF |
| 683 | |
| 684 | test_must_fail git -c protocol.version=2 -C client fetch \ |
| 685 | --negotiate-only \ |
| 686 | origin 2>err.actual && |
| 687 | test_cmp err.expect err.actual |
| 688 | ' |
| 689 | |
Glen Choo | 386c076 | 2022-01-18 16:00:56 -0800 | [diff] [blame] | 690 | test_expect_success 'usage: --negotiate-only with --recurse-submodules' ' |
| 691 | cat >err.expect <<-\EOF && |
Junio C Hamano | de4eaae | 2022-01-20 13:58:43 -0800 | [diff] [blame] | 692 | fatal: options '\''--negotiate-only'\'' and '\''--recurse-submodules'\'' cannot be used together |
Glen Choo | 386c076 | 2022-01-18 16:00:56 -0800 | [diff] [blame] | 693 | EOF |
| 694 | |
| 695 | test_must_fail git -c protocol.version=2 -C client fetch \ |
| 696 | --negotiate-only \ |
| 697 | --recurse-submodules \ |
| 698 | origin 2>err.actual && |
| 699 | test_cmp err.expect err.actual |
| 700 | ' |
| 701 | |
Jonathan Tan | 9c1e657 | 2021-05-04 14:16:01 -0700 | [diff] [blame] | 702 | test_expect_success 'file:// --negotiate-only' ' |
| 703 | SERVER="server" && |
| 704 | URI="file://$(pwd)/server" && |
| 705 | |
| 706 | setup_negotiate_only "$SERVER" "$URI" && |
| 707 | |
| 708 | git -c protocol.version=2 -C client fetch \ |
| 709 | --no-tags \ |
| 710 | --negotiate-only \ |
| 711 | --negotiation-tip=$(git -C client rev-parse HEAD) \ |
| 712 | origin >out && |
| 713 | COMMON=$(git -C "$SERVER" rev-parse two) && |
| 714 | grep "$COMMON" out |
| 715 | ' |
| 716 | |
| 717 | test_expect_success 'file:// --negotiate-only with protocol v0' ' |
| 718 | SERVER="server" && |
| 719 | URI="file://$(pwd)/server" && |
| 720 | |
| 721 | setup_negotiate_only "$SERVER" "$URI" && |
| 722 | |
| 723 | test_must_fail git -c protocol.version=0 -C client fetch \ |
| 724 | --no-tags \ |
| 725 | --negotiate-only \ |
| 726 | --negotiation-tip=$(git -C client rev-parse HEAD) \ |
| 727 | origin 2>err && |
| 728 | test_i18ngrep "negotiate-only requires protocol v2" err |
| 729 | ' |
| 730 | |
Brandon Williams | 0f1dc53 | 2018-03-15 10:31:41 -0700 | [diff] [blame] | 731 | # Test protocol v2 with 'http://' transport |
| 732 | # |
| 733 | . "$TEST_DIRECTORY"/lib-httpd.sh |
| 734 | start_httpd |
| 735 | |
| 736 | test_expect_success 'create repo to be served by http:// transport' ' |
| 737 | git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && |
| 738 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" config http.receivepack true && |
| 739 | test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one |
| 740 | ' |
| 741 | |
| 742 | test_expect_success 'clone with http:// using protocol v2' ' |
| 743 | test_when_finished "rm -f log" && |
| 744 | |
| 745 | GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \ |
| 746 | clone "$HTTPD_URL/smart/http_parent" http_child && |
| 747 | |
| 748 | git -C http_child log -1 --format=%s >actual && |
| 749 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect && |
| 750 | test_cmp expect actual && |
| 751 | |
| 752 | # Client requested to use protocol v2 |
| 753 | grep "Git-Protocol: version=2" log && |
| 754 | # Server responded using protocol v2 |
Jonathan Tan | a97d007 | 2019-02-21 12:24:41 -0800 | [diff] [blame] | 755 | grep "git< version 2" log && |
| 756 | # Verify that the chunked encoding sending codepath is NOT exercised |
| 757 | ! grep "Send header: Transfer-Encoding: chunked" log |
| 758 | ' |
| 759 | |
Denton Liu | 74b082a | 2020-05-19 06:53:58 -0400 | [diff] [blame] | 760 | test_expect_success 'clone repository with http:// using protocol v2 with incomplete pktline length' ' |
| 761 | test_when_finished "rm -f log" && |
| 762 | |
| 763 | git init "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_length" && |
| 764 | test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_length" file && |
| 765 | |
| 766 | test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \ |
| 767 | clone "$HTTPD_URL/smart/incomplete_length" incomplete_length_child 2>err && |
| 768 | |
| 769 | # Client requested to use protocol v2 |
| 770 | grep "Git-Protocol: version=2" log && |
| 771 | # Server responded using protocol v2 |
| 772 | grep "git< version 2" log && |
| 773 | # Client reported appropriate failure |
| 774 | test_i18ngrep "bytes of length header were received" err |
| 775 | ' |
| 776 | |
| 777 | test_expect_success 'clone repository with http:// using protocol v2 with incomplete pktline body' ' |
| 778 | test_when_finished "rm -f log" && |
| 779 | |
| 780 | git init "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_body" && |
| 781 | test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_body" file && |
| 782 | |
| 783 | test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \ |
| 784 | clone "$HTTPD_URL/smart/incomplete_body" incomplete_body_child 2>err && |
| 785 | |
| 786 | # Client requested to use protocol v2 |
| 787 | grep "Git-Protocol: version=2" log && |
| 788 | # Server responded using protocol v2 |
| 789 | grep "git< version 2" log && |
| 790 | # Client reported appropriate failure |
| 791 | test_i18ngrep "bytes of body are still expected" err |
| 792 | ' |
| 793 | |
Denton Liu | b0df0c1 | 2020-05-19 06:54:00 -0400 | [diff] [blame] | 794 | test_expect_success 'clone with http:// using protocol v2 and invalid parameters' ' |
| 795 | test_when_finished "rm -f log" && |
| 796 | |
| 797 | test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" \ |
| 798 | git -c protocol.version=2 \ |
| 799 | clone --shallow-since=20151012 "$HTTPD_URL/smart/http_parent" http_child_invalid && |
| 800 | |
| 801 | # Client requested to use protocol v2 |
| 802 | grep "Git-Protocol: version=2" log && |
| 803 | # Server responded using protocol v2 |
| 804 | grep "git< version 2" log |
| 805 | ' |
| 806 | |
Jonathan Tan | a97d007 | 2019-02-21 12:24:41 -0800 | [diff] [blame] | 807 | test_expect_success 'clone big repository with http:// using protocol v2' ' |
| 808 | test_when_finished "rm -f log" && |
| 809 | |
| 810 | git init "$HTTPD_DOCUMENT_ROOT_PATH/big" && |
| 811 | # Ensure that the list of wants is greater than http.postbuffer below |
| 812 | for i in $(test_seq 1 1500) |
| 813 | do |
| 814 | # do not use here-doc, because it requires a process |
| 815 | # per loop iteration |
| 816 | echo "commit refs/heads/too-many-refs-$i" && |
| 817 | echo "committer git <git@example.com> $i +0000" && |
| 818 | echo "data 0" && |
| 819 | echo "M 644 inline bla.txt" && |
| 820 | echo "data 4" && |
Eric Sunshine | d0fd993 | 2021-12-09 00:11:14 -0500 | [diff] [blame] | 821 | echo "bla" || return 1 |
Jonathan Tan | a97d007 | 2019-02-21 12:24:41 -0800 | [diff] [blame] | 822 | done | git -C "$HTTPD_DOCUMENT_ROOT_PATH/big" fast-import && |
| 823 | |
| 824 | GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git \ |
| 825 | -c protocol.version=2 -c http.postbuffer=65536 \ |
| 826 | clone "$HTTPD_URL/smart/big" big_child && |
| 827 | |
| 828 | # Client requested to use protocol v2 |
| 829 | grep "Git-Protocol: version=2" log && |
| 830 | # Server responded using protocol v2 |
| 831 | grep "git< version 2" log && |
| 832 | # Verify that the chunked encoding sending codepath is exercised |
| 833 | grep "Send header: Transfer-Encoding: chunked" log |
Brandon Williams | 0f1dc53 | 2018-03-15 10:31:41 -0700 | [diff] [blame] | 834 | ' |
| 835 | |
| 836 | test_expect_success 'fetch with http:// using protocol v2' ' |
| 837 | test_when_finished "rm -f log" && |
| 838 | |
| 839 | test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two && |
| 840 | |
| 841 | GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \ |
| 842 | fetch && |
| 843 | |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 844 | git -C http_child log -1 --format=%s origin/main >actual && |
Brandon Williams | 0f1dc53 | 2018-03-15 10:31:41 -0700 | [diff] [blame] | 845 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect && |
| 846 | test_cmp expect actual && |
| 847 | |
| 848 | # Server responded using protocol v2 |
| 849 | grep "git< version 2" log |
| 850 | ' |
| 851 | |
Jonathan Tan | ac3fda8 | 2019-08-21 15:20:09 -0700 | [diff] [blame] | 852 | test_expect_success 'fetch with http:// by hash without tag following with protocol v2 does not list refs' ' |
| 853 | test_when_finished "rm -f log" && |
| 854 | |
| 855 | test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two_a && |
| 856 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" rev-parse two_a >two_a_hash && |
| 857 | |
| 858 | GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \ |
| 859 | fetch --no-tags origin $(cat two_a_hash) && |
| 860 | |
| 861 | grep "fetch< version 2" log && |
| 862 | ! grep "fetch> command=ls-refs" log |
| 863 | ' |
| 864 | |
Jonathan Tan | e2f41a0 | 2019-01-17 15:33:05 -0800 | [diff] [blame] | 865 | test_expect_success 'fetch from namespaced repo respects namespaces' ' |
| 866 | test_when_finished "rm -f log" && |
| 867 | |
| 868 | git init "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" && |
| 869 | test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" one && |
| 870 | test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" two && |
| 871 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" \ |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 872 | update-ref refs/namespaces/ns/refs/heads/main one && |
Jonathan Tan | e2f41a0 | 2019-01-17 15:33:05 -0800 | [diff] [blame] | 873 | |
| 874 | GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \ |
| 875 | fetch "$HTTPD_URL/smart_namespace/nsrepo" \ |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 876 | refs/heads/main:refs/heads/theirs && |
Jonathan Tan | e2f41a0 | 2019-01-17 15:33:05 -0800 | [diff] [blame] | 877 | |
| 878 | # Server responded using protocol v2 |
| 879 | grep "fetch< version 2" log && |
| 880 | |
| 881 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" rev-parse one >expect && |
| 882 | git -C http_child rev-parse theirs >actual && |
| 883 | test_cmp expect actual |
| 884 | ' |
| 885 | |
Jeff King | 4d8cab9 | 2020-01-08 02:10:09 -0500 | [diff] [blame] | 886 | test_expect_success 'ls-remote with v2 http sends only one POST' ' |
| 887 | test_when_finished "rm -f log" && |
| 888 | |
| 889 | git ls-remote "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" >expect && |
| 890 | GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \ |
| 891 | ls-remote "$HTTPD_URL/smart/http_parent" >actual && |
| 892 | test_cmp expect actual && |
| 893 | |
| 894 | grep "Send header: POST" log >posts && |
| 895 | test_line_count = 1 posts |
| 896 | ' |
| 897 | |
Brandon Williams | a4d78ce | 2018-03-15 10:31:42 -0700 | [diff] [blame] | 898 | test_expect_success 'push with http:// and a config of v2 does not request v2' ' |
| 899 | test_when_finished "rm -f log" && |
| 900 | # Till v2 for push is designed, make sure that if a client has |
| 901 | # protocol.version configured to use v2, that the client instead falls |
| 902 | # back and uses v0. |
| 903 | |
| 904 | test_commit -C http_child three && |
| 905 | |
| 906 | # Push to another branch, as the target repository has the |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 907 | # main branch checked out and we cannot push into it. |
Brandon Williams | a4d78ce | 2018-03-15 10:31:42 -0700 | [diff] [blame] | 908 | GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \ |
| 909 | push origin HEAD:client_branch && |
| 910 | |
| 911 | git -C http_child log -1 --format=%s >actual && |
| 912 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s client_branch >expect && |
| 913 | test_cmp expect actual && |
| 914 | |
Elijah Newren | 7a40cf1 | 2019-11-05 17:07:24 +0000 | [diff] [blame] | 915 | # Client did not request to use protocol v2 |
Brandon Williams | a4d78ce | 2018-03-15 10:31:42 -0700 | [diff] [blame] | 916 | ! grep "Git-Protocol: version=2" log && |
Elijah Newren | 7a40cf1 | 2019-11-05 17:07:24 +0000 | [diff] [blame] | 917 | # Server did not respond using protocol v2 |
Brandon Williams | a4d78ce | 2018-03-15 10:31:42 -0700 | [diff] [blame] | 918 | ! grep "git< version 2" log |
| 919 | ' |
| 920 | |
Jonathan Tan | 5400b2a | 2018-10-19 15:54:04 -0700 | [diff] [blame] | 921 | test_expect_success 'when server sends "ready", expect DELIM' ' |
| 922 | rm -rf "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" http_child && |
| 923 | |
| 924 | git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && |
| 925 | test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one && |
| 926 | |
| 927 | git clone "$HTTPD_URL/smart/http_parent" http_child && |
| 928 | |
| 929 | test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two && |
| 930 | |
| 931 | # After "ready" in the acknowledgments section, pretend that a FLUSH |
| 932 | # (0000) was sent instead of a DELIM (0001). |
Johannes Schindelin | eafff6e | 2020-02-27 13:23:11 +0000 | [diff] [blame] | 933 | printf "\$ready = 1 if /ready/; \$ready && s/0001/0000/" \ |
| 934 | >"$HTTPD_ROOT_PATH/one-time-perl" && |
Jonathan Tan | 5400b2a | 2018-10-19 15:54:04 -0700 | [diff] [blame] | 935 | |
| 936 | test_must_fail git -C http_child -c protocol.version=2 \ |
Johannes Schindelin | eafff6e | 2020-02-27 13:23:11 +0000 | [diff] [blame] | 937 | fetch "$HTTPD_URL/one_time_perl/http_parent" 2> err && |
Jonathan Tan | 5400b2a | 2018-10-19 15:54:04 -0700 | [diff] [blame] | 938 | test_i18ngrep "expected packfile to be sent after .ready." err |
| 939 | ' |
| 940 | |
| 941 | test_expect_success 'when server does not send "ready", expect FLUSH' ' |
| 942 | rm -rf "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" http_child log && |
| 943 | |
| 944 | git init "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && |
| 945 | test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" one && |
| 946 | |
| 947 | git clone "$HTTPD_URL/smart/http_parent" http_child && |
| 948 | |
| 949 | test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two && |
| 950 | |
| 951 | # Create many commits to extend the negotiation phase across multiple |
| 952 | # requests, so that the server does not send "ready" in the first |
| 953 | # request. |
Jeff King | 9516345 | 2019-06-28 05:41:54 -0400 | [diff] [blame] | 954 | test_commit_bulk -C http_child --id=c 32 && |
Jonathan Tan | 5400b2a | 2018-10-19 15:54:04 -0700 | [diff] [blame] | 955 | |
| 956 | # After the acknowledgments section, pretend that a DELIM |
| 957 | # (0001) was sent instead of a FLUSH (0000). |
Johannes Schindelin | eafff6e | 2020-02-27 13:23:11 +0000 | [diff] [blame] | 958 | printf "\$ack = 1 if /acknowledgments/; \$ack && s/0000/0001/" \ |
| 959 | >"$HTTPD_ROOT_PATH/one-time-perl" && |
Jonathan Tan | 5400b2a | 2018-10-19 15:54:04 -0700 | [diff] [blame] | 960 | |
| 961 | test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" git -C http_child \ |
| 962 | -c protocol.version=2 \ |
Johannes Schindelin | eafff6e | 2020-02-27 13:23:11 +0000 | [diff] [blame] | 963 | fetch "$HTTPD_URL/one_time_perl/http_parent" 2> err && |
Jonathan Tan | 07c3c2a | 2019-01-16 11:28:15 -0800 | [diff] [blame] | 964 | grep "fetch< .*acknowledgments" log && |
| 965 | ! grep "fetch< .*ready" log && |
Jonathan Tan | 5400b2a | 2018-10-19 15:54:04 -0700 | [diff] [blame] | 966 | test_i18ngrep "expected no other sections to be sent after no .ready." err |
| 967 | ' |
Brandon Williams | a4d78ce | 2018-03-15 10:31:42 -0700 | [diff] [blame] | 968 | |
Jonathan Tan | dd4b732 | 2020-06-10 13:57:23 -0700 | [diff] [blame] | 969 | configure_exclusion () { |
| 970 | git -C "$1" hash-object "$2" >objh && |
| 971 | git -C "$1" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh && |
| 972 | git -C "$1" config --add \ |
| 973 | "uploadpack.blobpackfileuri" \ |
| 974 | "$(cat objh) $(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" && |
| 975 | cat objh |
| 976 | } |
| 977 | |
| 978 | test_expect_success 'part of packfile response provided as URI' ' |
| 979 | P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && |
| 980 | rm -rf "$P" http_child log && |
| 981 | |
| 982 | git init "$P" && |
| 983 | git -C "$P" config "uploadpack.allowsidebandall" "true" && |
| 984 | |
| 985 | echo my-blob >"$P/my-blob" && |
| 986 | git -C "$P" add my-blob && |
| 987 | echo other-blob >"$P/other-blob" && |
| 988 | git -C "$P" add other-blob && |
| 989 | git -C "$P" commit -m x && |
| 990 | |
| 991 | configure_exclusion "$P" my-blob >h && |
| 992 | configure_exclusion "$P" other-blob >h2 && |
| 993 | |
| 994 | GIT_TRACE=1 GIT_TRACE_PACKET="$(pwd)/log" GIT_TEST_SIDEBAND_ALL=1 \ |
| 995 | git -c protocol.version=2 \ |
| 996 | -c fetch.uriprotocols=http,https \ |
| 997 | clone "$HTTPD_URL/smart/http_parent" http_child && |
| 998 | |
| 999 | # Ensure that my-blob and other-blob are in separate packfiles. |
| 1000 | for idx in http_child/.git/objects/pack/*.idx |
| 1001 | do |
brian m. carlson | e74b606 | 2020-07-29 23:14:19 +0000 | [diff] [blame] | 1002 | git verify-pack --object-format=$(test_oid algo) --verbose $idx >out && |
Jonathan Tan | dd4b732 | 2020-06-10 13:57:23 -0700 | [diff] [blame] | 1003 | { |
Đoàn Trần Công Danh | a764c37 | 2022-09-21 20:02:30 +0700 | [diff] [blame] | 1004 | grep -E "^[0-9a-f]{16,} " out || : |
Jonathan Tan | dd4b732 | 2020-06-10 13:57:23 -0700 | [diff] [blame] | 1005 | } >out.objectlist && |
| 1006 | if test_line_count = 1 out.objectlist |
| 1007 | then |
| 1008 | if grep $(cat h) out |
| 1009 | then |
| 1010 | >hfound |
| 1011 | fi && |
| 1012 | if grep $(cat h2) out |
| 1013 | then |
| 1014 | >h2found |
| 1015 | fi |
Eric Sunshine | d0fd993 | 2021-12-09 00:11:14 -0500 | [diff] [blame] | 1016 | fi || return 1 |
Jonathan Tan | dd4b732 | 2020-06-10 13:57:23 -0700 | [diff] [blame] | 1017 | done && |
| 1018 | test -f hfound && |
| 1019 | test -f h2found && |
| 1020 | |
Jonathan Tan | 5476e1e | 2021-02-22 11:20:09 -0800 | [diff] [blame] | 1021 | # Ensure that there are exactly 3 packfiles with associated .idx |
| 1022 | ls http_child/.git/objects/pack/*.pack \ |
| 1023 | http_child/.git/objects/pack/*.idx >filelist && |
Jonathan Tan | dd4b732 | 2020-06-10 13:57:23 -0700 | [diff] [blame] | 1024 | test_line_count = 6 filelist |
| 1025 | ' |
| 1026 | |
Jonathan Tan | 2aec3bc | 2021-03-04 17:16:20 -0800 | [diff] [blame] | 1027 | test_expect_success 'packfile URIs with fetch instead of clone' ' |
| 1028 | P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && |
| 1029 | rm -rf "$P" http_child log && |
| 1030 | |
| 1031 | git init "$P" && |
| 1032 | git -C "$P" config "uploadpack.allowsidebandall" "true" && |
| 1033 | |
| 1034 | echo my-blob >"$P/my-blob" && |
| 1035 | git -C "$P" add my-blob && |
| 1036 | git -C "$P" commit -m x && |
| 1037 | |
| 1038 | configure_exclusion "$P" my-blob >h && |
| 1039 | |
| 1040 | git init http_child && |
| 1041 | |
| 1042 | GIT_TEST_SIDEBAND_ALL=1 \ |
| 1043 | git -C http_child -c protocol.version=2 \ |
| 1044 | -c fetch.uriprotocols=http,https \ |
| 1045 | fetch "$HTTPD_URL/smart/http_parent" |
| 1046 | ' |
| 1047 | |
Jonathan Tan | dd4b732 | 2020-06-10 13:57:23 -0700 | [diff] [blame] | 1048 | test_expect_success 'fetching with valid packfile URI but invalid hash fails' ' |
| 1049 | P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && |
| 1050 | rm -rf "$P" http_child log && |
| 1051 | |
| 1052 | git init "$P" && |
| 1053 | git -C "$P" config "uploadpack.allowsidebandall" "true" && |
| 1054 | |
| 1055 | echo my-blob >"$P/my-blob" && |
| 1056 | git -C "$P" add my-blob && |
| 1057 | echo other-blob >"$P/other-blob" && |
| 1058 | git -C "$P" add other-blob && |
| 1059 | git -C "$P" commit -m x && |
| 1060 | |
| 1061 | configure_exclusion "$P" my-blob >h && |
| 1062 | # Configure a URL for other-blob. Just reuse the hash of the object as |
| 1063 | # the hash of the packfile, since the hash does not matter for this |
| 1064 | # test as long as it is not the hash of the pack, and it is of the |
| 1065 | # expected length. |
| 1066 | git -C "$P" hash-object other-blob >objh && |
| 1067 | git -C "$P" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh && |
| 1068 | git -C "$P" config --add \ |
| 1069 | "uploadpack.blobpackfileuri" \ |
| 1070 | "$(cat objh) $(cat objh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" && |
| 1071 | |
| 1072 | test_must_fail env GIT_TEST_SIDEBAND_ALL=1 \ |
| 1073 | git -c protocol.version=2 \ |
| 1074 | -c fetch.uriprotocols=http,https \ |
| 1075 | clone "$HTTPD_URL/smart/http_parent" http_child 2>err && |
| 1076 | test_i18ngrep "pack downloaded from.*does not match expected hash" err |
| 1077 | ' |
| 1078 | |
Jonathan Tan | 0bd96be | 2020-08-17 12:48:20 -0700 | [diff] [blame] | 1079 | test_expect_success 'packfile-uri with transfer.fsckobjects' ' |
| 1080 | P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && |
| 1081 | rm -rf "$P" http_child log && |
| 1082 | |
| 1083 | git init "$P" && |
| 1084 | git -C "$P" config "uploadpack.allowsidebandall" "true" && |
| 1085 | |
| 1086 | echo my-blob >"$P/my-blob" && |
| 1087 | git -C "$P" add my-blob && |
| 1088 | git -C "$P" commit -m x && |
| 1089 | |
| 1090 | configure_exclusion "$P" my-blob >h && |
| 1091 | |
| 1092 | sane_unset GIT_TEST_SIDEBAND_ALL && |
| 1093 | git -c protocol.version=2 -c transfer.fsckobjects=1 \ |
| 1094 | -c fetch.uriprotocols=http,https \ |
| 1095 | clone "$HTTPD_URL/smart/http_parent" http_child && |
| 1096 | |
Jonathan Tan | 5476e1e | 2021-02-22 11:20:09 -0800 | [diff] [blame] | 1097 | # Ensure that there are exactly 2 packfiles with associated .idx |
| 1098 | ls http_child/.git/objects/pack/*.pack \ |
| 1099 | http_child/.git/objects/pack/*.idx >filelist && |
Jonathan Tan | 0bd96be | 2020-08-17 12:48:20 -0700 | [diff] [blame] | 1100 | test_line_count = 4 filelist |
| 1101 | ' |
| 1102 | |
| 1103 | test_expect_success 'packfile-uri with transfer.fsckobjects fails on bad object' ' |
| 1104 | P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && |
| 1105 | rm -rf "$P" http_child log && |
| 1106 | |
| 1107 | git init "$P" && |
| 1108 | git -C "$P" config "uploadpack.allowsidebandall" "true" && |
| 1109 | |
| 1110 | cat >bogus-commit <<-EOF && |
| 1111 | tree $EMPTY_TREE |
| 1112 | author Bugs Bunny 1234567890 +0000 |
| 1113 | committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000 |
| 1114 | |
| 1115 | This commit object intentionally broken |
| 1116 | EOF |
| 1117 | BOGUS=$(git -C "$P" hash-object -t commit -w --stdin <bogus-commit) && |
| 1118 | git -C "$P" branch bogus-branch "$BOGUS" && |
| 1119 | |
| 1120 | echo my-blob >"$P/my-blob" && |
| 1121 | git -C "$P" add my-blob && |
| 1122 | git -C "$P" commit -m x && |
| 1123 | |
| 1124 | configure_exclusion "$P" my-blob >h && |
| 1125 | |
| 1126 | sane_unset GIT_TEST_SIDEBAND_ALL && |
| 1127 | test_must_fail git -c protocol.version=2 -c transfer.fsckobjects=1 \ |
| 1128 | -c fetch.uriprotocols=http,https \ |
| 1129 | clone "$HTTPD_URL/smart/http_parent" http_child 2>error && |
| 1130 | test_i18ngrep "invalid author/committer line - missing email" error |
| 1131 | ' |
| 1132 | |
Jonathan Tan | 5476e1e | 2021-02-22 11:20:09 -0800 | [diff] [blame] | 1133 | test_expect_success 'packfile-uri with transfer.fsckobjects succeeds when .gitmodules is separate from tree' ' |
| 1134 | P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && |
| 1135 | rm -rf "$P" http_child && |
| 1136 | |
| 1137 | git init "$P" && |
| 1138 | git -C "$P" config "uploadpack.allowsidebandall" "true" && |
| 1139 | |
| 1140 | echo "[submodule libfoo]" >"$P/.gitmodules" && |
| 1141 | echo "path = include/foo" >>"$P/.gitmodules" && |
| 1142 | echo "url = git://example.com/git/lib.git" >>"$P/.gitmodules" && |
| 1143 | git -C "$P" add .gitmodules && |
| 1144 | git -C "$P" commit -m x && |
| 1145 | |
| 1146 | configure_exclusion "$P" .gitmodules >h && |
| 1147 | |
| 1148 | sane_unset GIT_TEST_SIDEBAND_ALL && |
| 1149 | git -c protocol.version=2 -c transfer.fsckobjects=1 \ |
| 1150 | -c fetch.uriprotocols=http,https \ |
| 1151 | clone "$HTTPD_URL/smart/http_parent" http_child && |
| 1152 | |
| 1153 | # Ensure that there are exactly 2 packfiles with associated .idx |
| 1154 | ls http_child/.git/objects/pack/*.pack \ |
| 1155 | http_child/.git/objects/pack/*.idx >filelist && |
| 1156 | test_line_count = 4 filelist |
| 1157 | ' |
| 1158 | |
| 1159 | test_expect_success 'packfile-uri with transfer.fsckobjects fails when .gitmodules separate from tree is invalid' ' |
| 1160 | P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && |
| 1161 | rm -rf "$P" http_child err && |
| 1162 | |
| 1163 | git init "$P" && |
| 1164 | git -C "$P" config "uploadpack.allowsidebandall" "true" && |
| 1165 | |
| 1166 | echo "[submodule \"..\"]" >"$P/.gitmodules" && |
| 1167 | echo "path = include/foo" >>"$P/.gitmodules" && |
| 1168 | echo "url = git://example.com/git/lib.git" >>"$P/.gitmodules" && |
| 1169 | git -C "$P" add .gitmodules && |
| 1170 | git -C "$P" commit -m x && |
| 1171 | |
| 1172 | configure_exclusion "$P" .gitmodules >h && |
| 1173 | |
| 1174 | sane_unset GIT_TEST_SIDEBAND_ALL && |
| 1175 | test_must_fail git -c protocol.version=2 -c transfer.fsckobjects=1 \ |
| 1176 | -c fetch.uriprotocols=http,https \ |
| 1177 | clone "$HTTPD_URL/smart/http_parent" http_child 2>err && |
| 1178 | test_i18ngrep "disallowed submodule name" err |
| 1179 | ' |
| 1180 | |
Ivan Frade | 88e9b1e | 2021-11-10 23:51:28 +0000 | [diff] [blame] | 1181 | test_expect_success 'packfile-uri path redacted in trace' ' |
| 1182 | P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && |
| 1183 | rm -rf "$P" http_child log && |
| 1184 | |
| 1185 | git init "$P" && |
| 1186 | git -C "$P" config "uploadpack.allowsidebandall" "true" && |
| 1187 | |
| 1188 | echo my-blob >"$P/my-blob" && |
| 1189 | git -C "$P" add my-blob && |
| 1190 | git -C "$P" commit -m x && |
| 1191 | |
| 1192 | git -C "$P" hash-object my-blob >objh && |
| 1193 | git -C "$P" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh && |
| 1194 | git -C "$P" config --add \ |
| 1195 | "uploadpack.blobpackfileuri" \ |
| 1196 | "$(cat objh) $(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" && |
| 1197 | |
| 1198 | GIT_TRACE_PACKET="$(pwd)/log" \ |
| 1199 | git -c protocol.version=2 \ |
| 1200 | -c fetch.uriprotocols=http,https \ |
| 1201 | clone "$HTTPD_URL/smart/http_parent" http_child && |
| 1202 | |
| 1203 | grep -F "clone< \\1$(cat packh) $HTTPD_URL/<redacted>" log |
| 1204 | ' |
| 1205 | |
| 1206 | test_expect_success 'packfile-uri path not redacted in trace when GIT_TRACE_REDACT=0' ' |
| 1207 | P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && |
| 1208 | rm -rf "$P" http_child log && |
| 1209 | |
| 1210 | git init "$P" && |
| 1211 | git -C "$P" config "uploadpack.allowsidebandall" "true" && |
| 1212 | |
| 1213 | echo my-blob >"$P/my-blob" && |
| 1214 | git -C "$P" add my-blob && |
| 1215 | git -C "$P" commit -m x && |
| 1216 | |
| 1217 | git -C "$P" hash-object my-blob >objh && |
| 1218 | git -C "$P" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh && |
| 1219 | git -C "$P" config --add \ |
| 1220 | "uploadpack.blobpackfileuri" \ |
| 1221 | "$(cat objh) $(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" && |
| 1222 | |
| 1223 | GIT_TRACE_PACKET="$(pwd)/log" \ |
| 1224 | GIT_TRACE_REDACT=0 \ |
| 1225 | git -c protocol.version=2 \ |
| 1226 | -c fetch.uriprotocols=http,https \ |
| 1227 | clone "$HTTPD_URL/smart/http_parent" http_child && |
| 1228 | |
| 1229 | grep -F "clone< \\1$(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" log |
| 1230 | ' |
| 1231 | |
Jonathan Tan | 9c1e657 | 2021-05-04 14:16:01 -0700 | [diff] [blame] | 1232 | test_expect_success 'http:// --negotiate-only' ' |
| 1233 | SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" && |
| 1234 | URI="$HTTPD_URL/smart/server" && |
| 1235 | |
| 1236 | setup_negotiate_only "$SERVER" "$URI" && |
| 1237 | |
| 1238 | git -c protocol.version=2 -C client fetch \ |
| 1239 | --no-tags \ |
| 1240 | --negotiate-only \ |
| 1241 | --negotiation-tip=$(git -C client rev-parse HEAD) \ |
| 1242 | origin >out && |
| 1243 | COMMON=$(git -C "$SERVER" rev-parse two) && |
| 1244 | grep "$COMMON" out |
| 1245 | ' |
| 1246 | |
| 1247 | test_expect_success 'http:// --negotiate-only without wait-for-done support' ' |
| 1248 | SERVER="server" && |
| 1249 | URI="$HTTPD_URL/one_time_perl/server" && |
| 1250 | |
| 1251 | setup_negotiate_only "$SERVER" "$URI" && |
| 1252 | |
| 1253 | echo "s/ wait-for-done/ xxxx-xxx-xxxx/" \ |
| 1254 | >"$HTTPD_ROOT_PATH/one-time-perl" && |
| 1255 | |
| 1256 | test_must_fail git -c protocol.version=2 -C client fetch \ |
| 1257 | --no-tags \ |
| 1258 | --negotiate-only \ |
| 1259 | --negotiation-tip=$(git -C client rev-parse HEAD) \ |
| 1260 | origin 2>err && |
| 1261 | test_i18ngrep "server does not support wait-for-done" err |
| 1262 | ' |
| 1263 | |
| 1264 | test_expect_success 'http:// --negotiate-only with protocol v0' ' |
| 1265 | SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" && |
| 1266 | URI="$HTTPD_URL/smart/server" && |
| 1267 | |
| 1268 | setup_negotiate_only "$SERVER" "$URI" && |
| 1269 | |
| 1270 | test_must_fail git -c protocol.version=0 -C client fetch \ |
| 1271 | --no-tags \ |
| 1272 | --negotiate-only \ |
| 1273 | --negotiation-tip=$(git -C client rev-parse HEAD) \ |
| 1274 | origin 2>err && |
| 1275 | test_i18ngrep "negotiate-only requires protocol v2" err |
| 1276 | ' |
| 1277 | |
SZEDER Gábor | decfe05 | 2019-08-01 17:53:09 +0200 | [diff] [blame] | 1278 | # DO NOT add non-httpd-specific tests here, because the last part of this |
| 1279 | # test script is only executed when httpd is available and enabled. |
| 1280 | |
Brandon Williams | e52449b | 2018-03-15 10:31:21 -0700 | [diff] [blame] | 1281 | test_done |