3 test_description
='test protocol v2 server commands'
7 test_expect_success
'test capability advertisement' '
8 test_oid_cache <<-EOF &&
10 wrong_algo sha256:sha1
14 agent=git/$(git version | cut -d" " -f3)
18 object-format=$(test_oid algo)
22 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
23 --advertise-capabilities >out &&
24 test-tool pkt-line unpack <out >actual &&
25 test_cmp expect actual
28 test_expect_success
'stateless-rpc flag does not list capabilities' '
30 test-tool pkt-line pack >in <<-EOF &&
33 test-tool serve-v2 --stateless-rpc >out <in &&
34 test_must_be_empty out &&
37 test-tool serve-v2 --stateless-rpc >out &&
38 test_must_be_empty out
41 test_expect_success
'request invalid capability' '
42 test-tool pkt-line pack >in <<-EOF &&
46 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
47 test_i18ngrep "unknown capability" err
50 test_expect_success
'request with no command' '
51 test-tool pkt-line pack >in <<-EOF &&
53 object-format=$(test_oid algo)
56 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
57 test_i18ngrep "no command requested" err
60 test_expect_success
'request invalid command' '
61 test-tool pkt-line pack >in <<-EOF &&
63 object-format=$(test_oid algo)
67 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
68 test_i18ngrep "invalid command" err
71 test_expect_success
'wrong object-format' '
72 test-tool pkt-line pack >in <<-EOF &&
75 object-format=$(test_oid wrong_algo)
78 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
79 test_i18ngrep "mismatched object format" err
82 # Test the basics of ls-refs
84 test_expect_success
'setup some refs and tags' '
86 git branch dev master &&
88 git symbolic-ref refs/heads/release refs/heads/master &&
89 git tag -a -m "annotated tag" annotated-tag
92 test_expect_success
'basics of ls-refs' '
93 test-tool pkt-line pack >in <<-EOF &&
95 object-format=$(test_oid algo)
100 $(git rev-parse HEAD) HEAD
101 $(git rev-parse refs/heads/dev) refs/heads/dev
102 $(git rev-parse refs/heads/master) refs/heads/master
103 $(git rev-parse refs/heads/release) refs/heads/release
104 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
105 $(git rev-parse refs/tags/one) refs/tags/one
106 $(git rev-parse refs/tags/two) refs/tags/two
110 test-tool serve-v2 --stateless-rpc <in >out &&
111 test-tool pkt-line unpack <out >actual &&
112 test_cmp expect actual
115 test_expect_success
'basic ref-prefixes' '
116 test-tool pkt-line pack >in <<-EOF &&
118 object-format=$(test_oid algo)
120 ref-prefix refs/heads/master
121 ref-prefix refs/tags/one
125 cat >expect <<-EOF &&
126 $(git rev-parse refs/heads/master) refs/heads/master
127 $(git rev-parse refs/tags/one) refs/tags/one
131 test-tool serve-v2 --stateless-rpc <in >out &&
132 test-tool pkt-line unpack <out >actual &&
133 test_cmp expect actual
136 test_expect_success
'refs/heads prefix' '
137 test-tool pkt-line pack >in <<-EOF &&
139 object-format=$(test_oid algo)
141 ref-prefix refs/heads/
145 cat >expect <<-EOF &&
146 $(git rev-parse refs/heads/dev) refs/heads/dev
147 $(git rev-parse refs/heads/master) refs/heads/master
148 $(git rev-parse refs/heads/release) refs/heads/release
152 test-tool serve-v2 --stateless-rpc <in >out &&
153 test-tool pkt-line unpack <out >actual &&
154 test_cmp expect actual
157 test_expect_success
'peel parameter' '
158 test-tool pkt-line pack >in <<-EOF &&
160 object-format=$(test_oid algo)
163 ref-prefix refs/tags/
167 cat >expect <<-EOF &&
168 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{})
169 $(git rev-parse refs/tags/one) refs/tags/one
170 $(git rev-parse refs/tags/two) refs/tags/two
174 test-tool serve-v2 --stateless-rpc <in >out &&
175 test-tool pkt-line unpack <out >actual &&
176 test_cmp expect actual
179 test_expect_success
'symrefs parameter' '
180 test-tool pkt-line pack >in <<-EOF &&
182 object-format=$(test_oid algo)
185 ref-prefix refs/heads/
189 cat >expect <<-EOF &&
190 $(git rev-parse refs/heads/dev) refs/heads/dev
191 $(git rev-parse refs/heads/master) refs/heads/master
192 $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/master
196 test-tool serve-v2 --stateless-rpc <in >out &&
197 test-tool pkt-line unpack <out >actual &&
198 test_cmp expect actual
201 test_expect_success
'sending server-options' '
202 test-tool pkt-line pack >in <<-EOF &&
204 object-format=$(test_oid algo)
212 cat >expect <<-EOF &&
213 $(git rev-parse HEAD) HEAD
217 test-tool serve-v2 --stateless-rpc <in >out &&
218 test-tool pkt-line unpack <out >actual &&
219 test_cmp expect actual
222 test_expect_success
'unexpected lines are not allowed in fetch request' '
225 test-tool pkt-line pack >in <<-EOF &&
227 object-format=$(test_oid algo)
229 this-is-not-a-command
235 test_must_fail test-tool serve-v2 --stateless-rpc
236 ) <in >/dev/null 2>err &&
237 grep "unexpected line: .this-is-not-a-command." err