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)
19 fetch=shallow wait-for-done
21 object-format=$(test_oid algo)
26 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
27 --advertise-capabilities >out &&
28 test-tool pkt-line unpack <out >actual &&
29 test_cmp expect actual
32 test_expect_success
'stateless-rpc flag does not list capabilities' '
34 test-tool pkt-line pack >in <<-EOF &&
37 test-tool serve-v2 --stateless-rpc >out <in &&
38 test_must_be_empty out &&
41 test-tool serve-v2 --stateless-rpc >out &&
42 test_must_be_empty out
45 test_expect_success
'request invalid capability' '
46 test-tool pkt-line pack >in <<-EOF &&
50 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
51 test_i18ngrep "unknown capability" err
54 test_expect_success
'request with no command' '
55 test-tool pkt-line pack >in <<-EOF &&
57 object-format=$(test_oid algo)
60 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
61 test_i18ngrep "no command requested" err
64 test_expect_success
'request invalid command' '
65 test-tool pkt-line pack >in <<-EOF &&
67 object-format=$(test_oid algo)
71 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
72 test_i18ngrep "invalid command" err
75 test_expect_success
'wrong object-format' '
76 test-tool pkt-line pack >in <<-EOF &&
79 object-format=$(test_oid wrong_algo)
82 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
83 test_i18ngrep "mismatched object format" err
86 # Test the basics of ls-refs
88 test_expect_success
'setup some refs and tags' '
90 git branch dev main &&
92 git symbolic-ref refs/heads/release refs/heads/main &&
93 git tag -a -m "annotated tag" annotated-tag
96 test_expect_success
'basics of ls-refs' '
97 test-tool pkt-line pack >in <<-EOF &&
99 object-format=$(test_oid algo)
103 cat >expect <<-EOF &&
104 $(git rev-parse HEAD) HEAD
105 $(git rev-parse refs/heads/dev) refs/heads/dev
106 $(git rev-parse refs/heads/main) refs/heads/main
107 $(git rev-parse refs/heads/release) refs/heads/release
108 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
109 $(git rev-parse refs/tags/one) refs/tags/one
110 $(git rev-parse refs/tags/two) refs/tags/two
114 test-tool serve-v2 --stateless-rpc <in >out &&
115 test-tool pkt-line unpack <out >actual &&
116 test_cmp expect actual
119 test_expect_success
'basic ref-prefixes' '
120 test-tool pkt-line pack >in <<-EOF &&
122 object-format=$(test_oid algo)
124 ref-prefix refs/heads/main
125 ref-prefix refs/tags/one
129 cat >expect <<-EOF &&
130 $(git rev-parse refs/heads/main) refs/heads/main
131 $(git rev-parse refs/tags/one) refs/tags/one
135 test-tool serve-v2 --stateless-rpc <in >out &&
136 test-tool pkt-line unpack <out >actual &&
137 test_cmp expect actual
140 test_expect_success
'refs/heads prefix' '
141 test-tool pkt-line pack >in <<-EOF &&
143 object-format=$(test_oid algo)
145 ref-prefix refs/heads/
149 cat >expect <<-EOF &&
150 $(git rev-parse refs/heads/dev) refs/heads/dev
151 $(git rev-parse refs/heads/main) refs/heads/main
152 $(git rev-parse refs/heads/release) refs/heads/release
156 test-tool serve-v2 --stateless-rpc <in >out &&
157 test-tool pkt-line unpack <out >actual &&
158 test_cmp expect actual
161 test_expect_success
'peel parameter' '
162 test-tool pkt-line pack >in <<-EOF &&
164 object-format=$(test_oid algo)
167 ref-prefix refs/tags/
171 cat >expect <<-EOF &&
172 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{})
173 $(git rev-parse refs/tags/one) refs/tags/one
174 $(git rev-parse refs/tags/two) refs/tags/two
178 test-tool serve-v2 --stateless-rpc <in >out &&
179 test-tool pkt-line unpack <out >actual &&
180 test_cmp expect actual
183 test_expect_success
'symrefs parameter' '
184 test-tool pkt-line pack >in <<-EOF &&
186 object-format=$(test_oid algo)
189 ref-prefix refs/heads/
193 cat >expect <<-EOF &&
194 $(git rev-parse refs/heads/dev) refs/heads/dev
195 $(git rev-parse refs/heads/main) refs/heads/main
196 $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/main
200 test-tool serve-v2 --stateless-rpc <in >out &&
201 test-tool pkt-line unpack <out >actual &&
202 test_cmp expect actual
205 test_expect_success
'sending server-options' '
206 test-tool pkt-line pack >in <<-EOF &&
208 object-format=$(test_oid algo)
216 cat >expect <<-EOF &&
217 $(git rev-parse HEAD) HEAD
221 test-tool serve-v2 --stateless-rpc <in >out &&
222 test-tool pkt-line unpack <out >actual &&
223 test_cmp expect actual
226 test_expect_success
'unexpected lines are not allowed in fetch request' '
229 test-tool pkt-line pack >in <<-EOF &&
231 object-format=$(test_oid algo)
233 this-is-not-a-command
239 test_must_fail test-tool serve-v2 --stateless-rpc
240 ) <in >/dev/null 2>err &&
241 grep "unexpected line: .this-is-not-a-command." err
244 # Test the basics of object-info
246 test_expect_success
'basics of object-info' '
247 test-tool pkt-line pack >in <<-EOF &&
249 object-format=$(test_oid algo)
252 oid $(git rev-parse two:two.t)
253 oid $(git rev-parse two:two.t)
257 cat >expect <<-EOF &&
259 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
260 $(git rev-parse two:two.t) $(wc -c <two.t | xargs)
264 test-tool serve-v2 --stateless-rpc <in >out &&
265 test-tool pkt-line unpack <out >actual &&
266 test_cmp expect actual