Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 function test_branch_create {
20 local testroot=`test_init branch_create`
22 # Create a branch based on repository's HEAD reference
23 got branch -r $testroot/repo newbranch
24 ret="$?"
25 if [ "$ret" != "0" ]; then
26 echo "got branch command failed unexpectedly"
27 test_done "$testroot" "$ret"
28 return 1
29 fi
31 # Ensure that Git recognizes the branch Got has created
32 (cd $testroot/repo && git checkout -q newbranch)
33 ret="$?"
34 if [ "$ret" != "0" ]; then
35 echo "git checkout command failed unexpectedly"
36 test_done "$testroot" "$ret"
37 return 1
38 fi
39 echo "modified delta on branch" > $testroot/repo/gamma/delta
40 git_commit $testroot/repo -m "committing to delta on newbranch"
42 got checkout -b newbranch $testroot/repo $testroot/wt >/dev/null
43 ret="$?"
44 if [ "$ret" != "0" ]; then
45 echo "got checkout command failed unexpectedly"
46 test_done "$testroot" "$ret"
47 return 1
48 fi
50 echo "modified delta on branch" > $testroot/content.expected
51 cat $testroot/wt/gamma/delta > $testroot/content
52 cmp -s $testroot/content.expected $testroot/content
53 ret="$?"
54 if [ "$ret" != "0" ]; then
55 diff -u $testroot/content.expected $testroot/content
56 test_done "$testroot" "$ret"
57 return 1
58 fi
60 # Create a branch based on the work tree's branch
61 (cd $testroot/wt && got branch anotherbranch)
62 ret="$?"
63 if [ "$ret" != "0" ]; then
64 test_done "$testroot" "$ret"
65 return 1
66 fi
68 (cd $testroot/repo && git checkout -q anotherbranch)
69 ret="$?"
70 if [ "$ret" != "0" ]; then
71 echo "git checkout command failed unexpectedly"
72 test_done "$testroot" "$ret"
73 return 1
74 fi
76 # Create a branch based on another specific branch
77 (cd $testroot/wt && got branch yetanotherbranch master)
78 ret="$?"
79 if [ "$ret" != "0" ]; then
80 test_done "$testroot" "$ret"
81 return 1
82 fi
84 (cd $testroot/repo && git checkout -q yetanotherbranch)
85 ret="$?"
86 if [ "$ret" != "0" ]; then
87 echo "git checkout command failed unexpectedly"
88 fi
89 test_done "$testroot" "$ret"
90 }
92 function test_branch_list {
93 local testroot=`test_init branch_list`
94 local commit_id=`git_show_head $testroot/repo`
96 for b in branch1 branch2 branch3; do
97 got branch -r $testroot/repo $b
98 ret="$?"
99 if [ "$ret" != "0" ]; then
100 echo "got branch command failed unexpectedly"
101 test_done "$testroot" "$ret"
102 return 1
103 fi
104 done
106 got branch -l -r $testroot/repo > $testroot/stdout
107 echo " branch1: $commit_id" > $testroot/stdout.expected
108 echo " branch2: $commit_id" >> $testroot/stdout.expected
109 echo " branch3: $commit_id" >> $testroot/stdout.expected
110 echo " master: $commit_id" >> $testroot/stdout.expected
111 cmp -s $testroot/stdout $testroot/stdout.expected
112 ret="$?"
113 if [ "$ret" != "0" ]; then
114 diff -u $testroot/stdout.expected $testroot/stdout
115 test_done "$testroot" "$ret"
116 return 1
117 fi
119 got checkout $testroot/repo $testroot/wt >/dev/null
120 ret="$?"
121 if [ "$ret" != "0" ]; then
122 echo "got checkout command failed unexpectedly"
123 test_done "$testroot" "$ret"
124 return 1
125 fi
127 (cd $testroot/wt && got branch -l > $testroot/stdout)
128 echo " branch1: $commit_id" > $testroot/stdout.expected
129 echo " branch2: $commit_id" >> $testroot/stdout.expected
130 echo " branch3: $commit_id" >> $testroot/stdout.expected
131 echo "* master: $commit_id" >> $testroot/stdout.expected
132 cmp -s $testroot/stdout $testroot/stdout.expected
133 ret="$?"
134 if [ "$ret" != "0" ]; then
135 diff -u $testroot/stdout.expected $testroot/stdout
136 test_done "$testroot" "$ret"
137 return 1
138 fi
140 echo "modified delta" > $testroot/repo/gamma/delta
141 git_commit $testroot/repo -m "committing to delta"
142 local commit_id2=`git_show_head $testroot/repo`
144 (cd $testroot/wt && got branch -l > $testroot/stdout)
145 echo " branch1: $commit_id" > $testroot/stdout.expected
146 echo " branch2: $commit_id" >> $testroot/stdout.expected
147 echo " branch3: $commit_id" >> $testroot/stdout.expected
148 echo "~ master: $commit_id2" >> $testroot/stdout.expected
149 cmp -s $testroot/stdout $testroot/stdout.expected
150 ret="$?"
151 if [ "$ret" != "0" ]; then
152 diff -u $testroot/stdout.expected $testroot/stdout
153 test_done "$testroot" "$ret"
154 return 1
155 fi
157 (cd $testroot/wt && got update > /dev/null)
158 ret="$?"
159 if [ "$ret" != "0" ]; then
160 echo "got update command failed unexpectedly"
161 test_done "$testroot" "$ret"
162 return 1
163 fi
165 (cd $testroot/wt && got branch -l > $testroot/stdout)
166 echo " branch1: $commit_id" > $testroot/stdout.expected
167 echo " branch2: $commit_id" >> $testroot/stdout.expected
168 echo " branch3: $commit_id" >> $testroot/stdout.expected
169 echo "* master: $commit_id2" >> $testroot/stdout.expected
170 cmp -s $testroot/stdout $testroot/stdout.expected
171 ret="$?"
172 if [ "$ret" != "0" ]; then
173 diff -u $testroot/stdout.expected $testroot/stdout
174 test_done "$testroot" "$ret"
175 return 1
176 fi
178 (cd $testroot/wt && got update -b branch1 > /dev/null)
179 ret="$?"
180 if [ "$ret" != "0" ]; then
181 echo "got update command failed unexpectedly"
182 test_done "$testroot" "$ret"
183 return 1
184 fi
186 (cd $testroot/wt && got branch -l > $testroot/stdout)
187 echo "* branch1: $commit_id" > $testroot/stdout.expected
188 echo " branch2: $commit_id" >> $testroot/stdout.expected
189 echo " branch3: $commit_id" >> $testroot/stdout.expected
190 echo " master: $commit_id2" >> $testroot/stdout.expected
191 cmp -s $testroot/stdout $testroot/stdout.expected
192 ret="$?"
193 if [ "$ret" != "0" ]; then
194 diff -u $testroot/stdout.expected $testroot/stdout
195 fi
196 test_done "$testroot" "$ret"
199 function test_branch_delete {
200 local testroot=`test_init branch_delete`
201 local commit_id=`git_show_head $testroot/repo`
203 for b in branch1 branch2 branch3; do
204 got branch -r $testroot/repo $b
205 ret="$?"
206 if [ "$ret" != "0" ]; then
207 echo "got branch command failed unexpectedly"
208 test_done "$testroot" "$ret"
209 return 1
210 fi
211 done
213 got branch -d branch2 -r $testroot/repo > $testroot/stdout
214 ret="$?"
215 if [ "$ret" != "0" ]; then
216 echo "got update command failed unexpectedly"
217 test_done "$testroot" "$ret"
218 return 1
219 fi
221 got branch -l -r $testroot/repo > $testroot/stdout
222 echo " branch1: $commit_id" > $testroot/stdout.expected
223 echo " branch3: $commit_id" >> $testroot/stdout.expected
224 echo " master: $commit_id" >> $testroot/stdout.expected
225 cmp -s $testroot/stdout $testroot/stdout.expected
226 ret="$?"
227 if [ "$ret" != "0" ]; then
228 diff -u $testroot/stdout.expected $testroot/stdout
229 test_done "$testroot" "$ret"
230 return 1
231 fi
233 got branch -d bogus_branch_name -r $testroot/repo \
234 > $testroot/stdout 2> $testroot/stderr
235 ret="$?"
236 if [ "$ret" == "0" ]; then
237 echo "got update succeeded unexpectedly"
238 test_done "$testroot" "$ret"
239 return 1
240 fi
242 echo "got: reference refs/heads/bogus_branch_name not found" \
243 > $testroot/stderr.expected
244 cmp -s $testroot/stderr $testroot/stderr.expected
245 ret="$?"
246 if [ "$ret" != "0" ]; then
247 diff -u $testroot/stderr.expected $testroot/stderr
248 fi
249 test_done "$testroot" "$ret"
253 run_test test_branch_create
254 run_test test_branch_list
255 run_test test_branch_delete