Prepare to start 2.19 cycle
[alt-git.git] / t / t5701-git-serve.sh
blob75ec79e6cb839e71f6830d9301d1982d0fc68925
1 #!/bin/sh
3 test_description='test git-serve and 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 serve --advertise-capabilities >out &&
18 test-pkt-line unpack <out >actual &&
19 test_cmp actual expect
22 test_expect_success 'stateless-rpc flag does not list capabilities' '
23 # Empty request
24 test-pkt-line pack >in <<-EOF &&
25 0000
26 EOF
27 git serve --stateless-rpc >out <in &&
28 test_must_be_empty out &&
30 # EOF
31 git serve --stateless-rpc >out &&
32 test_must_be_empty out
35 test_expect_success 'request invalid capability' '
36 test-pkt-line pack >in <<-EOF &&
37 foobar
38 0000
39 EOF
40 test_must_fail git serve --stateless-rpc 2>err <in &&
41 test_i18ngrep "unknown capability" err
44 test_expect_success 'request with no command' '
45 test-pkt-line pack >in <<-EOF &&
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
53 test_expect_success 'request invalid command' '
54 test-pkt-line pack >in <<-EOF &&
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
63 # Test the basics of ls-refs
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
73 test_expect_success 'basics of ls-refs' '
74 test-pkt-line pack >in <<-EOF &&
75 command=ls-refs
76 0000
77 EOF
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
90 git serve --stateless-rpc <in >out &&
91 test-pkt-line unpack <out >actual &&
92 test_cmp actual expect
95 test_expect_success 'basic ref-prefixes' '
96 test-pkt-line pack >in <<-EOF &&
97 command=ls-refs
98 0001
99 ref-prefix refs/heads/master
100 ref-prefix refs/tags/one
101 0000
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
110 git serve --stateless-rpc <in >out &&
111 test-pkt-line unpack <out >actual &&
112 test_cmp actual expect
115 test_expect_success 'refs/heads prefix' '
116 test-pkt-line pack >in <<-EOF &&
117 command=ls-refs
118 0001
119 ref-prefix refs/heads/
120 0000
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
130 git serve --stateless-rpc <in >out &&
131 test-pkt-line unpack <out >actual &&
132 test_cmp actual expect
135 test_expect_success 'peel parameter' '
136 test-pkt-line pack >in <<-EOF &&
137 command=ls-refs
138 0001
139 peel
140 ref-prefix refs/tags/
141 0000
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
151 git serve --stateless-rpc <in >out &&
152 test-pkt-line unpack <out >actual &&
153 test_cmp actual expect
156 test_expect_success 'symrefs parameter' '
157 test-pkt-line pack >in <<-EOF &&
158 command=ls-refs
159 0001
160 symrefs
161 ref-prefix refs/heads/
162 0000
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
172 git serve --stateless-rpc <in >out &&
173 test-pkt-line unpack <out >actual &&
174 test_cmp actual expect
177 test_expect_success 'sending server-options' '
178 test-pkt-line pack >in <<-EOF &&
179 command=ls-refs
180 server-option=hello
181 server-option=world
182 0001
183 ref-prefix HEAD
184 0000
187 cat >expect <<-EOF &&
188 $(git rev-parse HEAD) HEAD
189 0000
192 git serve --stateless-rpc <in >out &&
193 test-pkt-line unpack <out >actual &&
194 test_cmp actual expect
197 test_expect_success 'unexpected lines are not allowed in fetch request' '
198 git init server &&
200 test-pkt-line pack >in <<-EOF &&
201 command=fetch
202 0001
203 this-is-not-a-command
204 0000
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
211 test_done