Blame


1 dc5351b4 2019-07-30 stsp #!/bin/sh
2 dc5351b4 2019-07-30 stsp #
3 dc5351b4 2019-07-30 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 dc5351b4 2019-07-30 stsp #
5 dc5351b4 2019-07-30 stsp # Permission to use, copy, modify, and distribute this software for any
6 dc5351b4 2019-07-30 stsp # purpose with or without fee is hereby granted, provided that the above
7 dc5351b4 2019-07-30 stsp # copyright notice and this permission notice appear in all copies.
8 dc5351b4 2019-07-30 stsp #
9 dc5351b4 2019-07-30 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 dc5351b4 2019-07-30 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 dc5351b4 2019-07-30 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 dc5351b4 2019-07-30 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 dc5351b4 2019-07-30 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 dc5351b4 2019-07-30 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 dc5351b4 2019-07-30 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 dc5351b4 2019-07-30 stsp
17 dc5351b4 2019-07-30 stsp . ./common.sh
18 dc5351b4 2019-07-30 stsp
19 f6cae3ed 2020-09-13 naddy test_branch_create() {
20 dc5351b4 2019-07-30 stsp local testroot=`test_init branch_create`
21 da76fce2 2020-02-24 stsp local commit_id0=`git_show_head $testroot/repo`
22 dc5351b4 2019-07-30 stsp
23 dc5351b4 2019-07-30 stsp # Create a branch based on repository's HEAD reference
24 dc5351b4 2019-07-30 stsp got branch -r $testroot/repo newbranch
25 49c543a6 2022-03-31 naddy ret=$?
26 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
27 dc5351b4 2019-07-30 stsp echo "got branch command failed unexpectedly"
28 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
29 dc5351b4 2019-07-30 stsp return 1
30 dc5351b4 2019-07-30 stsp fi
31 dc5351b4 2019-07-30 stsp
32 dc5351b4 2019-07-30 stsp # Ensure that Git recognizes the branch Got has created
33 dc5351b4 2019-07-30 stsp (cd $testroot/repo && git checkout -q newbranch)
34 49c543a6 2022-03-31 naddy ret=$?
35 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
36 dc5351b4 2019-07-30 stsp echo "git checkout command failed unexpectedly"
37 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
38 dc5351b4 2019-07-30 stsp return 1
39 dc5351b4 2019-07-30 stsp fi
40 dc5351b4 2019-07-30 stsp echo "modified delta on branch" > $testroot/repo/gamma/delta
41 dc5351b4 2019-07-30 stsp git_commit $testroot/repo -m "committing to delta on newbranch"
42 dc5351b4 2019-07-30 stsp
43 dc5351b4 2019-07-30 stsp got checkout -b newbranch $testroot/repo $testroot/wt >/dev/null
44 49c543a6 2022-03-31 naddy ret=$?
45 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
46 dc5351b4 2019-07-30 stsp echo "got checkout command failed unexpectedly"
47 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
48 dc5351b4 2019-07-30 stsp return 1
49 dc5351b4 2019-07-30 stsp fi
50 dc5351b4 2019-07-30 stsp
51 dc5351b4 2019-07-30 stsp echo "modified delta on branch" > $testroot/content.expected
52 dc5351b4 2019-07-30 stsp cat $testroot/wt/gamma/delta > $testroot/content
53 dc5351b4 2019-07-30 stsp cmp -s $testroot/content.expected $testroot/content
54 49c543a6 2022-03-31 naddy ret=$?
55 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
56 dc5351b4 2019-07-30 stsp diff -u $testroot/content.expected $testroot/content
57 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
58 dc5351b4 2019-07-30 stsp return 1
59 dc5351b4 2019-07-30 stsp fi
60 dc5351b4 2019-07-30 stsp
61 dc5351b4 2019-07-30 stsp # Create a branch based on the work tree's branch
62 2f1457c6 2021-08-27 stsp (cd $testroot/wt && got branch -n refs/heads/anotherbranch)
63 49c543a6 2022-03-31 naddy ret=$?
64 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
65 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
66 dc5351b4 2019-07-30 stsp return 1
67 dc5351b4 2019-07-30 stsp fi
68 dc5351b4 2019-07-30 stsp
69 dc5351b4 2019-07-30 stsp (cd $testroot/repo && git checkout -q anotherbranch)
70 49c543a6 2022-03-31 naddy ret=$?
71 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
72 dc5351b4 2019-07-30 stsp echo "git checkout command failed unexpectedly"
73 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
74 dc5351b4 2019-07-30 stsp return 1
75 dc5351b4 2019-07-30 stsp fi
76 dc5351b4 2019-07-30 stsp
77 dc5351b4 2019-07-30 stsp # Create a branch based on another specific branch
78 da76fce2 2020-02-24 stsp (cd $testroot/wt && got branch -n -c master yetanotherbranch)
79 49c543a6 2022-03-31 naddy ret=$?
80 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
81 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
82 dc5351b4 2019-07-30 stsp return 1
83 dc5351b4 2019-07-30 stsp fi
84 dc5351b4 2019-07-30 stsp
85 dc5351b4 2019-07-30 stsp (cd $testroot/repo && git checkout -q yetanotherbranch)
86 49c543a6 2022-03-31 naddy ret=$?
87 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
88 a4f89d48 2019-08-25 stsp echo "git checkout command failed unexpectedly"
89 a4f89d48 2019-08-25 stsp test_done "$testroot" "$ret"
90 a4f89d48 2019-08-25 stsp return 1
91 a4f89d48 2019-08-25 stsp fi
92 a4f89d48 2019-08-25 stsp
93 a4f89d48 2019-08-25 stsp # Create a branch based on a specific commit
94 a4f89d48 2019-08-25 stsp local commit_id=`git_show_head $testroot/repo`
95 a74f7e83 2019-11-10 stsp got branch -r $testroot/repo -c $commit_id commitbranch
96 49c543a6 2022-03-31 naddy ret=$?
97 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
98 a4f89d48 2019-08-25 stsp echo "got branch command failed unexpectedly"
99 a4f89d48 2019-08-25 stsp test_done "$testroot" "$ret"
100 a4f89d48 2019-08-25 stsp return 1
101 a4f89d48 2019-08-25 stsp fi
102 a4f89d48 2019-08-25 stsp
103 a4f89d48 2019-08-25 stsp (cd $testroot/repo && git checkout -q commitbranch)
104 49c543a6 2022-03-31 naddy ret=$?
105 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
106 dc5351b4 2019-07-30 stsp echo "git checkout command failed unexpectedly"
107 da76fce2 2020-02-24 stsp test_done "$testroot" "$ret"
108 da76fce2 2020-02-24 stsp return 1
109 dc5351b4 2019-07-30 stsp fi
110 da76fce2 2020-02-24 stsp
111 da76fce2 2020-02-24 stsp # Create a branch and let the work tree be updated to it
112 da76fce2 2020-02-24 stsp (cd $testroot/wt && got branch -c $commit_id0 updatebranch \
113 da76fce2 2020-02-24 stsp > $testroot/stdout)
114 da76fce2 2020-02-24 stsp
115 da76fce2 2020-02-24 stsp echo -n "Switching work tree from refs/heads/newbranch to " \
116 da76fce2 2020-02-24 stsp > $testroot/stdout.expected
117 da76fce2 2020-02-24 stsp echo "refs/heads/updatebranch" >> $testroot/stdout.expected
118 da76fce2 2020-02-24 stsp echo "U gamma/delta" >> $testroot/stdout.expected
119 4f3c844b 2021-09-14 stsp echo "Updated to refs/heads/updatebranch: $commit_id0" \
120 4f3c844b 2021-09-14 stsp >> $testroot/stdout.expected
121 da76fce2 2020-02-24 stsp
122 da76fce2 2020-02-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
123 49c543a6 2022-03-31 naddy ret=$?
124 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
125 da76fce2 2020-02-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
126 da76fce2 2020-02-24 stsp fi
127 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
128 dc5351b4 2019-07-30 stsp }
129 dc5351b4 2019-07-30 stsp
130 f6cae3ed 2020-09-13 naddy test_branch_list() {
131 dc5351b4 2019-07-30 stsp local testroot=`test_init branch_list`
132 dc5351b4 2019-07-30 stsp local commit_id=`git_show_head $testroot/repo`
133 dc5351b4 2019-07-30 stsp
134 dc5351b4 2019-07-30 stsp for b in branch1 branch2 branch3; do
135 dc5351b4 2019-07-30 stsp got branch -r $testroot/repo $b
136 49c543a6 2022-03-31 naddy ret=$?
137 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
138 dc5351b4 2019-07-30 stsp echo "got branch command failed unexpectedly"
139 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
140 dc5351b4 2019-07-30 stsp return 1
141 dc5351b4 2019-07-30 stsp fi
142 dc5351b4 2019-07-30 stsp done
143 dc5351b4 2019-07-30 stsp
144 dc5351b4 2019-07-30 stsp got branch -l -r $testroot/repo > $testroot/stdout
145 dc5351b4 2019-07-30 stsp echo " branch1: $commit_id" > $testroot/stdout.expected
146 dc5351b4 2019-07-30 stsp echo " branch2: $commit_id" >> $testroot/stdout.expected
147 dc5351b4 2019-07-30 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
148 dc5351b4 2019-07-30 stsp echo " master: $commit_id" >> $testroot/stdout.expected
149 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
150 49c543a6 2022-03-31 naddy ret=$?
151 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
152 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
153 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
154 dc5351b4 2019-07-30 stsp return 1
155 dc5351b4 2019-07-30 stsp fi
156 dc5351b4 2019-07-30 stsp
157 dc5351b4 2019-07-30 stsp got checkout $testroot/repo $testroot/wt >/dev/null
158 49c543a6 2022-03-31 naddy ret=$?
159 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
160 dc5351b4 2019-07-30 stsp echo "got checkout command failed unexpectedly"
161 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
162 dc5351b4 2019-07-30 stsp return 1
163 dc5351b4 2019-07-30 stsp fi
164 dc5351b4 2019-07-30 stsp
165 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got branch -l > $testroot/stdout)
166 dc5351b4 2019-07-30 stsp echo " branch1: $commit_id" > $testroot/stdout.expected
167 dc5351b4 2019-07-30 stsp echo " branch2: $commit_id" >> $testroot/stdout.expected
168 dc5351b4 2019-07-30 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
169 dc5351b4 2019-07-30 stsp echo "* master: $commit_id" >> $testroot/stdout.expected
170 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
171 49c543a6 2022-03-31 naddy ret=$?
172 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
173 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
174 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
175 dc5351b4 2019-07-30 stsp return 1
176 dc5351b4 2019-07-30 stsp fi
177 dc5351b4 2019-07-30 stsp
178 dc5351b4 2019-07-30 stsp echo "modified delta" > $testroot/repo/gamma/delta
179 dc5351b4 2019-07-30 stsp git_commit $testroot/repo -m "committing to delta"
180 dc5351b4 2019-07-30 stsp local commit_id2=`git_show_head $testroot/repo`
181 dc5351b4 2019-07-30 stsp
182 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got branch -l > $testroot/stdout)
183 dc5351b4 2019-07-30 stsp echo " branch1: $commit_id" > $testroot/stdout.expected
184 dc5351b4 2019-07-30 stsp echo " branch2: $commit_id" >> $testroot/stdout.expected
185 dc5351b4 2019-07-30 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
186 dc5351b4 2019-07-30 stsp echo "~ master: $commit_id2" >> $testroot/stdout.expected
187 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
188 49c543a6 2022-03-31 naddy ret=$?
189 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
190 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
191 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
192 dc5351b4 2019-07-30 stsp return 1
193 dc5351b4 2019-07-30 stsp fi
194 dc5351b4 2019-07-30 stsp
195 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got update > /dev/null)
196 49c543a6 2022-03-31 naddy ret=$?
197 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
198 dc5351b4 2019-07-30 stsp echo "got update command failed unexpectedly"
199 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
200 dc5351b4 2019-07-30 stsp return 1
201 dc5351b4 2019-07-30 stsp fi
202 dc5351b4 2019-07-30 stsp
203 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got branch -l > $testroot/stdout)
204 dc5351b4 2019-07-30 stsp echo " branch1: $commit_id" > $testroot/stdout.expected
205 dc5351b4 2019-07-30 stsp echo " branch2: $commit_id" >> $testroot/stdout.expected
206 dc5351b4 2019-07-30 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
207 dc5351b4 2019-07-30 stsp echo "* master: $commit_id2" >> $testroot/stdout.expected
208 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
209 49c543a6 2022-03-31 naddy ret=$?
210 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
211 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
212 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
213 dc5351b4 2019-07-30 stsp return 1
214 dc5351b4 2019-07-30 stsp fi
215 dc5351b4 2019-07-30 stsp
216 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got update -b branch1 > /dev/null)
217 49c543a6 2022-03-31 naddy ret=$?
218 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
219 dc5351b4 2019-07-30 stsp echo "got update command failed unexpectedly"
220 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
221 dc5351b4 2019-07-30 stsp return 1
222 dc5351b4 2019-07-30 stsp fi
223 dc5351b4 2019-07-30 stsp
224 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got branch -l > $testroot/stdout)
225 dc5351b4 2019-07-30 stsp echo "* branch1: $commit_id" > $testroot/stdout.expected
226 dc5351b4 2019-07-30 stsp echo " branch2: $commit_id" >> $testroot/stdout.expected
227 dc5351b4 2019-07-30 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
228 dc5351b4 2019-07-30 stsp echo " master: $commit_id2" >> $testroot/stdout.expected
229 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
230 49c543a6 2022-03-31 naddy ret=$?
231 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
232 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
233 dc5351b4 2019-07-30 stsp fi
234 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
235 dc5351b4 2019-07-30 stsp }
236 dc5351b4 2019-07-30 stsp
237 f6cae3ed 2020-09-13 naddy test_branch_delete() {
238 dc5351b4 2019-07-30 stsp local testroot=`test_init branch_delete`
239 dc5351b4 2019-07-30 stsp local commit_id=`git_show_head $testroot/repo`
240 dc5351b4 2019-07-30 stsp
241 dc5351b4 2019-07-30 stsp for b in branch1 branch2 branch3; do
242 dc5351b4 2019-07-30 stsp got branch -r $testroot/repo $b
243 49c543a6 2022-03-31 naddy ret=$?
244 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
245 dc5351b4 2019-07-30 stsp echo "got branch command failed unexpectedly"
246 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
247 dc5351b4 2019-07-30 stsp return 1
248 dc5351b4 2019-07-30 stsp fi
249 dc5351b4 2019-07-30 stsp done
250 dc5351b4 2019-07-30 stsp
251 dc5351b4 2019-07-30 stsp got branch -d branch2 -r $testroot/repo > $testroot/stdout
252 49c543a6 2022-03-31 naddy ret=$?
253 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
254 2f1457c6 2021-08-27 stsp echo "got branch command failed unexpectedly"
255 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
256 dc5351b4 2019-07-30 stsp return 1
257 dc5351b4 2019-07-30 stsp fi
258 dc5351b4 2019-07-30 stsp
259 dc5351b4 2019-07-30 stsp got branch -l -r $testroot/repo > $testroot/stdout
260 dc5351b4 2019-07-30 stsp echo " branch1: $commit_id" > $testroot/stdout.expected
261 dc5351b4 2019-07-30 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
262 dc5351b4 2019-07-30 stsp echo " master: $commit_id" >> $testroot/stdout.expected
263 6aeab596 2019-08-28 stsp cmp -s $testroot/stdout $testroot/stdout.expected
264 49c543a6 2022-03-31 naddy ret=$?
265 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
266 6aeab596 2019-08-28 stsp diff -u $testroot/stdout.expected $testroot/stdout
267 6aeab596 2019-08-28 stsp test_done "$testroot" "$ret"
268 6aeab596 2019-08-28 stsp return 1
269 6aeab596 2019-08-28 stsp fi
270 6aeab596 2019-08-28 stsp
271 6aeab596 2019-08-28 stsp got ref -l -r $testroot/repo > $testroot/stdout
272 6aeab596 2019-08-28 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
273 6aeab596 2019-08-28 stsp echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
274 6aeab596 2019-08-28 stsp echo "refs/heads/branch3: $commit_id" >> $testroot/stdout.expected
275 6aeab596 2019-08-28 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
276 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
277 49c543a6 2022-03-31 naddy ret=$?
278 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
279 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
280 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
281 dc5351b4 2019-07-30 stsp return 1
282 dc5351b4 2019-07-30 stsp fi
283 dc5351b4 2019-07-30 stsp
284 dc5351b4 2019-07-30 stsp got branch -d bogus_branch_name -r $testroot/repo \
285 dc5351b4 2019-07-30 stsp > $testroot/stdout 2> $testroot/stderr
286 49c543a6 2022-03-31 naddy ret=$?
287 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
288 2f1457c6 2021-08-27 stsp echo "got branch succeeded unexpectedly"
289 a19f439c 2022-06-03 op test_done "$testroot" "1"
290 dc5351b4 2019-07-30 stsp return 1
291 dc5351b4 2019-07-30 stsp fi
292 dc5351b4 2019-07-30 stsp
293 dc5351b4 2019-07-30 stsp echo "got: reference refs/heads/bogus_branch_name not found" \
294 dc5351b4 2019-07-30 stsp > $testroot/stderr.expected
295 dc5351b4 2019-07-30 stsp cmp -s $testroot/stderr $testroot/stderr.expected
296 49c543a6 2022-03-31 naddy ret=$?
297 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
298 dc5351b4 2019-07-30 stsp diff -u $testroot/stderr.expected $testroot/stderr
299 2f1457c6 2021-08-27 stsp test_done "$testroot" "$ret"
300 2f1457c6 2021-08-27 stsp return 1
301 dc5351b4 2019-07-30 stsp fi
302 2f1457c6 2021-08-27 stsp
303 2f1457c6 2021-08-27 stsp got ref -r $testroot/repo -c master refs/remotes/origin/master
304 2f1457c6 2021-08-27 stsp got ref -r $testroot/repo -c branch1 refs/remotes/origin/branch1
305 2f1457c6 2021-08-27 stsp got ref -r $testroot/repo -c branch3 refs/remotes/origin/branch3
306 2f1457c6 2021-08-27 stsp
307 2f1457c6 2021-08-27 stsp got ref -l -r $testroot/repo > $testroot/stdout
308 2f1457c6 2021-08-27 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
309 2f1457c6 2021-08-27 stsp echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
310 2f1457c6 2021-08-27 stsp echo "refs/heads/branch3: $commit_id" >> $testroot/stdout.expected
311 2f1457c6 2021-08-27 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
312 2f1457c6 2021-08-27 stsp echo "refs/remotes/origin/branch1: $commit_id" \
313 2f1457c6 2021-08-27 stsp >> $testroot/stdout.expected
314 2f1457c6 2021-08-27 stsp echo "refs/remotes/origin/branch3: $commit_id" \
315 2f1457c6 2021-08-27 stsp >> $testroot/stdout.expected
316 2f1457c6 2021-08-27 stsp echo "refs/remotes/origin/master: $commit_id" \
317 2f1457c6 2021-08-27 stsp >> $testroot/stdout.expected
318 2f1457c6 2021-08-27 stsp cmp -s $testroot/stdout $testroot/stdout.expected
319 49c543a6 2022-03-31 naddy ret=$?
320 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
321 2f1457c6 2021-08-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
322 2f1457c6 2021-08-27 stsp test_done "$testroot" "$ret"
323 2f1457c6 2021-08-27 stsp return 1
324 2f1457c6 2021-08-27 stsp fi
325 2f1457c6 2021-08-27 stsp
326 2f1457c6 2021-08-27 stsp got branch -d origin/branch1 -r $testroot/repo > $testroot/stdout
327 49c543a6 2022-03-31 naddy ret=$?
328 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
329 2f1457c6 2021-08-27 stsp echo "got branch command failed unexpectedly"
330 2f1457c6 2021-08-27 stsp test_done "$testroot" "$ret"
331 2f1457c6 2021-08-27 stsp return 1
332 2f1457c6 2021-08-27 stsp fi
333 2f1457c6 2021-08-27 stsp
334 2f1457c6 2021-08-27 stsp got branch -d refs/remotes/origin/branch3 -r $testroot/repo \
335 2f1457c6 2021-08-27 stsp > $testroot/stdout
336 49c543a6 2022-03-31 naddy ret=$?
337 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
338 2f1457c6 2021-08-27 stsp echo "got branch command failed unexpectedly"
339 2f1457c6 2021-08-27 stsp test_done "$testroot" "$ret"
340 2f1457c6 2021-08-27 stsp return 1
341 2f1457c6 2021-08-27 stsp fi
342 2f1457c6 2021-08-27 stsp
343 2f1457c6 2021-08-27 stsp got ref -l -r $testroot/repo > $testroot/stdout
344 2f1457c6 2021-08-27 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
345 2f1457c6 2021-08-27 stsp echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
346 2f1457c6 2021-08-27 stsp echo "refs/heads/branch3: $commit_id" >> $testroot/stdout.expected
347 2f1457c6 2021-08-27 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
348 2f1457c6 2021-08-27 stsp echo "refs/remotes/origin/master: $commit_id" \
349 2f1457c6 2021-08-27 stsp >> $testroot/stdout.expected
350 2f1457c6 2021-08-27 stsp cmp -s $testroot/stdout $testroot/stdout.expected
351 49c543a6 2022-03-31 naddy ret=$?
352 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
353 2f1457c6 2021-08-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
354 2f1457c6 2021-08-27 stsp fi
355 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
356 dc5351b4 2019-07-30 stsp }
357 dc5351b4 2019-07-30 stsp
358 f6cae3ed 2020-09-13 naddy test_branch_delete_current_branch() {
359 45cd4e47 2019-08-25 stsp local testroot=`test_init branch_delete_current_branch`
360 45cd4e47 2019-08-25 stsp local commit_id=`git_show_head $testroot/repo`
361 45cd4e47 2019-08-25 stsp
362 45cd4e47 2019-08-25 stsp got checkout $testroot/repo $testroot/wt >/dev/null
363 49c543a6 2022-03-31 naddy ret=$?
364 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
365 45cd4e47 2019-08-25 stsp echo "got checkout command failed unexpectedly"
366 45cd4e47 2019-08-25 stsp test_done "$testroot" "$ret"
367 45cd4e47 2019-08-25 stsp return 1
368 45cd4e47 2019-08-25 stsp fi
369 dc5351b4 2019-07-30 stsp
370 45cd4e47 2019-08-25 stsp (cd $testroot/wt && got branch -d master > $testroot/stdout \
371 45cd4e47 2019-08-25 stsp 2> $testroot/stderr)
372 45cd4e47 2019-08-25 stsp
373 45cd4e47 2019-08-25 stsp echo "got: will not delete this work tree's current branch" \
374 6aeab596 2019-08-28 stsp > $testroot/stderr.expected
375 6aeab596 2019-08-28 stsp cmp -s $testroot/stderr $testroot/stderr.expected
376 49c543a6 2022-03-31 naddy ret=$?
377 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
378 6aeab596 2019-08-28 stsp diff -u $testroot/stderr.expected $testroot/stderr
379 6aeab596 2019-08-28 stsp fi
380 6aeab596 2019-08-28 stsp test_done "$testroot" "$ret"
381 6aeab596 2019-08-28 stsp }
382 6aeab596 2019-08-28 stsp
383 f6cae3ed 2020-09-13 naddy test_branch_delete_packed() {
384 6aeab596 2019-08-28 stsp local testroot=`test_init branch_delete_packed`
385 6aeab596 2019-08-28 stsp local commit_id=`git_show_head $testroot/repo`
386 6aeab596 2019-08-28 stsp
387 6aeab596 2019-08-28 stsp for b in branch1 branch2 branch3; do
388 6aeab596 2019-08-28 stsp got branch -r $testroot/repo $b
389 49c543a6 2022-03-31 naddy ret=$?
390 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
391 6aeab596 2019-08-28 stsp echo "got branch command failed unexpectedly"
392 6aeab596 2019-08-28 stsp test_done "$testroot" "$ret"
393 6aeab596 2019-08-28 stsp return 1
394 6aeab596 2019-08-28 stsp fi
395 6aeab596 2019-08-28 stsp done
396 6aeab596 2019-08-28 stsp
397 6aeab596 2019-08-28 stsp (cd $testroot/repo && git pack-refs --all)
398 6aeab596 2019-08-28 stsp
399 2f1457c6 2021-08-27 stsp got branch -d refs/heads/branch2 -r $testroot/repo > $testroot/stdout
400 49c543a6 2022-03-31 naddy ret=$?
401 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
402 6aeab596 2019-08-28 stsp echo "got update command failed unexpectedly"
403 6aeab596 2019-08-28 stsp test_done "$testroot" "$ret"
404 6aeab596 2019-08-28 stsp return 1
405 6aeab596 2019-08-28 stsp fi
406 6aeab596 2019-08-28 stsp
407 6aeab596 2019-08-28 stsp got branch -l -r $testroot/repo > $testroot/stdout
408 6aeab596 2019-08-28 stsp echo " branch1: $commit_id" > $testroot/stdout.expected
409 6aeab596 2019-08-28 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
410 6aeab596 2019-08-28 stsp echo " master: $commit_id" >> $testroot/stdout.expected
411 6aeab596 2019-08-28 stsp cmp -s $testroot/stdout $testroot/stdout.expected
412 49c543a6 2022-03-31 naddy ret=$?
413 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
414 6aeab596 2019-08-28 stsp diff -u $testroot/stdout.expected $testroot/stdout
415 6aeab596 2019-08-28 stsp test_done "$testroot" "$ret"
416 6aeab596 2019-08-28 stsp return 1
417 6aeab596 2019-08-28 stsp fi
418 6aeab596 2019-08-28 stsp
419 6aeab596 2019-08-28 stsp got ref -l -r $testroot/repo > $testroot/stdout
420 6aeab596 2019-08-28 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
421 6aeab596 2019-08-28 stsp echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
422 6aeab596 2019-08-28 stsp echo "refs/heads/branch3: $commit_id" >> $testroot/stdout.expected
423 6aeab596 2019-08-28 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
424 6aeab596 2019-08-28 stsp cmp -s $testroot/stdout $testroot/stdout.expected
425 49c543a6 2022-03-31 naddy ret=$?
426 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
427 6aeab596 2019-08-28 stsp diff -u $testroot/stdout.expected $testroot/stdout
428 6aeab596 2019-08-28 stsp test_done "$testroot" "$ret"
429 6aeab596 2019-08-28 stsp return 1
430 6aeab596 2019-08-28 stsp fi
431 6aeab596 2019-08-28 stsp
432 6aeab596 2019-08-28 stsp got branch -d bogus_branch_name -r $testroot/repo \
433 6aeab596 2019-08-28 stsp > $testroot/stdout 2> $testroot/stderr
434 49c543a6 2022-03-31 naddy ret=$?
435 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
436 6aeab596 2019-08-28 stsp echo "got update succeeded unexpectedly"
437 a19f439c 2022-06-03 op test_done "$testroot" "1"
438 6aeab596 2019-08-28 stsp return 1
439 6aeab596 2019-08-28 stsp fi
440 6aeab596 2019-08-28 stsp
441 6aeab596 2019-08-28 stsp echo "got: reference refs/heads/bogus_branch_name not found" \
442 45cd4e47 2019-08-25 stsp > $testroot/stderr.expected
443 45cd4e47 2019-08-25 stsp cmp -s $testroot/stderr $testroot/stderr.expected
444 49c543a6 2022-03-31 naddy ret=$?
445 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
446 45cd4e47 2019-08-25 stsp diff -u $testroot/stderr.expected $testroot/stderr
447 ad89fa31 2019-10-04 stsp fi
448 ad89fa31 2019-10-04 stsp test_done "$testroot" "$ret"
449 ad89fa31 2019-10-04 stsp }
450 ad89fa31 2019-10-04 stsp
451 f6cae3ed 2020-09-13 naddy test_branch_show() {
452 ad89fa31 2019-10-04 stsp local testroot=`test_init branch_show`
453 ad89fa31 2019-10-04 stsp local commit_id=`git_show_head $testroot/repo`
454 ad89fa31 2019-10-04 stsp
455 ad89fa31 2019-10-04 stsp for b in branch1 branch2 branch3; do
456 ad89fa31 2019-10-04 stsp got branch -r $testroot/repo $b
457 49c543a6 2022-03-31 naddy ret=$?
458 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
459 ad89fa31 2019-10-04 stsp echo "got branch command failed unexpectedly"
460 ad89fa31 2019-10-04 stsp test_done "$testroot" "$ret"
461 ad89fa31 2019-10-04 stsp return 1
462 ad89fa31 2019-10-04 stsp fi
463 ad89fa31 2019-10-04 stsp done
464 ad89fa31 2019-10-04 stsp
465 ad89fa31 2019-10-04 stsp got checkout $testroot/repo $testroot/wt >/dev/null
466 49c543a6 2022-03-31 naddy ret=$?
467 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
468 ad89fa31 2019-10-04 stsp echo "got checkout command failed unexpectedly"
469 ad89fa31 2019-10-04 stsp test_done "$testroot" "$ret"
470 ad89fa31 2019-10-04 stsp return 1
471 ad89fa31 2019-10-04 stsp fi
472 ad89fa31 2019-10-04 stsp
473 ad89fa31 2019-10-04 stsp (cd $testroot/wt && got branch > $testroot/stdout)
474 ad89fa31 2019-10-04 stsp echo "master" > $testroot/stdout.expected
475 ad89fa31 2019-10-04 stsp cmp -s $testroot/stdout $testroot/stdout.expected
476 49c543a6 2022-03-31 naddy ret=$?
477 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
478 ad89fa31 2019-10-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
479 ad89fa31 2019-10-04 stsp test_done "$testroot" "$ret"
480 ad89fa31 2019-10-04 stsp return 1
481 45cd4e47 2019-08-25 stsp fi
482 ad89fa31 2019-10-04 stsp
483 ad89fa31 2019-10-04 stsp (cd $testroot/wt && got update -b branch1 > /dev/null)
484 49c543a6 2022-03-31 naddy ret=$?
485 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
486 ad89fa31 2019-10-04 stsp echo "got update command failed unexpectedly"
487 ad89fa31 2019-10-04 stsp test_done "$testroot" "$ret"
488 ad89fa31 2019-10-04 stsp return 1
489 ad89fa31 2019-10-04 stsp fi
490 ad89fa31 2019-10-04 stsp
491 ad89fa31 2019-10-04 stsp (cd $testroot/wt && got branch > $testroot/stdout)
492 ad89fa31 2019-10-04 stsp echo "branch1" > $testroot/stdout.expected
493 ad89fa31 2019-10-04 stsp cmp -s $testroot/stdout $testroot/stdout.expected
494 49c543a6 2022-03-31 naddy ret=$?
495 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
496 ad89fa31 2019-10-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
497 ad89fa31 2019-10-04 stsp fi
498 45cd4e47 2019-08-25 stsp test_done "$testroot" "$ret"
499 ad89fa31 2019-10-04 stsp
500 45cd4e47 2019-08-25 stsp }
501 7db2b0dd 2022-09-05 stsp
502 7db2b0dd 2022-09-05 stsp test_branch_packed_ref_collision() {
503 7db2b0dd 2022-09-05 stsp local testroot=`test_init branch_packed_ref_collision`
504 7db2b0dd 2022-09-05 stsp local commit_id=`git_show_head $testroot/repo`
505 45cd4e47 2019-08-25 stsp
506 7db2b0dd 2022-09-05 stsp got br -r $testroot/repo zoo > $testroot/stdout
507 7db2b0dd 2022-09-05 stsp got co -b zoo $testroot/repo $testroot/wt > /dev/null
508 7db2b0dd 2022-09-05 stsp echo "modified alpha" > $testroot/wt/alpha
509 7db2b0dd 2022-09-05 stsp
510 7db2b0dd 2022-09-05 stsp # sleep in order to ensure that a significant fraction of time
511 7db2b0dd 2022-09-05 stsp # passes between commits; required for got branch -t option below
512 7db2b0dd 2022-09-05 stsp sleep 1
513 7db2b0dd 2022-09-05 stsp
514 7db2b0dd 2022-09-05 stsp (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
515 7db2b0dd 2022-09-05 stsp local commit_id2=`git_show_branch_head $testroot/repo zoo`
516 7db2b0dd 2022-09-05 stsp
517 7db2b0dd 2022-09-05 stsp # Fabricate a packed reference which points to an older commit
518 7db2b0dd 2022-09-05 stsp # and collides with the existing on-disk reference
519 7db2b0dd 2022-09-05 stsp echo '# pack-refs with: peeled fully-peeled sorted' > \
520 7db2b0dd 2022-09-05 stsp $testroot/repo/.git/packed-refs
521 7db2b0dd 2022-09-05 stsp echo "$commit_id refs/heads/zoo" >> $testroot/repo/.git/packed-refs
522 7db2b0dd 2022-09-05 stsp
523 7db2b0dd 2022-09-05 stsp # Bug: This command used to show both packed and on-disk
524 7db2b0dd 2022-09-05 stsp # variants of ref/heads/zoo:
525 7db2b0dd 2022-09-05 stsp (cd $testroot/wt && got br -lt > $testroot/stdout)
526 7db2b0dd 2022-09-05 stsp
527 7db2b0dd 2022-09-05 stsp echo "* zoo: $commit_id2" > $testroot/stdout.expected
528 7db2b0dd 2022-09-05 stsp echo " master: $commit_id" >> $testroot/stdout.expected
529 7db2b0dd 2022-09-05 stsp cmp -s $testroot/stdout $testroot/stdout.expected
530 7db2b0dd 2022-09-05 stsp ret=$?
531 7db2b0dd 2022-09-05 stsp if [ $ret -ne 0 ]; then
532 7db2b0dd 2022-09-05 stsp diff -u $testroot/stdout.expected $testroot/stdout
533 7db2b0dd 2022-09-05 stsp test_done "$testroot" "$ret"
534 7db2b0dd 2022-09-05 stsp return 1
535 7db2b0dd 2022-09-05 stsp fi
536 7db2b0dd 2022-09-05 stsp
537 7db2b0dd 2022-09-05 stsp test_done "$testroot" "$ret"
538 7db2b0dd 2022-09-05 stsp }
539 7db2b0dd 2022-09-05 stsp
540 7fb414ae 2020-08-08 stsp test_parseargs "$@"
541 dc5351b4 2019-07-30 stsp run_test test_branch_create
542 dc5351b4 2019-07-30 stsp run_test test_branch_list
543 dc5351b4 2019-07-30 stsp run_test test_branch_delete
544 45cd4e47 2019-08-25 stsp run_test test_branch_delete_current_branch
545 6aeab596 2019-08-28 stsp run_test test_branch_delete_packed
546 ad89fa31 2019-10-04 stsp run_test test_branch_show
547 7db2b0dd 2022-09-05 stsp run_test test_branch_packed_ref_collision