]>
Commit | Line | Data |
---|---|---|
ed10cb95 BW |
1 | #!/bin/sh |
2 | ||
b7ce24d0 | 3 | test_description='test protocol v2 server commands' |
ed10cb95 BW |
4 | |
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success 'test capability advertisement' ' | |
8 | cat >expect <<-EOF && | |
9 | version 2 | |
10 | agent=git/$(git version | cut -d" " -f3) | |
72d0ea00 | 11 | ls-refs |
685fbd32 | 12 | fetch=shallow |
ecc3e534 | 13 | server-option |
ed10cb95 BW |
14 | 0000 |
15 | EOF | |
16 | ||
b7ce24d0 JS |
17 | GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \ |
18 | --advertise-capabilities >out && | |
8ea40cc5 | 19 | test-tool pkt-line unpack <out >actual && |
dcbaa0b3 | 20 | test_cmp expect actual |
ed10cb95 BW |
21 | ' |
22 | ||
23 | test_expect_success 'stateless-rpc flag does not list capabilities' ' | |
24 | # Empty request | |
8ea40cc5 | 25 | test-tool pkt-line pack >in <<-EOF && |
ed10cb95 BW |
26 | 0000 |
27 | EOF | |
b7ce24d0 | 28 | test-tool serve-v2 --stateless-rpc >out <in && |
ed10cb95 BW |
29 | test_must_be_empty out && |
30 | ||
31 | # EOF | |
b7ce24d0 | 32 | test-tool serve-v2 --stateless-rpc >out && |
ed10cb95 BW |
33 | test_must_be_empty out |
34 | ' | |
35 | ||
36 | test_expect_success 'request invalid capability' ' | |
8ea40cc5 | 37 | test-tool pkt-line pack >in <<-EOF && |
ed10cb95 BW |
38 | foobar |
39 | 0000 | |
40 | EOF | |
b7ce24d0 | 41 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && |
ed10cb95 BW |
42 | test_i18ngrep "unknown capability" err |
43 | ' | |
44 | ||
45 | test_expect_success 'request with no command' ' | |
8ea40cc5 | 46 | test-tool pkt-line pack >in <<-EOF && |
ed10cb95 BW |
47 | agent=git/test |
48 | 0000 | |
49 | EOF | |
b7ce24d0 | 50 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && |
ed10cb95 BW |
51 | test_i18ngrep "no command requested" err |
52 | ' | |
53 | ||
54 | test_expect_success 'request invalid command' ' | |
8ea40cc5 | 55 | test-tool pkt-line pack >in <<-EOF && |
ed10cb95 BW |
56 | command=foo |
57 | agent=git/test | |
58 | 0000 | |
59 | EOF | |
b7ce24d0 | 60 | test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && |
ed10cb95 BW |
61 | test_i18ngrep "invalid command" err |
62 | ' | |
63 | ||
72d0ea00 BW |
64 | # Test the basics of ls-refs |
65 | # | |
66 | test_expect_success 'setup some refs and tags' ' | |
67 | test_commit one && | |
68 | git branch dev master && | |
69 | test_commit two && | |
70 | git symbolic-ref refs/heads/release refs/heads/master && | |
71 | git tag -a -m "annotated tag" annotated-tag | |
72 | ' | |
73 | ||
74 | test_expect_success 'basics of ls-refs' ' | |
8ea40cc5 | 75 | test-tool pkt-line pack >in <<-EOF && |
72d0ea00 BW |
76 | command=ls-refs |
77 | 0000 | |
78 | EOF | |
79 | ||
80 | cat >expect <<-EOF && | |
81 | $(git rev-parse HEAD) HEAD | |
82 | $(git rev-parse refs/heads/dev) refs/heads/dev | |
83 | $(git rev-parse refs/heads/master) refs/heads/master | |
84 | $(git rev-parse refs/heads/release) refs/heads/release | |
85 | $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag | |
86 | $(git rev-parse refs/tags/one) refs/tags/one | |
87 | $(git rev-parse refs/tags/two) refs/tags/two | |
88 | 0000 | |
89 | EOF | |
90 | ||
b7ce24d0 | 91 | test-tool serve-v2 --stateless-rpc <in >out && |
8ea40cc5 | 92 | test-tool pkt-line unpack <out >actual && |
dcbaa0b3 | 93 | test_cmp expect actual |
72d0ea00 BW |
94 | ' |
95 | ||
96 | test_expect_success 'basic ref-prefixes' ' | |
8ea40cc5 | 97 | test-tool pkt-line pack >in <<-EOF && |
72d0ea00 BW |
98 | command=ls-refs |
99 | 0001 | |
100 | ref-prefix refs/heads/master | |
101 | ref-prefix refs/tags/one | |
102 | 0000 | |
103 | EOF | |
104 | ||
105 | cat >expect <<-EOF && | |
106 | $(git rev-parse refs/heads/master) refs/heads/master | |
107 | $(git rev-parse refs/tags/one) refs/tags/one | |
108 | 0000 | |
109 | EOF | |
110 | ||
b7ce24d0 | 111 | test-tool serve-v2 --stateless-rpc <in >out && |
8ea40cc5 | 112 | test-tool pkt-line unpack <out >actual && |
dcbaa0b3 | 113 | test_cmp expect actual |
72d0ea00 BW |
114 | ' |
115 | ||
116 | test_expect_success 'refs/heads prefix' ' | |
8ea40cc5 | 117 | test-tool pkt-line pack >in <<-EOF && |
72d0ea00 BW |
118 | command=ls-refs |
119 | 0001 | |
120 | ref-prefix refs/heads/ | |
121 | 0000 | |
122 | EOF | |
123 | ||
124 | cat >expect <<-EOF && | |
125 | $(git rev-parse refs/heads/dev) refs/heads/dev | |
126 | $(git rev-parse refs/heads/master) refs/heads/master | |
127 | $(git rev-parse refs/heads/release) refs/heads/release | |
128 | 0000 | |
129 | EOF | |
130 | ||
b7ce24d0 | 131 | test-tool serve-v2 --stateless-rpc <in >out && |
8ea40cc5 | 132 | test-tool pkt-line unpack <out >actual && |
dcbaa0b3 | 133 | test_cmp expect actual |
72d0ea00 BW |
134 | ' |
135 | ||
136 | test_expect_success 'peel parameter' ' | |
8ea40cc5 | 137 | test-tool pkt-line pack >in <<-EOF && |
72d0ea00 BW |
138 | command=ls-refs |
139 | 0001 | |
140 | peel | |
141 | ref-prefix refs/tags/ | |
142 | 0000 | |
143 | EOF | |
144 | ||
145 | cat >expect <<-EOF && | |
146 | $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{}) | |
147 | $(git rev-parse refs/tags/one) refs/tags/one | |
148 | $(git rev-parse refs/tags/two) refs/tags/two | |
149 | 0000 | |
150 | EOF | |
151 | ||
b7ce24d0 | 152 | test-tool serve-v2 --stateless-rpc <in >out && |
8ea40cc5 | 153 | test-tool pkt-line unpack <out >actual && |
dcbaa0b3 | 154 | test_cmp expect actual |
72d0ea00 BW |
155 | ' |
156 | ||
157 | test_expect_success 'symrefs parameter' ' | |
8ea40cc5 | 158 | test-tool pkt-line pack >in <<-EOF && |
72d0ea00 BW |
159 | command=ls-refs |
160 | 0001 | |
161 | symrefs | |
162 | ref-prefix refs/heads/ | |
163 | 0000 | |
164 | EOF | |
165 | ||
166 | cat >expect <<-EOF && | |
167 | $(git rev-parse refs/heads/dev) refs/heads/dev | |
168 | $(git rev-parse refs/heads/master) refs/heads/master | |
169 | $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/master | |
170 | 0000 | |
171 | EOF | |
172 | ||
b7ce24d0 | 173 | test-tool serve-v2 --stateless-rpc <in >out && |
8ea40cc5 | 174 | test-tool pkt-line unpack <out >actual && |
dcbaa0b3 | 175 | test_cmp expect actual |
72d0ea00 BW |
176 | ' |
177 | ||
ecc3e534 | 178 | test_expect_success 'sending server-options' ' |
8ea40cc5 | 179 | test-tool pkt-line pack >in <<-EOF && |
ecc3e534 BW |
180 | command=ls-refs |
181 | server-option=hello | |
182 | server-option=world | |
183 | 0001 | |
184 | ref-prefix HEAD | |
185 | 0000 | |
186 | EOF | |
187 | ||
188 | cat >expect <<-EOF && | |
189 | $(git rev-parse HEAD) HEAD | |
190 | 0000 | |
191 | EOF | |
192 | ||
b7ce24d0 | 193 | test-tool serve-v2 --stateless-rpc <in >out && |
8ea40cc5 | 194 | test-tool pkt-line unpack <out >actual && |
dcbaa0b3 | 195 | test_cmp expect actual |
ecc3e534 BW |
196 | ' |
197 | ||
7cc6ed2d JT |
198 | test_expect_success 'unexpected lines are not allowed in fetch request' ' |
199 | git init server && | |
200 | ||
8ea40cc5 | 201 | test-tool pkt-line pack >in <<-EOF && |
7cc6ed2d JT |
202 | command=fetch |
203 | 0001 | |
204 | this-is-not-a-command | |
205 | 0000 | |
206 | EOF | |
207 | ||
b7ce24d0 JS |
208 | ( |
209 | cd server && | |
210 | test_must_fail test-tool serve-v2 --stateless-rpc | |
211 | ) <in >/dev/null 2>err && | |
7cc6ed2d JT |
212 | grep "unexpected line: .this-is-not-a-command." err |
213 | ' | |
214 | ||
ed10cb95 | 215 | test_done |