Merge branch 'bw/protocol-v2'
[git/debian.git] / t / t5701-git-serve.sh
blob72d7bc56280b13c68b930ea41690788ad87c9853
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 0000
14 EOF
16 git serve --advertise-capabilities >out &&
17 test-pkt-line unpack <out >actual &&
18 test_cmp actual expect
21 test_expect_success 'stateless-rpc flag does not list capabilities' '
22 # Empty request
23 test-pkt-line pack >in <<-EOF &&
24 0000
25 EOF
26 git serve --stateless-rpc >out <in &&
27 test_must_be_empty out &&
29 # EOF
30 git serve --stateless-rpc >out &&
31 test_must_be_empty out
34 test_expect_success 'request invalid capability' '
35 test-pkt-line pack >in <<-EOF &&
36 foobar
37 0000
38 EOF
39 test_must_fail git serve --stateless-rpc 2>err <in &&
40 test_i18ngrep "unknown capability" err
43 test_expect_success 'request with no command' '
44 test-pkt-line pack >in <<-EOF &&
45 agent=git/test
46 0000
47 EOF
48 test_must_fail git serve --stateless-rpc 2>err <in &&
49 test_i18ngrep "no command requested" err
52 test_expect_success 'request invalid command' '
53 test-pkt-line pack >in <<-EOF &&
54 command=foo
55 agent=git/test
56 0000
57 EOF
58 test_must_fail git serve --stateless-rpc 2>err <in &&
59 test_i18ngrep "invalid command" err
62 # Test the basics of ls-refs
64 test_expect_success 'setup some refs and tags' '
65 test_commit one &&
66 git branch dev master &&
67 test_commit two &&
68 git symbolic-ref refs/heads/release refs/heads/master &&
69 git tag -a -m "annotated tag" annotated-tag
72 test_expect_success 'basics of ls-refs' '
73 test-pkt-line pack >in <<-EOF &&
74 command=ls-refs
75 0000
76 EOF
78 cat >expect <<-EOF &&
79 $(git rev-parse HEAD) HEAD
80 $(git rev-parse refs/heads/dev) refs/heads/dev
81 $(git rev-parse refs/heads/master) refs/heads/master
82 $(git rev-parse refs/heads/release) refs/heads/release
83 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
84 $(git rev-parse refs/tags/one) refs/tags/one
85 $(git rev-parse refs/tags/two) refs/tags/two
86 0000
87 EOF
89 git serve --stateless-rpc <in >out &&
90 test-pkt-line unpack <out >actual &&
91 test_cmp actual expect
94 test_expect_success 'basic ref-prefixes' '
95 test-pkt-line pack >in <<-EOF &&
96 command=ls-refs
97 0001
98 ref-prefix refs/heads/master
99 ref-prefix refs/tags/one
100 0000
103 cat >expect <<-EOF &&
104 $(git rev-parse refs/heads/master) refs/heads/master
105 $(git rev-parse refs/tags/one) refs/tags/one
106 0000
109 git serve --stateless-rpc <in >out &&
110 test-pkt-line unpack <out >actual &&
111 test_cmp actual expect
114 test_expect_success 'refs/heads prefix' '
115 test-pkt-line pack >in <<-EOF &&
116 command=ls-refs
117 0001
118 ref-prefix refs/heads/
119 0000
122 cat >expect <<-EOF &&
123 $(git rev-parse refs/heads/dev) refs/heads/dev
124 $(git rev-parse refs/heads/master) refs/heads/master
125 $(git rev-parse refs/heads/release) refs/heads/release
126 0000
129 git serve --stateless-rpc <in >out &&
130 test-pkt-line unpack <out >actual &&
131 test_cmp actual expect
134 test_expect_success 'peel parameter' '
135 test-pkt-line pack >in <<-EOF &&
136 command=ls-refs
137 0001
138 peel
139 ref-prefix refs/tags/
140 0000
143 cat >expect <<-EOF &&
144 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{})
145 $(git rev-parse refs/tags/one) refs/tags/one
146 $(git rev-parse refs/tags/two) refs/tags/two
147 0000
150 git serve --stateless-rpc <in >out &&
151 test-pkt-line unpack <out >actual &&
152 test_cmp actual expect
155 test_expect_success 'symrefs parameter' '
156 test-pkt-line pack >in <<-EOF &&
157 command=ls-refs
158 0001
159 symrefs
160 ref-prefix refs/heads/
161 0000
164 cat >expect <<-EOF &&
165 $(git rev-parse refs/heads/dev) refs/heads/dev
166 $(git rev-parse refs/heads/master) refs/heads/master
167 $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/master
168 0000
171 git serve --stateless-rpc <in >out &&
172 test-pkt-line unpack <out >actual &&
173 test_cmp actual expect
176 test_done