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 dc5351b4 2019-07-30 stsp ret="$?"
26 dc5351b4 2019-07-30 stsp if [ "$ret" != "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 dc5351b4 2019-07-30 stsp ret="$?"
35 dc5351b4 2019-07-30 stsp if [ "$ret" != "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 dc5351b4 2019-07-30 stsp ret="$?"
45 dc5351b4 2019-07-30 stsp if [ "$ret" != "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 dc5351b4 2019-07-30 stsp ret="$?"
55 dc5351b4 2019-07-30 stsp if [ "$ret" != "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 dc5351b4 2019-07-30 stsp ret="$?"
64 dc5351b4 2019-07-30 stsp if [ "$ret" != "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 dc5351b4 2019-07-30 stsp ret="$?"
71 dc5351b4 2019-07-30 stsp if [ "$ret" != "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 dc5351b4 2019-07-30 stsp ret="$?"
80 dc5351b4 2019-07-30 stsp if [ "$ret" != "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 a4f89d48 2019-08-25 stsp ret="$?"
87 a4f89d48 2019-08-25 stsp if [ "$ret" != "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 dc5351b4 2019-07-30 stsp ret="$?"
97 dc5351b4 2019-07-30 stsp if [ "$ret" != "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 a4f89d48 2019-08-25 stsp ret="$?"
105 a4f89d48 2019-08-25 stsp if [ "$ret" != "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 da76fce2 2020-02-24 stsp echo "Updated to commit $commit_id0" >> $testroot/stdout.expected
120 da76fce2 2020-02-24 stsp
121 da76fce2 2020-02-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
122 da76fce2 2020-02-24 stsp ret="$?"
123 da76fce2 2020-02-24 stsp if [ "$ret" != "0" ]; then
124 da76fce2 2020-02-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
125 da76fce2 2020-02-24 stsp fi
126 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
127 dc5351b4 2019-07-30 stsp }
128 dc5351b4 2019-07-30 stsp
129 f6cae3ed 2020-09-13 naddy test_branch_list() {
130 dc5351b4 2019-07-30 stsp local testroot=`test_init branch_list`
131 dc5351b4 2019-07-30 stsp local commit_id=`git_show_head $testroot/repo`
132 dc5351b4 2019-07-30 stsp
133 dc5351b4 2019-07-30 stsp for b in branch1 branch2 branch3; do
134 dc5351b4 2019-07-30 stsp got branch -r $testroot/repo $b
135 dc5351b4 2019-07-30 stsp ret="$?"
136 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
137 dc5351b4 2019-07-30 stsp echo "got branch command failed unexpectedly"
138 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
139 dc5351b4 2019-07-30 stsp return 1
140 dc5351b4 2019-07-30 stsp fi
141 dc5351b4 2019-07-30 stsp done
142 dc5351b4 2019-07-30 stsp
143 dc5351b4 2019-07-30 stsp got branch -l -r $testroot/repo > $testroot/stdout
144 dc5351b4 2019-07-30 stsp echo " branch1: $commit_id" > $testroot/stdout.expected
145 dc5351b4 2019-07-30 stsp echo " branch2: $commit_id" >> $testroot/stdout.expected
146 dc5351b4 2019-07-30 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
147 dc5351b4 2019-07-30 stsp echo " master: $commit_id" >> $testroot/stdout.expected
148 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
149 dc5351b4 2019-07-30 stsp ret="$?"
150 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
151 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
152 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
153 dc5351b4 2019-07-30 stsp return 1
154 dc5351b4 2019-07-30 stsp fi
155 dc5351b4 2019-07-30 stsp
156 dc5351b4 2019-07-30 stsp got checkout $testroot/repo $testroot/wt >/dev/null
157 dc5351b4 2019-07-30 stsp ret="$?"
158 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
159 dc5351b4 2019-07-30 stsp echo "got checkout command failed unexpectedly"
160 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
161 dc5351b4 2019-07-30 stsp return 1
162 dc5351b4 2019-07-30 stsp fi
163 dc5351b4 2019-07-30 stsp
164 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got branch -l > $testroot/stdout)
165 dc5351b4 2019-07-30 stsp echo " branch1: $commit_id" > $testroot/stdout.expected
166 dc5351b4 2019-07-30 stsp echo " branch2: $commit_id" >> $testroot/stdout.expected
167 dc5351b4 2019-07-30 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
168 dc5351b4 2019-07-30 stsp echo "* master: $commit_id" >> $testroot/stdout.expected
169 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
170 dc5351b4 2019-07-30 stsp ret="$?"
171 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
172 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
173 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
174 dc5351b4 2019-07-30 stsp return 1
175 dc5351b4 2019-07-30 stsp fi
176 dc5351b4 2019-07-30 stsp
177 dc5351b4 2019-07-30 stsp echo "modified delta" > $testroot/repo/gamma/delta
178 dc5351b4 2019-07-30 stsp git_commit $testroot/repo -m "committing to delta"
179 dc5351b4 2019-07-30 stsp local commit_id2=`git_show_head $testroot/repo`
180 dc5351b4 2019-07-30 stsp
181 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got branch -l > $testroot/stdout)
182 dc5351b4 2019-07-30 stsp echo " branch1: $commit_id" > $testroot/stdout.expected
183 dc5351b4 2019-07-30 stsp echo " branch2: $commit_id" >> $testroot/stdout.expected
184 dc5351b4 2019-07-30 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
185 dc5351b4 2019-07-30 stsp echo "~ master: $commit_id2" >> $testroot/stdout.expected
186 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
187 dc5351b4 2019-07-30 stsp ret="$?"
188 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
189 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
190 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
191 dc5351b4 2019-07-30 stsp return 1
192 dc5351b4 2019-07-30 stsp fi
193 dc5351b4 2019-07-30 stsp
194 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got update > /dev/null)
195 dc5351b4 2019-07-30 stsp ret="$?"
196 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
197 dc5351b4 2019-07-30 stsp echo "got update command failed unexpectedly"
198 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
199 dc5351b4 2019-07-30 stsp return 1
200 dc5351b4 2019-07-30 stsp fi
201 dc5351b4 2019-07-30 stsp
202 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got branch -l > $testroot/stdout)
203 dc5351b4 2019-07-30 stsp echo " branch1: $commit_id" > $testroot/stdout.expected
204 dc5351b4 2019-07-30 stsp echo " branch2: $commit_id" >> $testroot/stdout.expected
205 dc5351b4 2019-07-30 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
206 dc5351b4 2019-07-30 stsp echo "* master: $commit_id2" >> $testroot/stdout.expected
207 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
208 dc5351b4 2019-07-30 stsp ret="$?"
209 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
210 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
211 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
212 dc5351b4 2019-07-30 stsp return 1
213 dc5351b4 2019-07-30 stsp fi
214 dc5351b4 2019-07-30 stsp
215 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got update -b branch1 > /dev/null)
216 dc5351b4 2019-07-30 stsp ret="$?"
217 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
218 dc5351b4 2019-07-30 stsp echo "got update command failed unexpectedly"
219 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
220 dc5351b4 2019-07-30 stsp return 1
221 dc5351b4 2019-07-30 stsp fi
222 dc5351b4 2019-07-30 stsp
223 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got branch -l > $testroot/stdout)
224 dc5351b4 2019-07-30 stsp echo "* branch1: $commit_id" > $testroot/stdout.expected
225 dc5351b4 2019-07-30 stsp echo " branch2: $commit_id" >> $testroot/stdout.expected
226 dc5351b4 2019-07-30 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
227 dc5351b4 2019-07-30 stsp echo " master: $commit_id2" >> $testroot/stdout.expected
228 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
229 dc5351b4 2019-07-30 stsp ret="$?"
230 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
231 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
232 dc5351b4 2019-07-30 stsp fi
233 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
234 dc5351b4 2019-07-30 stsp }
235 dc5351b4 2019-07-30 stsp
236 f6cae3ed 2020-09-13 naddy test_branch_delete() {
237 dc5351b4 2019-07-30 stsp local testroot=`test_init branch_delete`
238 dc5351b4 2019-07-30 stsp local commit_id=`git_show_head $testroot/repo`
239 dc5351b4 2019-07-30 stsp
240 dc5351b4 2019-07-30 stsp for b in branch1 branch2 branch3; do
241 dc5351b4 2019-07-30 stsp got branch -r $testroot/repo $b
242 dc5351b4 2019-07-30 stsp ret="$?"
243 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
244 dc5351b4 2019-07-30 stsp echo "got branch command failed unexpectedly"
245 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
246 dc5351b4 2019-07-30 stsp return 1
247 dc5351b4 2019-07-30 stsp fi
248 dc5351b4 2019-07-30 stsp done
249 dc5351b4 2019-07-30 stsp
250 dc5351b4 2019-07-30 stsp got branch -d branch2 -r $testroot/repo > $testroot/stdout
251 dc5351b4 2019-07-30 stsp ret="$?"
252 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
253 2f1457c6 2021-08-27 stsp echo "got branch command failed unexpectedly"
254 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
255 dc5351b4 2019-07-30 stsp return 1
256 dc5351b4 2019-07-30 stsp fi
257 dc5351b4 2019-07-30 stsp
258 dc5351b4 2019-07-30 stsp got branch -l -r $testroot/repo > $testroot/stdout
259 dc5351b4 2019-07-30 stsp echo " branch1: $commit_id" > $testroot/stdout.expected
260 dc5351b4 2019-07-30 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
261 dc5351b4 2019-07-30 stsp echo " master: $commit_id" >> $testroot/stdout.expected
262 6aeab596 2019-08-28 stsp cmp -s $testroot/stdout $testroot/stdout.expected
263 6aeab596 2019-08-28 stsp ret="$?"
264 6aeab596 2019-08-28 stsp if [ "$ret" != "0" ]; then
265 6aeab596 2019-08-28 stsp diff -u $testroot/stdout.expected $testroot/stdout
266 6aeab596 2019-08-28 stsp test_done "$testroot" "$ret"
267 6aeab596 2019-08-28 stsp return 1
268 6aeab596 2019-08-28 stsp fi
269 6aeab596 2019-08-28 stsp
270 6aeab596 2019-08-28 stsp got ref -l -r $testroot/repo > $testroot/stdout
271 6aeab596 2019-08-28 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
272 6aeab596 2019-08-28 stsp echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
273 6aeab596 2019-08-28 stsp echo "refs/heads/branch3: $commit_id" >> $testroot/stdout.expected
274 6aeab596 2019-08-28 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
275 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
276 dc5351b4 2019-07-30 stsp ret="$?"
277 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
278 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
279 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
280 dc5351b4 2019-07-30 stsp return 1
281 dc5351b4 2019-07-30 stsp fi
282 dc5351b4 2019-07-30 stsp
283 dc5351b4 2019-07-30 stsp got branch -d bogus_branch_name -r $testroot/repo \
284 dc5351b4 2019-07-30 stsp > $testroot/stdout 2> $testroot/stderr
285 dc5351b4 2019-07-30 stsp ret="$?"
286 54c39596 2020-12-28 stsp if [ "$ret" = "0" ]; then
287 2f1457c6 2021-08-27 stsp echo "got branch succeeded unexpectedly"
288 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
289 dc5351b4 2019-07-30 stsp return 1
290 dc5351b4 2019-07-30 stsp fi
291 dc5351b4 2019-07-30 stsp
292 dc5351b4 2019-07-30 stsp echo "got: reference refs/heads/bogus_branch_name not found" \
293 dc5351b4 2019-07-30 stsp > $testroot/stderr.expected
294 dc5351b4 2019-07-30 stsp cmp -s $testroot/stderr $testroot/stderr.expected
295 dc5351b4 2019-07-30 stsp ret="$?"
296 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
297 dc5351b4 2019-07-30 stsp diff -u $testroot/stderr.expected $testroot/stderr
298 2f1457c6 2021-08-27 stsp test_done "$testroot" "$ret"
299 2f1457c6 2021-08-27 stsp return 1
300 dc5351b4 2019-07-30 stsp fi
301 2f1457c6 2021-08-27 stsp
302 2f1457c6 2021-08-27 stsp got ref -r $testroot/repo -c master refs/remotes/origin/master
303 2f1457c6 2021-08-27 stsp got ref -r $testroot/repo -c branch1 refs/remotes/origin/branch1
304 2f1457c6 2021-08-27 stsp got ref -r $testroot/repo -c branch3 refs/remotes/origin/branch3
305 2f1457c6 2021-08-27 stsp
306 2f1457c6 2021-08-27 stsp got ref -l -r $testroot/repo > $testroot/stdout
307 2f1457c6 2021-08-27 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
308 2f1457c6 2021-08-27 stsp echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
309 2f1457c6 2021-08-27 stsp echo "refs/heads/branch3: $commit_id" >> $testroot/stdout.expected
310 2f1457c6 2021-08-27 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
311 2f1457c6 2021-08-27 stsp echo "refs/remotes/origin/branch1: $commit_id" \
312 2f1457c6 2021-08-27 stsp >> $testroot/stdout.expected
313 2f1457c6 2021-08-27 stsp echo "refs/remotes/origin/branch3: $commit_id" \
314 2f1457c6 2021-08-27 stsp >> $testroot/stdout.expected
315 2f1457c6 2021-08-27 stsp echo "refs/remotes/origin/master: $commit_id" \
316 2f1457c6 2021-08-27 stsp >> $testroot/stdout.expected
317 2f1457c6 2021-08-27 stsp cmp -s $testroot/stdout $testroot/stdout.expected
318 2f1457c6 2021-08-27 stsp ret="$?"
319 2f1457c6 2021-08-27 stsp if [ "$ret" != "0" ]; then
320 2f1457c6 2021-08-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
321 2f1457c6 2021-08-27 stsp test_done "$testroot" "$ret"
322 2f1457c6 2021-08-27 stsp return 1
323 2f1457c6 2021-08-27 stsp fi
324 2f1457c6 2021-08-27 stsp
325 2f1457c6 2021-08-27 stsp got branch -d origin/branch1 -r $testroot/repo > $testroot/stdout
326 2f1457c6 2021-08-27 stsp ret="$?"
327 2f1457c6 2021-08-27 stsp if [ "$ret" != "0" ]; then
328 2f1457c6 2021-08-27 stsp echo "got branch command failed unexpectedly"
329 2f1457c6 2021-08-27 stsp test_done "$testroot" "$ret"
330 2f1457c6 2021-08-27 stsp return 1
331 2f1457c6 2021-08-27 stsp fi
332 2f1457c6 2021-08-27 stsp
333 2f1457c6 2021-08-27 stsp got branch -d refs/remotes/origin/branch3 -r $testroot/repo \
334 2f1457c6 2021-08-27 stsp > $testroot/stdout
335 2f1457c6 2021-08-27 stsp ret="$?"
336 2f1457c6 2021-08-27 stsp if [ "$ret" != "0" ]; then
337 2f1457c6 2021-08-27 stsp echo "got branch command failed unexpectedly"
338 2f1457c6 2021-08-27 stsp test_done "$testroot" "$ret"
339 2f1457c6 2021-08-27 stsp return 1
340 2f1457c6 2021-08-27 stsp fi
341 2f1457c6 2021-08-27 stsp
342 2f1457c6 2021-08-27 stsp got ref -l -r $testroot/repo > $testroot/stdout
343 2f1457c6 2021-08-27 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
344 2f1457c6 2021-08-27 stsp echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
345 2f1457c6 2021-08-27 stsp echo "refs/heads/branch3: $commit_id" >> $testroot/stdout.expected
346 2f1457c6 2021-08-27 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
347 2f1457c6 2021-08-27 stsp echo "refs/remotes/origin/master: $commit_id" \
348 2f1457c6 2021-08-27 stsp >> $testroot/stdout.expected
349 2f1457c6 2021-08-27 stsp cmp -s $testroot/stdout $testroot/stdout.expected
350 2f1457c6 2021-08-27 stsp ret="$?"
351 2f1457c6 2021-08-27 stsp if [ "$ret" != "0" ]; then
352 2f1457c6 2021-08-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
353 2f1457c6 2021-08-27 stsp fi
354 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
355 dc5351b4 2019-07-30 stsp }
356 dc5351b4 2019-07-30 stsp
357 f6cae3ed 2020-09-13 naddy test_branch_delete_current_branch() {
358 45cd4e47 2019-08-25 stsp local testroot=`test_init branch_delete_current_branch`
359 45cd4e47 2019-08-25 stsp local commit_id=`git_show_head $testroot/repo`
360 45cd4e47 2019-08-25 stsp
361 45cd4e47 2019-08-25 stsp got checkout $testroot/repo $testroot/wt >/dev/null
362 45cd4e47 2019-08-25 stsp ret="$?"
363 45cd4e47 2019-08-25 stsp if [ "$ret" != "0" ]; then
364 45cd4e47 2019-08-25 stsp echo "got checkout command failed unexpectedly"
365 45cd4e47 2019-08-25 stsp test_done "$testroot" "$ret"
366 45cd4e47 2019-08-25 stsp return 1
367 45cd4e47 2019-08-25 stsp fi
368 dc5351b4 2019-07-30 stsp
369 45cd4e47 2019-08-25 stsp (cd $testroot/wt && got branch -d master > $testroot/stdout \
370 45cd4e47 2019-08-25 stsp 2> $testroot/stderr)
371 45cd4e47 2019-08-25 stsp
372 45cd4e47 2019-08-25 stsp echo "got: will not delete this work tree's current branch" \
373 6aeab596 2019-08-28 stsp > $testroot/stderr.expected
374 6aeab596 2019-08-28 stsp cmp -s $testroot/stderr $testroot/stderr.expected
375 6aeab596 2019-08-28 stsp ret="$?"
376 6aeab596 2019-08-28 stsp if [ "$ret" != "0" ]; then
377 6aeab596 2019-08-28 stsp diff -u $testroot/stderr.expected $testroot/stderr
378 6aeab596 2019-08-28 stsp fi
379 6aeab596 2019-08-28 stsp test_done "$testroot" "$ret"
380 6aeab596 2019-08-28 stsp }
381 6aeab596 2019-08-28 stsp
382 f6cae3ed 2020-09-13 naddy test_branch_delete_packed() {
383 6aeab596 2019-08-28 stsp local testroot=`test_init branch_delete_packed`
384 6aeab596 2019-08-28 stsp local commit_id=`git_show_head $testroot/repo`
385 6aeab596 2019-08-28 stsp
386 6aeab596 2019-08-28 stsp for b in branch1 branch2 branch3; do
387 6aeab596 2019-08-28 stsp got branch -r $testroot/repo $b
388 6aeab596 2019-08-28 stsp ret="$?"
389 6aeab596 2019-08-28 stsp if [ "$ret" != "0" ]; then
390 6aeab596 2019-08-28 stsp echo "got branch command failed unexpectedly"
391 6aeab596 2019-08-28 stsp test_done "$testroot" "$ret"
392 6aeab596 2019-08-28 stsp return 1
393 6aeab596 2019-08-28 stsp fi
394 6aeab596 2019-08-28 stsp done
395 6aeab596 2019-08-28 stsp
396 6aeab596 2019-08-28 stsp (cd $testroot/repo && git pack-refs --all)
397 6aeab596 2019-08-28 stsp
398 2f1457c6 2021-08-27 stsp got branch -d refs/heads/branch2 -r $testroot/repo > $testroot/stdout
399 6aeab596 2019-08-28 stsp ret="$?"
400 6aeab596 2019-08-28 stsp if [ "$ret" != "0" ]; then
401 6aeab596 2019-08-28 stsp echo "got update command failed unexpectedly"
402 6aeab596 2019-08-28 stsp test_done "$testroot" "$ret"
403 6aeab596 2019-08-28 stsp return 1
404 6aeab596 2019-08-28 stsp fi
405 6aeab596 2019-08-28 stsp
406 6aeab596 2019-08-28 stsp got branch -l -r $testroot/repo > $testroot/stdout
407 6aeab596 2019-08-28 stsp echo " branch1: $commit_id" > $testroot/stdout.expected
408 6aeab596 2019-08-28 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
409 6aeab596 2019-08-28 stsp echo " master: $commit_id" >> $testroot/stdout.expected
410 6aeab596 2019-08-28 stsp cmp -s $testroot/stdout $testroot/stdout.expected
411 6aeab596 2019-08-28 stsp ret="$?"
412 6aeab596 2019-08-28 stsp if [ "$ret" != "0" ]; then
413 6aeab596 2019-08-28 stsp diff -u $testroot/stdout.expected $testroot/stdout
414 6aeab596 2019-08-28 stsp test_done "$testroot" "$ret"
415 6aeab596 2019-08-28 stsp return 1
416 6aeab596 2019-08-28 stsp fi
417 6aeab596 2019-08-28 stsp
418 6aeab596 2019-08-28 stsp got ref -l -r $testroot/repo > $testroot/stdout
419 6aeab596 2019-08-28 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
420 6aeab596 2019-08-28 stsp echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
421 6aeab596 2019-08-28 stsp echo "refs/heads/branch3: $commit_id" >> $testroot/stdout.expected
422 6aeab596 2019-08-28 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
423 6aeab596 2019-08-28 stsp cmp -s $testroot/stdout $testroot/stdout.expected
424 6aeab596 2019-08-28 stsp ret="$?"
425 6aeab596 2019-08-28 stsp if [ "$ret" != "0" ]; then
426 6aeab596 2019-08-28 stsp diff -u $testroot/stdout.expected $testroot/stdout
427 6aeab596 2019-08-28 stsp test_done "$testroot" "$ret"
428 6aeab596 2019-08-28 stsp return 1
429 6aeab596 2019-08-28 stsp fi
430 6aeab596 2019-08-28 stsp
431 6aeab596 2019-08-28 stsp got branch -d bogus_branch_name -r $testroot/repo \
432 6aeab596 2019-08-28 stsp > $testroot/stdout 2> $testroot/stderr
433 6aeab596 2019-08-28 stsp ret="$?"
434 54c39596 2020-12-28 stsp if [ "$ret" = "0" ]; then
435 6aeab596 2019-08-28 stsp echo "got update succeeded unexpectedly"
436 6aeab596 2019-08-28 stsp test_done "$testroot" "$ret"
437 6aeab596 2019-08-28 stsp return 1
438 6aeab596 2019-08-28 stsp fi
439 6aeab596 2019-08-28 stsp
440 6aeab596 2019-08-28 stsp echo "got: reference refs/heads/bogus_branch_name not found" \
441 45cd4e47 2019-08-25 stsp > $testroot/stderr.expected
442 45cd4e47 2019-08-25 stsp cmp -s $testroot/stderr $testroot/stderr.expected
443 45cd4e47 2019-08-25 stsp ret="$?"
444 45cd4e47 2019-08-25 stsp if [ "$ret" != "0" ]; then
445 45cd4e47 2019-08-25 stsp diff -u $testroot/stderr.expected $testroot/stderr
446 ad89fa31 2019-10-04 stsp fi
447 ad89fa31 2019-10-04 stsp test_done "$testroot" "$ret"
448 ad89fa31 2019-10-04 stsp }
449 ad89fa31 2019-10-04 stsp
450 f6cae3ed 2020-09-13 naddy test_branch_show() {
451 ad89fa31 2019-10-04 stsp local testroot=`test_init branch_show`
452 ad89fa31 2019-10-04 stsp local commit_id=`git_show_head $testroot/repo`
453 ad89fa31 2019-10-04 stsp
454 ad89fa31 2019-10-04 stsp for b in branch1 branch2 branch3; do
455 ad89fa31 2019-10-04 stsp got branch -r $testroot/repo $b
456 ad89fa31 2019-10-04 stsp ret="$?"
457 ad89fa31 2019-10-04 stsp if [ "$ret" != "0" ]; then
458 ad89fa31 2019-10-04 stsp echo "got branch command failed unexpectedly"
459 ad89fa31 2019-10-04 stsp test_done "$testroot" "$ret"
460 ad89fa31 2019-10-04 stsp return 1
461 ad89fa31 2019-10-04 stsp fi
462 ad89fa31 2019-10-04 stsp done
463 ad89fa31 2019-10-04 stsp
464 ad89fa31 2019-10-04 stsp got checkout $testroot/repo $testroot/wt >/dev/null
465 ad89fa31 2019-10-04 stsp ret="$?"
466 ad89fa31 2019-10-04 stsp if [ "$ret" != "0" ]; then
467 ad89fa31 2019-10-04 stsp echo "got checkout command failed unexpectedly"
468 ad89fa31 2019-10-04 stsp test_done "$testroot" "$ret"
469 ad89fa31 2019-10-04 stsp return 1
470 ad89fa31 2019-10-04 stsp fi
471 ad89fa31 2019-10-04 stsp
472 ad89fa31 2019-10-04 stsp (cd $testroot/wt && got branch > $testroot/stdout)
473 ad89fa31 2019-10-04 stsp echo "master" > $testroot/stdout.expected
474 ad89fa31 2019-10-04 stsp cmp -s $testroot/stdout $testroot/stdout.expected
475 ad89fa31 2019-10-04 stsp ret="$?"
476 ad89fa31 2019-10-04 stsp if [ "$ret" != "0" ]; then
477 ad89fa31 2019-10-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
478 ad89fa31 2019-10-04 stsp test_done "$testroot" "$ret"
479 ad89fa31 2019-10-04 stsp return 1
480 45cd4e47 2019-08-25 stsp fi
481 ad89fa31 2019-10-04 stsp
482 ad89fa31 2019-10-04 stsp (cd $testroot/wt && got update -b branch1 > /dev/null)
483 ad89fa31 2019-10-04 stsp ret="$?"
484 ad89fa31 2019-10-04 stsp if [ "$ret" != "0" ]; then
485 ad89fa31 2019-10-04 stsp echo "got update command failed unexpectedly"
486 ad89fa31 2019-10-04 stsp test_done "$testroot" "$ret"
487 ad89fa31 2019-10-04 stsp return 1
488 ad89fa31 2019-10-04 stsp fi
489 ad89fa31 2019-10-04 stsp
490 ad89fa31 2019-10-04 stsp (cd $testroot/wt && got branch > $testroot/stdout)
491 ad89fa31 2019-10-04 stsp echo "branch1" > $testroot/stdout.expected
492 ad89fa31 2019-10-04 stsp cmp -s $testroot/stdout $testroot/stdout.expected
493 ad89fa31 2019-10-04 stsp ret="$?"
494 ad89fa31 2019-10-04 stsp if [ "$ret" != "0" ]; then
495 ad89fa31 2019-10-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
496 ad89fa31 2019-10-04 stsp fi
497 45cd4e47 2019-08-25 stsp test_done "$testroot" "$ret"
498 ad89fa31 2019-10-04 stsp
499 45cd4e47 2019-08-25 stsp }
500 45cd4e47 2019-08-25 stsp
501 7fb414ae 2020-08-08 stsp test_parseargs "$@"
502 dc5351b4 2019-07-30 stsp run_test test_branch_create
503 dc5351b4 2019-07-30 stsp run_test test_branch_list
504 dc5351b4 2019-07-30 stsp run_test test_branch_delete
505 45cd4e47 2019-08-25 stsp run_test test_branch_delete_current_branch
506 6aeab596 2019-08-28 stsp run_test test_branch_delete_packed
507 ad89fa31 2019-10-04 stsp run_test test_branch_show