3 test_description
='test protocol v2 server commands'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success
'test capability advertisement' '
11 test_oid_cache <<-EOF &&
12 wrong_algo sha1:sha256
13 wrong_algo sha256:sha1
17 agent=git/$(git version | cut -d" " -f3)
21 object-format=$(test_oid algo)
25 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
26 --advertise-capabilities >out &&
27 test-tool pkt-line unpack <out >actual &&
28 test_cmp expect actual
31 test_expect_success
'stateless-rpc flag does not list capabilities' '
33 test-tool pkt-line pack >in <<-EOF &&
36 test-tool serve-v2 --stateless-rpc >out <in &&
37 test_must_be_empty out &&
40 test-tool serve-v2 --stateless-rpc >out &&
41 test_must_be_empty out
44 test_expect_success
'request invalid capability' '
45 test-tool pkt-line pack >in <<-EOF &&
49 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
50 test_i18ngrep "unknown capability" err
53 test_expect_success
'request with no command' '
54 test-tool pkt-line pack >in <<-EOF &&
56 object-format=$(test_oid algo)
59 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
60 test_i18ngrep "no command requested" err
63 test_expect_success
'request invalid command' '
64 test-tool pkt-line pack >in <<-EOF &&
66 object-format=$(test_oid algo)
70 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
71 test_i18ngrep "invalid command" err
74 test_expect_success
'wrong object-format' '
75 test-tool pkt-line pack >in <<-EOF &&
78 object-format=$(test_oid wrong_algo)
81 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
82 test_i18ngrep "mismatched object format" err
85 # Test the basics of ls-refs
87 test_expect_success
'setup some refs and tags' '
89 git branch dev main &&
91 git symbolic-ref refs/heads/release refs/heads/main &&
92 git tag -a -m "annotated tag" annotated-tag
95 test_expect_success
'basics of ls-refs' '
96 test-tool pkt-line pack >in <<-EOF &&
98 object-format=$(test_oid algo)
102 cat >expect <<-EOF &&
103 $(git rev-parse HEAD) HEAD
104 $(git rev-parse refs/heads/dev) refs/heads/dev
105 $(git rev-parse refs/heads/main) refs/heads/main
106 $(git rev-parse refs/heads/release) refs/heads/release
107 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
108 $(git rev-parse refs/tags/one) refs/tags/one
109 $(git rev-parse refs/tags/two) refs/tags/two
113 test-tool serve-v2 --stateless-rpc <in >out &&
114 test-tool pkt-line unpack <out >actual &&
115 test_cmp expect actual
118 test_expect_success
'basic ref-prefixes' '
119 test-tool pkt-line pack >in <<-EOF &&
121 object-format=$(test_oid algo)
123 ref-prefix refs/heads/main
124 ref-prefix refs/tags/one
128 cat >expect <<-EOF &&
129 $(git rev-parse refs/heads/main) refs/heads/main
130 $(git rev-parse refs/tags/one) refs/tags/one
134 test-tool serve-v2 --stateless-rpc <in >out &&
135 test-tool pkt-line unpack <out >actual &&
136 test_cmp expect actual
139 test_expect_success
'refs/heads prefix' '
140 test-tool pkt-line pack >in <<-EOF &&
142 object-format=$(test_oid algo)
144 ref-prefix refs/heads/
148 cat >expect <<-EOF &&
149 $(git rev-parse refs/heads/dev) refs/heads/dev
150 $(git rev-parse refs/heads/main) refs/heads/main
151 $(git rev-parse refs/heads/release) refs/heads/release
155 test-tool serve-v2 --stateless-rpc <in >out &&
156 test-tool pkt-line unpack <out >actual &&
157 test_cmp expect actual
160 test_expect_success
'peel parameter' '
161 test-tool pkt-line pack >in <<-EOF &&
163 object-format=$(test_oid algo)
166 ref-prefix refs/tags/
170 cat >expect <<-EOF &&
171 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{})
172 $(git rev-parse refs/tags/one) refs/tags/one
173 $(git rev-parse refs/tags/two) refs/tags/two
177 test-tool serve-v2 --stateless-rpc <in >out &&
178 test-tool pkt-line unpack <out >actual &&
179 test_cmp expect actual
182 test_expect_success
'symrefs parameter' '
183 test-tool pkt-line pack >in <<-EOF &&
185 object-format=$(test_oid algo)
188 ref-prefix refs/heads/
192 cat >expect <<-EOF &&
193 $(git rev-parse refs/heads/dev) refs/heads/dev
194 $(git rev-parse refs/heads/main) refs/heads/main
195 $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/main
199 test-tool serve-v2 --stateless-rpc <in >out &&
200 test-tool pkt-line unpack <out >actual &&
201 test_cmp expect actual
204 test_expect_success
'sending server-options' '
205 test-tool pkt-line pack >in <<-EOF &&
207 object-format=$(test_oid algo)
215 cat >expect <<-EOF &&
216 $(git rev-parse HEAD) HEAD
220 test-tool serve-v2 --stateless-rpc <in >out &&
221 test-tool pkt-line unpack <out >actual &&
222 test_cmp expect actual
225 test_expect_success
'unexpected lines are not allowed in fetch request' '
228 test-tool pkt-line pack >in <<-EOF &&
230 object-format=$(test_oid algo)
232 this-is-not-a-command
238 test_must_fail test-tool serve-v2 --stateless-rpc
239 ) <in >/dev/null 2>err &&
240 grep "unexpected line: .this-is-not-a-command." err