Blame


1 d1c1ae5f 2019-08-12 stsp #!/bin/sh
2 d1c1ae5f 2019-08-12 stsp #
3 d1c1ae5f 2019-08-12 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 d1c1ae5f 2019-08-12 stsp #
5 d1c1ae5f 2019-08-12 stsp # Permission to use, copy, modify, and distribute this software for any
6 d1c1ae5f 2019-08-12 stsp # purpose with or without fee is hereby granted, provided that the above
7 d1c1ae5f 2019-08-12 stsp # copyright notice and this permission notice appear in all copies.
8 d1c1ae5f 2019-08-12 stsp #
9 d1c1ae5f 2019-08-12 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 d1c1ae5f 2019-08-12 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 d1c1ae5f 2019-08-12 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 d1c1ae5f 2019-08-12 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 d1c1ae5f 2019-08-12 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 d1c1ae5f 2019-08-12 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 d1c1ae5f 2019-08-12 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 d1c1ae5f 2019-08-12 stsp
17 d1c1ae5f 2019-08-12 stsp . ./common.sh
18 d1c1ae5f 2019-08-12 stsp
19 f6cae3ed 2020-09-13 naddy test_ref_create() {
20 d1c1ae5f 2019-08-12 stsp local testroot=`test_init ref_create`
21 d1c1ae5f 2019-08-12 stsp local commit_id=`git_show_head $testroot/repo`
22 d1c1ae5f 2019-08-12 stsp
23 e31abbf2 2020-03-22 stsp # Create a ref pointing at a commit ID
24 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/heads/commitref
25 d4fc9a62 2019-10-09 stsp ret="$?"
26 d4fc9a62 2019-10-09 stsp if [ "$ret" != "0" ]; then
27 d4fc9a62 2019-10-09 stsp echo "got ref command failed unexpectedly"
28 d4fc9a62 2019-10-09 stsp test_done "$testroot" "$ret"
29 d4fc9a62 2019-10-09 stsp return 1
30 d4fc9a62 2019-10-09 stsp fi
31 d4fc9a62 2019-10-09 stsp
32 d4fc9a62 2019-10-09 stsp # Create a ref based on repository's HEAD reference
33 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c HEAD refs/heads/newref
34 d1c1ae5f 2019-08-12 stsp ret="$?"
35 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
36 d1c1ae5f 2019-08-12 stsp echo "got ref command failed unexpectedly"
37 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
38 d1c1ae5f 2019-08-12 stsp return 1
39 d1c1ae5f 2019-08-12 stsp fi
40 d1c1ae5f 2019-08-12 stsp
41 d1c1ae5f 2019-08-12 stsp # Ensure that Git recognizes the ref Got has created
42 d1c1ae5f 2019-08-12 stsp (cd $testroot/repo && git checkout -q newref)
43 d1c1ae5f 2019-08-12 stsp ret="$?"
44 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
45 d1c1ae5f 2019-08-12 stsp echo "git checkout command failed unexpectedly"
46 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
47 d1c1ae5f 2019-08-12 stsp return 1
48 d1c1ae5f 2019-08-12 stsp fi
49 d1c1ae5f 2019-08-12 stsp
50 a009df92 2019-08-22 stsp # Ensure Got recognizes the new ref
51 d1c1ae5f 2019-08-12 stsp got checkout -b newref $testroot/repo $testroot/wt >/dev/null
52 d1c1ae5f 2019-08-12 stsp ret="$?"
53 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
54 d1c1ae5f 2019-08-12 stsp echo "got checkout command failed unexpectedly"
55 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
56 d1c1ae5f 2019-08-12 stsp return 1
57 d1c1ae5f 2019-08-12 stsp fi
58 d1c1ae5f 2019-08-12 stsp
59 d1c1ae5f 2019-08-12 stsp # Create a head ref based on another specific ref
60 e31abbf2 2020-03-22 stsp (cd $testroot/wt && got ref -c refs/heads/master refs/heads/anotherref)
61 d1c1ae5f 2019-08-12 stsp ret="$?"
62 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
63 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
64 d1c1ae5f 2019-08-12 stsp return 1
65 d1c1ae5f 2019-08-12 stsp fi
66 d1c1ae5f 2019-08-12 stsp
67 d1c1ae5f 2019-08-12 stsp (cd $testroot/repo && git checkout -q anotherref)
68 d1c1ae5f 2019-08-12 stsp ret="$?"
69 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
70 d1c1ae5f 2019-08-12 stsp echo "git checkout command failed unexpectedly"
71 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
72 d1c1ae5f 2019-08-12 stsp fi
73 d1c1ae5f 2019-08-12 stsp
74 d1c1ae5f 2019-08-12 stsp # Create a symbolic ref
75 e31abbf2 2020-03-22 stsp (cd $testroot/wt && got ref -s refs/heads/master refs/heads/symbolicref)
76 d1c1ae5f 2019-08-12 stsp ret="$?"
77 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
78 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
79 d1c1ae5f 2019-08-12 stsp return 1
80 d1c1ae5f 2019-08-12 stsp fi
81 d1c1ae5f 2019-08-12 stsp
82 d1c1ae5f 2019-08-12 stsp (cd $testroot/repo && git checkout -q symbolicref)
83 d1c1ae5f 2019-08-12 stsp ret="$?"
84 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
85 d1c1ae5f 2019-08-12 stsp echo "git checkout command failed unexpectedly"
86 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
87 2d463f36 2019-08-12 stsp return 1
88 d1c1ae5f 2019-08-12 stsp fi
89 d1c1ae5f 2019-08-12 stsp
90 2d463f36 2019-08-12 stsp # Attempt to create a symbolic ref pointing at a non-reference
91 e31abbf2 2020-03-22 stsp (cd $testroot/wt && got ref -s $commit_id refs/heads/symbolicref \
92 2d463f36 2019-08-12 stsp 2> $testroot/stderr)
93 2d463f36 2019-08-12 stsp ret="$?"
94 54c39596 2020-12-28 stsp if [ "$ret" = "0" ]; then
95 2d463f36 2019-08-12 stsp echo "git ref command succeeded unexpectedly"
96 2d463f36 2019-08-12 stsp test_done "$testroot" "1"
97 2d463f36 2019-08-12 stsp return 1
98 2d463f36 2019-08-12 stsp fi
99 2d463f36 2019-08-12 stsp
100 2d463f36 2019-08-12 stsp echo "got: reference $commit_id not found" > $testroot/stderr.expected
101 2d463f36 2019-08-12 stsp cmp -s $testroot/stderr $testroot/stderr.expected
102 2d463f36 2019-08-12 stsp ret="$?"
103 2d463f36 2019-08-12 stsp if [ "$ret" != "0" ]; then
104 2d463f36 2019-08-12 stsp diff -u $testroot/stderr.expected $testroot/stderr
105 2d463f36 2019-08-12 stsp test_done "$testroot" "$ret"
106 2d463f36 2019-08-12 stsp return 1
107 2d463f36 2019-08-12 stsp fi
108 2d463f36 2019-08-12 stsp
109 e31abbf2 2020-03-22 stsp # Attempt to create a reference without specifying a name
110 e31abbf2 2020-03-22 stsp (cd $testroot/wt && got ref -c $commit_id 2> $testroot/stderr)
111 e31abbf2 2020-03-22 stsp ret="$?"
112 54c39596 2020-12-28 stsp if [ "$ret" = "0" ]; then
113 e31abbf2 2020-03-22 stsp echo "git ref command succeeded unexpectedly"
114 e31abbf2 2020-03-22 stsp test_done "$testroot" "1"
115 e31abbf2 2020-03-22 stsp return 1
116 e31abbf2 2020-03-22 stsp fi
117 e31abbf2 2020-03-22 stsp
118 e31abbf2 2020-03-22 stsp grep -q '^usage: got ref' $testroot/stderr
119 e31abbf2 2020-03-22 stsp ret="$?"
120 e31abbf2 2020-03-22 stsp if [ "$ret" != "0" ]; then
121 e31abbf2 2020-03-22 stsp echo "unexpected usage error message: " >&2
122 e31abbf2 2020-03-22 stsp cat $testroot/stderr >&2
123 e31abbf2 2020-03-22 stsp test_done "$testroot" "$ret"
124 e31abbf2 2020-03-22 stsp return 1
125 e31abbf2 2020-03-22 stsp fi
126 e31abbf2 2020-03-22 stsp
127 e31abbf2 2020-03-22 stsp # Attempt to create a symbolic reference without specifying a name
128 e31abbf2 2020-03-22 stsp (cd $testroot/wt && got ref -s refs/heads/symbolicref \
129 e31abbf2 2020-03-22 stsp 2> $testroot/stderr)
130 e31abbf2 2020-03-22 stsp ret="$?"
131 54c39596 2020-12-28 stsp if [ "$ret" = "0" ]; then
132 e31abbf2 2020-03-22 stsp echo "git ref command succeeded unexpectedly"
133 e31abbf2 2020-03-22 stsp test_done "$testroot" "1"
134 e31abbf2 2020-03-22 stsp return 1
135 e31abbf2 2020-03-22 stsp fi
136 e31abbf2 2020-03-22 stsp
137 e31abbf2 2020-03-22 stsp grep -q '^usage: got ref' $testroot/stderr
138 e31abbf2 2020-03-22 stsp ret="$?"
139 e31abbf2 2020-03-22 stsp if [ "$ret" != "0" ]; then
140 e31abbf2 2020-03-22 stsp echo "unexpected usage error message: " >&2
141 e31abbf2 2020-03-22 stsp cat $testroot/stderr >&2
142 e31abbf2 2020-03-22 stsp test_done "$testroot" "$ret"
143 e31abbf2 2020-03-22 stsp return 1
144 e31abbf2 2020-03-22 stsp fi
145 e31abbf2 2020-03-22 stsp
146 7fa81f88 2020-02-21 stsp # Change HEAD
147 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -s refs/heads/newref HEAD
148 7fa81f88 2020-02-21 stsp ret="$?"
149 7fa81f88 2020-02-21 stsp if [ "$ret" != "0" ]; then
150 7fa81f88 2020-02-21 stsp echo "got ref command failed unexpectedly"
151 7fa81f88 2020-02-21 stsp test_done "$testroot" "$ret"
152 7fa81f88 2020-02-21 stsp return 1
153 7fa81f88 2020-02-21 stsp fi
154 7fa81f88 2020-02-21 stsp
155 7fa81f88 2020-02-21 stsp # Ensure that Git recognizes the ref Got has created
156 7fa81f88 2020-02-21 stsp (cd $testroot/repo && git checkout -q HEAD)
157 7fa81f88 2020-02-21 stsp ret="$?"
158 7fa81f88 2020-02-21 stsp if [ "$ret" != "0" ]; then
159 7fa81f88 2020-02-21 stsp echo "git checkout command failed unexpectedly"
160 7fa81f88 2020-02-21 stsp test_done "$testroot" "$ret"
161 7fa81f88 2020-02-21 stsp return 1
162 7fa81f88 2020-02-21 stsp fi
163 7fa81f88 2020-02-21 stsp
164 7fa81f88 2020-02-21 stsp # Ensure Got recognizes the new ref
165 7fa81f88 2020-02-21 stsp (cd $testroot/wt && got update -b HEAD >/dev/null)
166 7fa81f88 2020-02-21 stsp ret="$?"
167 7fa81f88 2020-02-21 stsp if [ "$ret" != "0" ]; then
168 7fa81f88 2020-02-21 stsp echo "got checkout command failed unexpectedly"
169 7fa81f88 2020-02-21 stsp test_done "$testroot" "$ret"
170 7fa81f88 2020-02-21 stsp return 1
171 7fa81f88 2020-02-21 stsp fi
172 d1c1ae5f 2019-08-12 stsp got ref -r $testroot/repo -l > $testroot/stdout
173 7fa81f88 2020-02-21 stsp echo "HEAD: refs/heads/newref" > $testroot/stdout.expected
174 d1c1ae5f 2019-08-12 stsp echo -n "refs/got/worktree/base-" >> $testroot/stdout.expected
175 d1c1ae5f 2019-08-12 stsp cat $testroot/wt/.got/uuid | tr -d '\n' >> $testroot/stdout.expected
176 d1c1ae5f 2019-08-12 stsp echo ": $commit_id" >> $testroot/stdout.expected
177 d1c1ae5f 2019-08-12 stsp echo "refs/heads/anotherref: $commit_id" >> $testroot/stdout.expected
178 d4fc9a62 2019-10-09 stsp echo "refs/heads/commitref: $commit_id" >> $testroot/stdout.expected
179 d1c1ae5f 2019-08-12 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
180 d1c1ae5f 2019-08-12 stsp echo "refs/heads/newref: $commit_id" >> $testroot/stdout.expected
181 d1c1ae5f 2019-08-12 stsp echo "refs/heads/symbolicref: refs/heads/master" \
182 d1c1ae5f 2019-08-12 stsp >> $testroot/stdout.expected
183 d1c1ae5f 2019-08-12 stsp cmp -s $testroot/stdout $testroot/stdout.expected
184 d1c1ae5f 2019-08-12 stsp ret="$?"
185 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
186 d1c1ae5f 2019-08-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
187 d1c1ae5f 2019-08-12 stsp fi
188 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
189 d1c1ae5f 2019-08-12 stsp }
190 d1c1ae5f 2019-08-12 stsp
191 f6cae3ed 2020-09-13 naddy test_ref_delete() {
192 d1c1ae5f 2019-08-12 stsp local testroot=`test_init ref_delete`
193 d1c1ae5f 2019-08-12 stsp local commit_id=`git_show_head $testroot/repo`
194 d1c1ae5f 2019-08-12 stsp
195 d1c1ae5f 2019-08-12 stsp for b in ref1 ref2 ref3; do
196 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c refs/heads/master refs/heads/$b
197 d1c1ae5f 2019-08-12 stsp ret="$?"
198 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
199 d1c1ae5f 2019-08-12 stsp echo "got ref command failed unexpectedly"
200 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
201 d1c1ae5f 2019-08-12 stsp return 1
202 d1c1ae5f 2019-08-12 stsp fi
203 d1c1ae5f 2019-08-12 stsp done
204 d1c1ae5f 2019-08-12 stsp
205 e31abbf2 2020-03-22 stsp got ref -d -r $testroot/repo refs/heads/ref2 > $testroot/stdout
206 d1c1ae5f 2019-08-12 stsp ret="$?"
207 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
208 d1c1ae5f 2019-08-12 stsp echo "got ref command failed unexpectedly"
209 993f033b 2021-07-16 stsp test_done "$testroot" "$ret"
210 993f033b 2021-07-16 stsp return 1
211 993f033b 2021-07-16 stsp fi
212 993f033b 2021-07-16 stsp echo "Deleted refs/heads/ref2: $commit_id" > $testroot/stdout.expected
213 993f033b 2021-07-16 stsp cmp -s $testroot/stdout $testroot/stdout.expected
214 993f033b 2021-07-16 stsp ret="$?"
215 993f033b 2021-07-16 stsp if [ "$ret" != "0" ]; then
216 993f033b 2021-07-16 stsp diff -u $testroot/stdout.expected $testroot/stdout
217 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
218 d1c1ae5f 2019-08-12 stsp return 1
219 d1c1ae5f 2019-08-12 stsp fi
220 d1c1ae5f 2019-08-12 stsp
221 d1c1ae5f 2019-08-12 stsp got ref -l -r $testroot/repo > $testroot/stdout
222 d1c1ae5f 2019-08-12 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
223 d1c1ae5f 2019-08-12 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
224 d1c1ae5f 2019-08-12 stsp echo "refs/heads/ref1: $commit_id" >> $testroot/stdout.expected
225 d1c1ae5f 2019-08-12 stsp echo "refs/heads/ref3: $commit_id" >> $testroot/stdout.expected
226 d1c1ae5f 2019-08-12 stsp cmp -s $testroot/stdout $testroot/stdout.expected
227 d1c1ae5f 2019-08-12 stsp ret="$?"
228 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
229 d1c1ae5f 2019-08-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
230 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
231 d1c1ae5f 2019-08-12 stsp return 1
232 d1c1ae5f 2019-08-12 stsp fi
233 d1c1ae5f 2019-08-12 stsp
234 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -d refs/heads/bogus_ref_name \
235 d1c1ae5f 2019-08-12 stsp > $testroot/stdout 2> $testroot/stderr
236 d1c1ae5f 2019-08-12 stsp ret="$?"
237 54c39596 2020-12-28 stsp if [ "$ret" = "0" ]; then
238 d1c1ae5f 2019-08-12 stsp echo "got ref succeeded unexpectedly"
239 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
240 d1c1ae5f 2019-08-12 stsp return 1
241 d1c1ae5f 2019-08-12 stsp fi
242 d1c1ae5f 2019-08-12 stsp
243 d1c1ae5f 2019-08-12 stsp echo "got: reference refs/heads/bogus_ref_name not found" \
244 d1c1ae5f 2019-08-12 stsp > $testroot/stderr.expected
245 d1c1ae5f 2019-08-12 stsp cmp -s $testroot/stderr $testroot/stderr.expected
246 d1c1ae5f 2019-08-12 stsp ret="$?"
247 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
248 d1c1ae5f 2019-08-12 stsp diff -u $testroot/stderr.expected $testroot/stderr
249 2a104ff6 2020-09-21 stsp test_done "$testroot" "$ret"
250 2a104ff6 2020-09-21 stsp return 1
251 2a104ff6 2020-09-21 stsp fi
252 2a104ff6 2020-09-21 stsp
253 2a104ff6 2020-09-21 stsp (cd $testroot/repo && git pack-refs --all)
254 2a104ff6 2020-09-21 stsp
255 2a104ff6 2020-09-21 stsp echo "modified alpha" > $testroot/repo/alpha
256 2a104ff6 2020-09-21 stsp git_commit $testroot/repo -m "modified alpha"
257 2a104ff6 2020-09-21 stsp local commit_id2=`git_show_head $testroot/repo`
258 2a104ff6 2020-09-21 stsp
259 2a104ff6 2020-09-21 stsp # ref 'master' now exists in both packed and loose forms
260 2a104ff6 2020-09-21 stsp
261 2a104ff6 2020-09-21 stsp got ref -l -r $testroot/repo > $testroot/stdout
262 2a104ff6 2020-09-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
263 2a104ff6 2020-09-21 stsp echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
264 2a104ff6 2020-09-21 stsp echo "refs/heads/ref1: $commit_id" >> $testroot/stdout.expected
265 2a104ff6 2020-09-21 stsp echo "refs/heads/ref3: $commit_id" >> $testroot/stdout.expected
266 2a104ff6 2020-09-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
267 2a104ff6 2020-09-21 stsp ret="$?"
268 2a104ff6 2020-09-21 stsp if [ "$ret" != "0" ]; then
269 2a104ff6 2020-09-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
270 2a104ff6 2020-09-21 stsp test_done "$testroot" "$ret"
271 2a104ff6 2020-09-21 stsp return 1
272 b2070a3f 2020-03-22 stsp fi
273 2a104ff6 2020-09-21 stsp
274 993f033b 2021-07-16 stsp got ref -r $testroot/repo -d master >/dev/null
275 2a104ff6 2020-09-21 stsp
276 2a104ff6 2020-09-21 stsp got ref -l -r $testroot/repo > $testroot/stdout
277 48cae60d 2020-09-22 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
278 48cae60d 2020-09-22 stsp echo "refs/heads/ref1: $commit_id" >> $testroot/stdout.expected
279 2a104ff6 2020-09-21 stsp echo "refs/heads/ref3: $commit_id" >> $testroot/stdout.expected
280 2a104ff6 2020-09-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
281 2a104ff6 2020-09-21 stsp ret="$?"
282 2a104ff6 2020-09-21 stsp if [ "$ret" != "0" ]; then
283 2a104ff6 2020-09-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
284 2a104ff6 2020-09-21 stsp fi
285 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
286 b2070a3f 2020-03-22 stsp }
287 b2070a3f 2020-03-22 stsp
288 f6cae3ed 2020-09-13 naddy test_ref_list() {
289 b2070a3f 2020-03-22 stsp local testroot=`test_init ref_list`
290 b2070a3f 2020-03-22 stsp local commit_id=`git_show_head $testroot/repo`
291 b2070a3f 2020-03-22 stsp
292 b2070a3f 2020-03-22 stsp # Create a tag pointing at a commit ID
293 b2070a3f 2020-03-22 stsp got tag -r $testroot/repo -c $commit_id -m "1.0" "1.0" >/dev/null
294 b2070a3f 2020-03-22 stsp ret="$?"
295 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
296 b2070a3f 2020-03-22 stsp echo "got tag command failed unexpectedly"
297 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
298 b2070a3f 2020-03-22 stsp return 1
299 b2070a3f 2020-03-22 stsp fi
300 b2070a3f 2020-03-22 stsp local tag_id=`got ref -r $testroot/repo -l \
301 b2070a3f 2020-03-22 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
302 b2070a3f 2020-03-22 stsp
303 b2070a3f 2020-03-22 stsp # Create a ref based on repository's HEAD reference
304 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -c HEAD refs/foo/zoo
305 b2070a3f 2020-03-22 stsp ret="$?"
306 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
307 b2070a3f 2020-03-22 stsp echo "got ref command failed unexpectedly"
308 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
309 b2070a3f 2020-03-22 stsp return 1
310 b2070a3f 2020-03-22 stsp fi
311 b2070a3f 2020-03-22 stsp
312 b2070a3f 2020-03-22 stsp # Create a head ref based on another specific ref
313 b2070a3f 2020-03-22 stsp (cd $testroot/repo && got ref -c refs/heads/master refs/foo/bar/baz)
314 b2070a3f 2020-03-22 stsp ret="$?"
315 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
316 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
317 b2070a3f 2020-03-22 stsp return 1
318 b2070a3f 2020-03-22 stsp fi
319 b2070a3f 2020-03-22 stsp
320 75236079 2020-03-25 stsp # Create a HEAD ref in the namespace of a remote repository
321 75236079 2020-03-25 stsp (cd $testroot/repo && got ref -s refs/heads/master \
322 75236079 2020-03-25 stsp refs/remotes/origin/HEAD)
323 75236079 2020-03-25 stsp ret="$?"
324 75236079 2020-03-25 stsp if [ "$ret" != "0" ]; then
325 75236079 2020-03-25 stsp test_done "$testroot" "$ret"
326 75236079 2020-03-25 stsp return 1
327 75236079 2020-03-25 stsp fi
328 75236079 2020-03-25 stsp
329 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l > $testroot/stdout
330 b2070a3f 2020-03-22 stsp
331 b2070a3f 2020-03-22 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
332 b2070a3f 2020-03-22 stsp echo "refs/foo/bar/baz: $commit_id" >> $testroot/stdout.expected
333 b2070a3f 2020-03-22 stsp echo "refs/foo/zoo: $commit_id" >> $testroot/stdout.expected
334 b2070a3f 2020-03-22 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
335 75236079 2020-03-25 stsp echo "refs/remotes/origin/HEAD: refs/heads/master" \
336 75236079 2020-03-25 stsp >> $testroot/stdout.expected
337 b2070a3f 2020-03-22 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
338 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
339 b2070a3f 2020-03-22 stsp ret="$?"
340 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
341 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
342 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
343 b2070a3f 2020-03-22 stsp return 1
344 b2070a3f 2020-03-22 stsp fi
345 b2070a3f 2020-03-22 stsp
346 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l refs > $testroot/stdout
347 b2070a3f 2020-03-22 stsp
348 b2070a3f 2020-03-22 stsp echo "refs/foo/bar/baz: $commit_id" > $testroot/stdout.expected
349 b2070a3f 2020-03-22 stsp echo "refs/foo/zoo: $commit_id" >> $testroot/stdout.expected
350 b2070a3f 2020-03-22 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
351 75236079 2020-03-25 stsp echo "refs/remotes/origin/HEAD: refs/heads/master" \
352 75236079 2020-03-25 stsp >> $testroot/stdout.expected
353 b2070a3f 2020-03-22 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
354 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
355 b2070a3f 2020-03-22 stsp ret="$?"
356 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
357 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
358 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
359 b2070a3f 2020-03-22 stsp return 1
360 b2070a3f 2020-03-22 stsp fi
361 b2070a3f 2020-03-22 stsp
362 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l refs/tags > $testroot/stdout
363 b2070a3f 2020-03-22 stsp
364 b2070a3f 2020-03-22 stsp echo "refs/tags/1.0: $tag_id" > $testroot/stdout.expected
365 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
366 b2070a3f 2020-03-22 stsp ret="$?"
367 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
368 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
369 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
370 b2070a3f 2020-03-22 stsp return 1
371 d1c1ae5f 2019-08-12 stsp fi
372 b2070a3f 2020-03-22 stsp
373 b2070a3f 2020-03-22 stsp for r in refs/foo/bar/baz refs/foo/bar/baz foo/bar/baz foo/bar; do
374 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l $r > $testroot/stdout
375 b2070a3f 2020-03-22 stsp
376 b2070a3f 2020-03-22 stsp echo "refs/foo/bar/baz: $commit_id" > $testroot/stdout.expected
377 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
378 b2070a3f 2020-03-22 stsp ret="$?"
379 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
380 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
381 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
382 b2070a3f 2020-03-22 stsp return 1
383 b2070a3f 2020-03-22 stsp fi
384 b2070a3f 2020-03-22 stsp done
385 b2070a3f 2020-03-22 stsp
386 b2070a3f 2020-03-22 stsp for r in refs/foo foo; do
387 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l $r > $testroot/stdout
388 b2070a3f 2020-03-22 stsp
389 b2070a3f 2020-03-22 stsp echo "refs/foo/bar/baz: $commit_id" > $testroot/stdout.expected
390 b2070a3f 2020-03-22 stsp echo "refs/foo/zoo: $commit_id" >> $testroot/stdout.expected
391 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
392 b2070a3f 2020-03-22 stsp ret="$?"
393 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
394 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
395 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
396 b2070a3f 2020-03-22 stsp return 1
397 b2070a3f 2020-03-22 stsp fi
398 b2070a3f 2020-03-22 stsp done
399 b2070a3f 2020-03-22 stsp
400 57c18198 2021-05-24 stsp for r in /refs/abc refs//foo/bar refs//foo//bar refs////////foo//bar; do
401 57c18198 2021-05-24 stsp got ref -r $testroot/repo -l $r > $testroot/stdout \
402 57c18198 2021-05-24 stsp 2> $testroot/stderr
403 b2070a3f 2020-03-22 stsp
404 57c18198 2021-05-24 stsp echo -n > $testroot/stdout.expected
405 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
406 b2070a3f 2020-03-22 stsp ret="$?"
407 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
408 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
409 57c18198 2021-05-24 stsp test_done "$testroot" "$ret"
410 57c18198 2021-05-24 stsp return 1
411 57c18198 2021-05-24 stsp fi
412 57c18198 2021-05-24 stsp
413 57c18198 2021-05-24 stsp echo "got: $r: bad reference name" > $testroot/stderr.expected
414 57c18198 2021-05-24 stsp cmp -s $testroot/stderr $testroot/stderr.expected
415 57c18198 2021-05-24 stsp ret="$?"
416 57c18198 2021-05-24 stsp if [ "$ret" != "0" ]; then
417 57c18198 2021-05-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
418 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
419 b2070a3f 2020-03-22 stsp return 1
420 b2070a3f 2020-03-22 stsp fi
421 b2070a3f 2020-03-22 stsp done
422 b2070a3f 2020-03-22 stsp
423 b2070a3f 2020-03-22 stsp # attempt to list non-existing references
424 57c18198 2021-05-24 stsp for r in refs/fo bar baz moo riffs refs/abc refs/foo/bar/baz/moo; do
425 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l $r > $testroot/stdout
426 b2070a3f 2020-03-22 stsp
427 b2070a3f 2020-03-22 stsp echo -n > $testroot/stdout.expected
428 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
429 b2070a3f 2020-03-22 stsp ret="$?"
430 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
431 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
432 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
433 b2070a3f 2020-03-22 stsp return 1
434 b2070a3f 2020-03-22 stsp fi
435 b2070a3f 2020-03-22 stsp done
436 b2070a3f 2020-03-22 stsp
437 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
438 d1c1ae5f 2019-08-12 stsp }
439 d1c1ae5f 2019-08-12 stsp
440 7fb414ae 2020-08-08 stsp test_parseargs "$@"
441 d1c1ae5f 2019-08-12 stsp run_test test_ref_create
442 d1c1ae5f 2019-08-12 stsp run_test test_ref_delete
443 b2070a3f 2020-03-22 stsp run_test test_ref_list