Merge branch 'tb/commit-graph-no-check-oids'
[git/raj.git] / t / t5701-git-serve.sh
blobffb9613885904eaf474a726f6124032d13db9753
1 #!/bin/sh
3 test_description='test protocol v2 server commands'
5 . ./test-lib.sh
7 test_expect_success 'test capability advertisement' '
8 cat >expect <<-EOF &&
9 version 2
10 agent=git/$(git version | cut -d" " -f3)
11 ls-refs
12 fetch=shallow
13 server-option
14 0000
15 EOF
17 GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
18 --advertise-capabilities >out &&
19 test-tool pkt-line unpack <out >actual &&
20 test_cmp expect actual
23 test_expect_success 'stateless-rpc flag does not list capabilities' '
24 # Empty request
25 test-tool pkt-line pack >in <<-EOF &&
26 0000
27 EOF
28 test-tool serve-v2 --stateless-rpc >out <in &&
29 test_must_be_empty out &&
31 # EOF
32 test-tool serve-v2 --stateless-rpc >out &&
33 test_must_be_empty out
36 test_expect_success 'request invalid capability' '
37 test-tool pkt-line pack >in <<-EOF &&
38 foobar
39 0000
40 EOF
41 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
42 test_i18ngrep "unknown capability" err
45 test_expect_success 'request with no command' '
46 test-tool pkt-line pack >in <<-EOF &&
47 agent=git/test
48 0000
49 EOF
50 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
51 test_i18ngrep "no command requested" err
54 test_expect_success 'request invalid command' '
55 test-tool pkt-line pack >in <<-EOF &&
56 command=foo
57 agent=git/test
58 0000
59 EOF
60 test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
61 test_i18ngrep "invalid command" err
64 # Test the basics of ls-refs
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
74 test_expect_success 'basics of ls-refs' '
75 test-tool pkt-line pack >in <<-EOF &&
76 command=ls-refs
77 0000
78 EOF
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
91 test-tool serve-v2 --stateless-rpc <in >out &&
92 test-tool pkt-line unpack <out >actual &&
93 test_cmp expect actual
96 test_expect_success 'basic ref-prefixes' '
97 test-tool pkt-line pack >in <<-EOF &&
98 command=ls-refs
99 0001
100 ref-prefix refs/heads/master
101 ref-prefix refs/tags/one
102 0000
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
111 test-tool serve-v2 --stateless-rpc <in >out &&
112 test-tool pkt-line unpack <out >actual &&
113 test_cmp expect actual
116 test_expect_success 'refs/heads prefix' '
117 test-tool pkt-line pack >in <<-EOF &&
118 command=ls-refs
119 0001
120 ref-prefix refs/heads/
121 0000
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
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 'peel parameter' '
137 test-tool pkt-line pack >in <<-EOF &&
138 command=ls-refs
139 0001
140 peel
141 ref-prefix refs/tags/
142 0000
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
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 'symrefs parameter' '
158 test-tool pkt-line pack >in <<-EOF &&
159 command=ls-refs
160 0001
161 symrefs
162 ref-prefix refs/heads/
163 0000
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
173 test-tool serve-v2 --stateless-rpc <in >out &&
174 test-tool pkt-line unpack <out >actual &&
175 test_cmp expect actual
178 test_expect_success 'sending server-options' '
179 test-tool pkt-line pack >in <<-EOF &&
180 command=ls-refs
181 server-option=hello
182 server-option=world
183 0001
184 ref-prefix HEAD
185 0000
188 cat >expect <<-EOF &&
189 $(git rev-parse HEAD) HEAD
190 0000
193 test-tool serve-v2 --stateless-rpc <in >out &&
194 test-tool pkt-line unpack <out >actual &&
195 test_cmp expect actual
198 test_expect_success 'unexpected lines are not allowed in fetch request' '
199 git init server &&
201 test-tool pkt-line pack >in <<-EOF &&
202 command=fetch
203 0001
204 this-is-not-a-command
205 0000
209 cd server &&
210 test_must_fail test-tool serve-v2 --stateless-rpc
211 ) <in >/dev/null 2>err &&
212 grep "unexpected line: .this-is-not-a-command." err
215 test_done