1#!/bin/sh
2
3test_description='test git-serve and server commands'
4
5. ./test-lib.sh
6
7test_expect_success 'test capability advertisement' '
8 cat >expect <<-EOF &&
9 version 2
10 agent=git/$(git version | cut -d" " -f3)
11 ls-refs
12 0000
13 EOF
14
15 git serve --advertise-capabilities >out &&
16 test-pkt-line unpack <out >actual &&
17 test_cmp actual expect
18'
19
20test_expect_success 'stateless-rpc flag does not list capabilities' '
21 # Empty request
22 test-pkt-line pack >in <<-EOF &&
23 0000
24 EOF
25 git serve --stateless-rpc >out <in &&
26 test_must_be_empty out &&
27
28 # EOF
29 git serve --stateless-rpc >out &&
30 test_must_be_empty out
31'
32
33test_expect_success 'request invalid capability' '
34 test-pkt-line pack >in <<-EOF &&
35 foobar
36 0000
37 EOF
38 test_must_fail git serve --stateless-rpc 2>err <in &&
39 test_i18ngrep "unknown capability" err
40'
41
42test_expect_success 'request with no command' '
43 test-pkt-line pack >in <<-EOF &&
44 agent=git/test
45 0000
46 EOF
47 test_must_fail git serve --stateless-rpc 2>err <in &&
48 test_i18ngrep "no command requested" err
49'
50
51test_expect_success 'request invalid command' '
52 test-pkt-line pack >in <<-EOF &&
53 command=foo
54 agent=git/test
55 0000
56 EOF
57 test_must_fail git serve --stateless-rpc 2>err <in &&
58 test_i18ngrep "invalid command" err
59'
60
61# Test the basics of ls-refs
62#
63test_expect_success 'setup some refs and tags' '
64 test_commit one &&
65 git branch dev master &&
66 test_commit two &&
67 git symbolic-ref refs/heads/release refs/heads/master &&
68 git tag -a -m "annotated tag" annotated-tag
69'
70
71test_expect_success 'basics of ls-refs' '
72 test-pkt-line pack >in <<-EOF &&
73 command=ls-refs
74 0000
75 EOF
76
77 cat >expect <<-EOF &&
78 $(git rev-parse HEAD) HEAD
79 $(git rev-parse refs/heads/dev) refs/heads/dev
80 $(git rev-parse refs/heads/master) refs/heads/master
81 $(git rev-parse refs/heads/release) refs/heads/release
82 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag
83 $(git rev-parse refs/tags/one) refs/tags/one
84 $(git rev-parse refs/tags/two) refs/tags/two
85 0000
86 EOF
87
88 git serve --stateless-rpc <in >out &&
89 test-pkt-line unpack <out >actual &&
90 test_cmp actual expect
91'
92
93test_expect_success 'basic ref-prefixes' '
94 test-pkt-line pack >in <<-EOF &&
95 command=ls-refs
96 0001
97 ref-prefix refs/heads/master
98 ref-prefix refs/tags/one
99 0000
100 EOF
101
102 cat >expect <<-EOF &&
103 $(git rev-parse refs/heads/master) refs/heads/master
104 $(git rev-parse refs/tags/one) refs/tags/one
105 0000
106 EOF
107
108 git serve --stateless-rpc <in >out &&
109 test-pkt-line unpack <out >actual &&
110 test_cmp actual expect
111'
112
113test_expect_success 'refs/heads prefix' '
114 test-pkt-line pack >in <<-EOF &&
115 command=ls-refs
116 0001
117 ref-prefix refs/heads/
118 0000
119 EOF
120
121 cat >expect <<-EOF &&
122 $(git rev-parse refs/heads/dev) refs/heads/dev
123 $(git rev-parse refs/heads/master) refs/heads/master
124 $(git rev-parse refs/heads/release) refs/heads/release
125 0000
126 EOF
127
128 git serve --stateless-rpc <in >out &&
129 test-pkt-line unpack <out >actual &&
130 test_cmp actual expect
131'
132
133test_expect_success 'peel parameter' '
134 test-pkt-line pack >in <<-EOF &&
135 command=ls-refs
136 0001
137 peel
138 ref-prefix refs/tags/
139 0000
140 EOF
141
142 cat >expect <<-EOF &&
143 $(git rev-parse refs/tags/annotated-tag) refs/tags/annotated-tag peeled:$(git rev-parse refs/tags/annotated-tag^{})
144 $(git rev-parse refs/tags/one) refs/tags/one
145 $(git rev-parse refs/tags/two) refs/tags/two
146 0000
147 EOF
148
149 git serve --stateless-rpc <in >out &&
150 test-pkt-line unpack <out >actual &&
151 test_cmp actual expect
152'
153
154test_expect_success 'symrefs parameter' '
155 test-pkt-line pack >in <<-EOF &&
156 command=ls-refs
157 0001
158 symrefs
159 ref-prefix refs/heads/
160 0000
161 EOF
162
163 cat >expect <<-EOF &&
164 $(git rev-parse refs/heads/dev) refs/heads/dev
165 $(git rev-parse refs/heads/master) refs/heads/master
166 $(git rev-parse refs/heads/release) refs/heads/release symref-target:refs/heads/master
167 0000
168 EOF
169
170 git serve --stateless-rpc <in >out &&
171 test-pkt-line unpack <out >actual &&
172 test_cmp actual expect
173'
174
175test_done