Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Johannes Schindelin | b7ce24d | 2019-04-18 06:16:51 -0700 | [diff] [blame] | 3 | test_description='test protocol v2 server commands' |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 4 | |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
Ævar Arnfjörð Bjarmason | d96fb14 | 2021-10-31 00:24:13 +0200 | [diff] [blame] | 8 | TEST_PASSES_SANITIZE_LEAK=true |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 9 | . ./test-lib.sh |
| 10 | |
| 11 | test_expect_success 'test capability advertisement' ' |
brian m. carlson | 9de0dd3 | 2020-05-25 19:59:17 +0000 | [diff] [blame] | 12 | test_oid_cache <<-EOF && |
| 13 | wrong_algo sha1:sha256 |
| 14 | wrong_algo sha256:sha1 |
| 15 | EOF |
Ævar Arnfjörð Bjarmason | 8b8d9a2 | 2022-12-22 15:14:07 +0000 | [diff] [blame] | 16 | cat >expect.base <<-EOF && |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 17 | version 2 |
| 18 | agent=git/$(git version | cut -d" " -f3) |
Jonathan Tan | 59e1205 | 2021-02-05 12:48:47 -0800 | [diff] [blame] | 19 | ls-refs=unborn |
Jonathan Tan | 9c1e657 | 2021-05-04 14:16:01 -0700 | [diff] [blame] | 20 | fetch=shallow wait-for-done |
Brandon Williams | ecc3e53 | 2018-04-23 15:46:22 -0700 | [diff] [blame] | 21 | server-option |
brian m. carlson | 9de0dd3 | 2020-05-25 19:59:17 +0000 | [diff] [blame] | 22 | object-format=$(test_oid algo) |
Bruno Albuquerque | a2ba162 | 2021-04-20 16:38:31 -0700 | [diff] [blame] | 23 | object-info |
Ævar Arnfjörð Bjarmason | 8b8d9a2 | 2022-12-22 15:14:07 +0000 | [diff] [blame] | 24 | EOF |
| 25 | cat >expect.trailer <<-EOF && |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 26 | 0000 |
| 27 | EOF |
Ævar Arnfjörð Bjarmason | 8b8d9a2 | 2022-12-22 15:14:07 +0000 | [diff] [blame] | 28 | cat expect.base expect.trailer >expect && |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 29 | |
Johannes Schindelin | b7ce24d | 2019-04-18 06:16:51 -0700 | [diff] [blame] | 30 | GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \ |
| 31 | --advertise-capabilities >out && |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 32 | test-tool pkt-line unpack <out >actual && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 33 | test_cmp expect actual |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 34 | ' |
| 35 | |
| 36 | test_expect_success 'stateless-rpc flag does not list capabilities' ' |
| 37 | # Empty request |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 38 | test-tool pkt-line pack >in <<-EOF && |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 39 | 0000 |
| 40 | EOF |
Johannes Schindelin | b7ce24d | 2019-04-18 06:16:51 -0700 | [diff] [blame] | 41 | test-tool serve-v2 --stateless-rpc >out <in && |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 42 | test_must_be_empty out && |
| 43 | |
| 44 | # EOF |
Johannes Schindelin | b7ce24d | 2019-04-18 06:16:51 -0700 | [diff] [blame] | 45 | test-tool serve-v2 --stateless-rpc >out && |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 46 | test_must_be_empty out |
| 47 | ' |
| 48 | |
| 49 | test_expect_success 'request invalid capability' ' |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 50 | test-tool pkt-line pack >in <<-EOF && |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 51 | foobar |
| 52 | 0000 |
| 53 | EOF |
Johannes Schindelin | b7ce24d | 2019-04-18 06:16:51 -0700 | [diff] [blame] | 54 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 55 | test_grep "unknown capability" err |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 56 | ' |
| 57 | |
| 58 | test_expect_success 'request with no command' ' |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 59 | test-tool pkt-line pack >in <<-EOF && |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 60 | agent=git/test |
brian m. carlson | 9de0dd3 | 2020-05-25 19:59:17 +0000 | [diff] [blame] | 61 | object-format=$(test_oid algo) |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 62 | 0000 |
| 63 | EOF |
Johannes Schindelin | b7ce24d | 2019-04-18 06:16:51 -0700 | [diff] [blame] | 64 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 65 | test_grep "no command requested" err |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 66 | ' |
| 67 | |
| 68 | test_expect_success 'request invalid command' ' |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 69 | test-tool pkt-line pack >in <<-EOF && |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 70 | command=foo |
brian m. carlson | 9de0dd3 | 2020-05-25 19:59:17 +0000 | [diff] [blame] | 71 | object-format=$(test_oid algo) |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 72 | agent=git/test |
| 73 | 0000 |
| 74 | EOF |
Johannes Schindelin | b7ce24d | 2019-04-18 06:16:51 -0700 | [diff] [blame] | 75 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 76 | test_grep "invalid command" err |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 77 | ' |
| 78 | |
Jeff King | 0ab7eec | 2021-09-15 14:36:36 -0400 | [diff] [blame] | 79 | test_expect_success 'request capability as command' ' |
| 80 | test-tool pkt-line pack >in <<-EOF && |
| 81 | command=agent |
| 82 | object-format=$(test_oid algo) |
| 83 | 0000 |
| 84 | EOF |
| 85 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && |
| 86 | grep invalid.command.*agent err |
| 87 | ' |
| 88 | |
| 89 | test_expect_success 'request command as capability' ' |
| 90 | test-tool pkt-line pack >in <<-EOF && |
| 91 | command=ls-refs |
| 92 | object-format=$(test_oid algo) |
| 93 | fetch |
| 94 | 0000 |
| 95 | EOF |
| 96 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && |
| 97 | grep unknown.capability err |
| 98 | ' |
| 99 | |
Jeff King | 108c265 | 2021-09-15 14:36:33 -0400 | [diff] [blame] | 100 | test_expect_success 'requested command is command=value' ' |
| 101 | test-tool pkt-line pack >in <<-EOF && |
| 102 | command=ls-refs=whatever |
| 103 | object-format=$(test_oid algo) |
| 104 | 0000 |
| 105 | EOF |
| 106 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && |
| 107 | grep invalid.command.*ls-refs=whatever err |
| 108 | ' |
| 109 | |
brian m. carlson | 9de0dd3 | 2020-05-25 19:59:17 +0000 | [diff] [blame] | 110 | test_expect_success 'wrong object-format' ' |
| 111 | test-tool pkt-line pack >in <<-EOF && |
| 112 | command=fetch |
| 113 | agent=git/test |
| 114 | object-format=$(test_oid wrong_algo) |
| 115 | 0000 |
| 116 | EOF |
| 117 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 118 | test_grep "mismatched object format" err |
brian m. carlson | 9de0dd3 | 2020-05-25 19:59:17 +0000 | [diff] [blame] | 119 | ' |
| 120 | |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 121 | # Test the basics of ls-refs |
| 122 | # |
| 123 | test_expect_success 'setup some refs and tags' ' |
| 124 | test_commit one && |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 125 | git branch dev main && |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 126 | test_commit two && |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 127 | git symbolic-ref refs/heads/release refs/heads/main && |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 128 | git tag -a -m "annotated tag" annotated-tag |
| 129 | ' |
| 130 | |
| 131 | test_expect_success 'basics of ls-refs' ' |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 132 | test-tool pkt-line pack >in <<-EOF && |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 133 | command=ls-refs |
brian m. carlson | 9de0dd3 | 2020-05-25 19:59:17 +0000 | [diff] [blame] | 134 | object-format=$(test_oid algo) |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 135 | 0000 |
| 136 | EOF |
| 137 | |
| 138 | cat >expect <<-EOF && |
| 139 | $(git rev-parse HEAD) HEAD |
| 140 | $(git rev-parse refs/heads/dev) refs/heads/dev |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 141 | $(git rev-parse refs/heads/main) refs/heads/main |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 142 | $(git rev-parse refs/heads/release) refs/heads/release |
| 143 | $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag |
| 144 | $(git rev-parse refs/tags/one) refs/tags/one |
| 145 | $(git rev-parse refs/tags/two) refs/tags/two |
| 146 | 0000 |
| 147 | EOF |
| 148 | |
Johannes Schindelin | b7ce24d | 2019-04-18 06:16:51 -0700 | [diff] [blame] | 149 | test-tool serve-v2 --stateless-rpc <in >out && |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 150 | test-tool pkt-line unpack <out >actual && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 151 | test_cmp expect actual |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 152 | ' |
| 153 | |
Jeff King | ccf0947 | 2021-09-15 14:36:38 -0400 | [diff] [blame] | 154 | test_expect_success 'ls-refs complains about unknown options' ' |
| 155 | test-tool pkt-line pack >in <<-EOF && |
| 156 | command=ls-refs |
| 157 | object-format=$(test_oid algo) |
| 158 | 0001 |
| 159 | no-such-arg |
| 160 | 0000 |
| 161 | EOF |
| 162 | |
| 163 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && |
| 164 | grep unexpected.line.*no-such-arg err |
| 165 | ' |
| 166 | |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 167 | test_expect_success 'basic ref-prefixes' ' |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 168 | test-tool pkt-line pack >in <<-EOF && |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 169 | command=ls-refs |
brian m. carlson | 9de0dd3 | 2020-05-25 19:59:17 +0000 | [diff] [blame] | 170 | object-format=$(test_oid algo) |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 171 | 0001 |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 172 | ref-prefix refs/heads/main |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 173 | ref-prefix refs/tags/one |
| 174 | 0000 |
| 175 | EOF |
| 176 | |
| 177 | cat >expect <<-EOF && |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 178 | $(git rev-parse refs/heads/main) refs/heads/main |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 179 | $(git rev-parse refs/tags/one) refs/tags/one |
| 180 | 0000 |
| 181 | EOF |
| 182 | |
Johannes Schindelin | b7ce24d | 2019-04-18 06:16:51 -0700 | [diff] [blame] | 183 | test-tool serve-v2 --stateless-rpc <in >out && |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 184 | test-tool pkt-line unpack <out >actual && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 185 | test_cmp expect actual |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 186 | ' |
| 187 | |
| 188 | test_expect_success 'refs/heads prefix' ' |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 189 | test-tool pkt-line pack >in <<-EOF && |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 190 | command=ls-refs |
brian m. carlson | 9de0dd3 | 2020-05-25 19:59:17 +0000 | [diff] [blame] | 191 | object-format=$(test_oid algo) |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 192 | 0001 |
| 193 | ref-prefix refs/heads/ |
| 194 | 0000 |
| 195 | EOF |
| 196 | |
| 197 | cat >expect <<-EOF && |
| 198 | $(git rev-parse refs/heads/dev) refs/heads/dev |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 199 | $(git rev-parse refs/heads/main) refs/heads/main |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 200 | $(git rev-parse refs/heads/release) refs/heads/release |
| 201 | 0000 |
| 202 | EOF |
| 203 | |
Johannes Schindelin | b7ce24d | 2019-04-18 06:16:51 -0700 | [diff] [blame] | 204 | test-tool serve-v2 --stateless-rpc <in >out && |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 205 | test-tool pkt-line unpack <out >actual && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 206 | test_cmp expect actual |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 207 | ' |
| 208 | |
Jeff King | 7f0e4f6 | 2021-09-15 14:35:31 -0400 | [diff] [blame] | 209 | test_expect_success 'ignore very large set of prefixes' ' |
| 210 | # generate a large number of ref-prefixes that we expect |
| 211 | # to match nothing; the value here exceeds TOO_MANY_PREFIXES |
| 212 | # from ls-refs.c. |
| 213 | { |
| 214 | echo command=ls-refs && |
| 215 | echo object-format=$(test_oid algo) && |
| 216 | echo 0001 && |
| 217 | perl -le "print \"ref-prefix refs/heads/\$_\" for (1..65536)" && |
| 218 | echo 0000 |
| 219 | } | |
| 220 | test-tool pkt-line pack >in && |
| 221 | |
| 222 | # and then confirm that we see unmatched prefixes anyway (i.e., |
| 223 | # that the prefix was not applied). |
| 224 | cat >expect <<-EOF && |
| 225 | $(git rev-parse HEAD) HEAD |
| 226 | $(git rev-parse refs/heads/dev) refs/heads/dev |
| 227 | $(git rev-parse refs/heads/main) refs/heads/main |
| 228 | $(git rev-parse refs/heads/release) refs/heads/release |
| 229 | $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag |
| 230 | $(git rev-parse refs/tags/one) refs/tags/one |
| 231 | $(git rev-parse refs/tags/two) refs/tags/two |
| 232 | 0000 |
| 233 | EOF |
| 234 | |
| 235 | test-tool serve-v2 --stateless-rpc <in >out && |
| 236 | test-tool pkt-line unpack <out >actual && |
| 237 | test_cmp expect actual |
| 238 | ' |
| 239 | |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 240 | test_expect_success 'peel parameter' ' |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 241 | test-tool pkt-line pack >in <<-EOF && |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 242 | command=ls-refs |
brian m. carlson | 9de0dd3 | 2020-05-25 19:59:17 +0000 | [diff] [blame] | 243 | object-format=$(test_oid algo) |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 244 | 0001 |
| 245 | peel |
| 246 | ref-prefix refs/tags/ |
| 247 | 0000 |
| 248 | EOF |
| 249 | |
| 250 | cat >expect <<-EOF && |
| 251 | $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{}) |
| 252 | $(git rev-parse refs/tags/one) refs/tags/one |
| 253 | $(git rev-parse refs/tags/two) refs/tags/two |
| 254 | 0000 |
| 255 | EOF |
| 256 | |
Johannes Schindelin | b7ce24d | 2019-04-18 06:16:51 -0700 | [diff] [blame] | 257 | test-tool serve-v2 --stateless-rpc <in >out && |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 258 | test-tool pkt-line unpack <out >actual && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 259 | test_cmp expect actual |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 260 | ' |
| 261 | |
| 262 | test_expect_success 'symrefs parameter' ' |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 263 | test-tool pkt-line pack >in <<-EOF && |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 264 | command=ls-refs |
brian m. carlson | 9de0dd3 | 2020-05-25 19:59:17 +0000 | [diff] [blame] | 265 | object-format=$(test_oid algo) |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 266 | 0001 |
| 267 | symrefs |
| 268 | ref-prefix refs/heads/ |
| 269 | 0000 |
| 270 | EOF |
| 271 | |
| 272 | cat >expect <<-EOF && |
| 273 | $(git rev-parse refs/heads/dev) refs/heads/dev |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 274 | $(git rev-parse refs/heads/main) refs/heads/main |
| 275 | $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/main |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 276 | 0000 |
| 277 | EOF |
| 278 | |
Johannes Schindelin | b7ce24d | 2019-04-18 06:16:51 -0700 | [diff] [blame] | 279 | test-tool serve-v2 --stateless-rpc <in >out && |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 280 | test-tool pkt-line unpack <out >actual && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 281 | test_cmp expect actual |
Brandon Williams | 72d0ea0 | 2018-03-15 10:31:20 -0700 | [diff] [blame] | 282 | ' |
| 283 | |
Brandon Williams | ecc3e53 | 2018-04-23 15:46:22 -0700 | [diff] [blame] | 284 | test_expect_success 'sending server-options' ' |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 285 | test-tool pkt-line pack >in <<-EOF && |
Brandon Williams | ecc3e53 | 2018-04-23 15:46:22 -0700 | [diff] [blame] | 286 | command=ls-refs |
brian m. carlson | 9de0dd3 | 2020-05-25 19:59:17 +0000 | [diff] [blame] | 287 | object-format=$(test_oid algo) |
Brandon Williams | ecc3e53 | 2018-04-23 15:46:22 -0700 | [diff] [blame] | 288 | server-option=hello |
| 289 | server-option=world |
| 290 | 0001 |
| 291 | ref-prefix HEAD |
| 292 | 0000 |
| 293 | EOF |
| 294 | |
| 295 | cat >expect <<-EOF && |
| 296 | $(git rev-parse HEAD) HEAD |
| 297 | 0000 |
| 298 | EOF |
| 299 | |
Johannes Schindelin | b7ce24d | 2019-04-18 06:16:51 -0700 | [diff] [blame] | 300 | test-tool serve-v2 --stateless-rpc <in >out && |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 301 | test-tool pkt-line unpack <out >actual && |
Matthew DeVore | dcbaa0b | 2018-10-05 14:54:04 -0700 | [diff] [blame] | 302 | test_cmp expect actual |
Brandon Williams | ecc3e53 | 2018-04-23 15:46:22 -0700 | [diff] [blame] | 303 | ' |
| 304 | |
Jonathan Tan | 7cc6ed2 | 2018-05-01 17:31:29 -0700 | [diff] [blame] | 305 | test_expect_success 'unexpected lines are not allowed in fetch request' ' |
| 306 | git init server && |
| 307 | |
Nguyễn Thái Ngọc Duy | 8ea40cc | 2018-09-09 19:36:28 +0200 | [diff] [blame] | 308 | test-tool pkt-line pack >in <<-EOF && |
Jonathan Tan | 7cc6ed2 | 2018-05-01 17:31:29 -0700 | [diff] [blame] | 309 | command=fetch |
brian m. carlson | 9de0dd3 | 2020-05-25 19:59:17 +0000 | [diff] [blame] | 310 | object-format=$(test_oid algo) |
Jonathan Tan | 7cc6ed2 | 2018-05-01 17:31:29 -0700 | [diff] [blame] | 311 | 0001 |
| 312 | this-is-not-a-command |
| 313 | 0000 |
| 314 | EOF |
| 315 | |
Johannes Schindelin | b7ce24d | 2019-04-18 06:16:51 -0700 | [diff] [blame] | 316 | ( |
| 317 | cd server && |
| 318 | test_must_fail test-tool serve-v2 --stateless-rpc |
| 319 | ) <in >/dev/null 2>err && |
Jonathan Tan | 7cc6ed2 | 2018-05-01 17:31:29 -0700 | [diff] [blame] | 320 | grep "unexpected line: .this-is-not-a-command." err |
| 321 | ' |
| 322 | |
Bruno Albuquerque | a2ba162 | 2021-04-20 16:38:31 -0700 | [diff] [blame] | 323 | # Test the basics of object-info |
| 324 | # |
| 325 | test_expect_success 'basics of object-info' ' |
| 326 | test-tool pkt-line pack >in <<-EOF && |
| 327 | command=object-info |
| 328 | object-format=$(test_oid algo) |
| 329 | 0001 |
| 330 | size |
| 331 | oid $(git rev-parse two:two.t) |
| 332 | oid $(git rev-parse two:two.t) |
| 333 | 0000 |
| 334 | EOF |
| 335 | |
| 336 | cat >expect <<-EOF && |
| 337 | size |
| 338 | $(git rev-parse two:two.t) $(wc -c <two.t | xargs) |
| 339 | $(git rev-parse two:two.t) $(wc -c <two.t | xargs) |
| 340 | 0000 |
| 341 | EOF |
| 342 | |
| 343 | test-tool serve-v2 --stateless-rpc <in >out && |
| 344 | test-tool pkt-line unpack <out >actual && |
| 345 | test_cmp expect actual |
| 346 | ' |
| 347 | |
Ævar Arnfjörð Bjarmason | 8b8d9a2 | 2022-12-22 15:14:07 +0000 | [diff] [blame] | 348 | test_expect_success 'test capability advertisement with uploadpack.advertiseBundleURIs' ' |
| 349 | test_config uploadpack.advertiseBundleURIs true && |
| 350 | |
| 351 | cat >expect.extra <<-EOF && |
| 352 | bundle-uri |
| 353 | EOF |
| 354 | cat expect.base \ |
| 355 | expect.extra \ |
| 356 | expect.trailer >expect && |
| 357 | |
| 358 | GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \ |
| 359 | --advertise-capabilities >out && |
| 360 | test-tool pkt-line unpack <out >actual && |
| 361 | test_cmp expect actual |
| 362 | ' |
| 363 | |
| 364 | test_expect_success 'basics of bundle-uri: dies if not enabled' ' |
| 365 | test-tool pkt-line pack >in <<-EOF && |
| 366 | command=bundle-uri |
| 367 | 0000 |
| 368 | EOF |
| 369 | |
| 370 | cat >err.expect <<-\EOF && |
| 371 | fatal: invalid command '"'"'bundle-uri'"'"' |
| 372 | EOF |
| 373 | |
| 374 | cat >expect <<-\EOF && |
| 375 | ERR serve: invalid command '"'"'bundle-uri'"'"' |
| 376 | EOF |
| 377 | |
| 378 | test_must_fail test-tool serve-v2 --stateless-rpc <in >out 2>err.actual && |
| 379 | test_cmp err.expect err.actual && |
| 380 | test_must_be_empty out |
| 381 | ' |
| 382 | |
Brandon Williams | ed10cb9 | 2018-03-15 10:31:19 -0700 | [diff] [blame] | 383 | test_done |