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