3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
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.
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.
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
25 if [ "$ret" != "0" ]; then
26 echo "got branch command failed unexpectedly"
27 test_done "$testroot" "$ret"
31 # Ensure that Git recognizes the branch Got has created
32 (cd $testroot/repo && git checkout -q newbranch)
34 if [ "$ret" != "0" ]; then
35 echo "git checkout command failed unexpectedly"
36 test_done "$testroot" "$ret"
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
44 if [ "$ret" != "0" ]; then
45 echo "got checkout command failed unexpectedly"
46 test_done "$testroot" "$ret"
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
54 if [ "$ret" != "0" ]; then
55 diff -u $testroot/content.expected $testroot/content
56 test_done "$testroot" "$ret"
60 # Create a branch based on the work tree's branch
61 (cd $testroot/wt && got branch anotherbranch)
63 if [ "$ret" != "0" ]; then
64 test_done "$testroot" "$ret"
68 (cd $testroot/repo && git checkout -q anotherbranch)
70 if [ "$ret" != "0" ]; then
71 echo "git checkout command failed unexpectedly"
72 test_done "$testroot" "$ret"
76 # Create a branch based on another specific branch
77 (cd $testroot/wt && got branch yetanotherbranch master)
79 if [ "$ret" != "0" ]; then
80 test_done "$testroot" "$ret"
84 (cd $testroot/repo && git checkout -q yetanotherbranch)
86 if [ "$ret" != "0" ]; then
87 echo "git checkout command failed unexpectedly"
89 test_done "$testroot" "$ret"
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
99 if [ "$ret" != "0" ]; then
100 echo "got branch command failed unexpectedly"
101 test_done "$testroot" "$ret"
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
113 if [ "$ret" != "0" ]; then
114 diff -u $testroot/stdout.expected $testroot/stdout
115 test_done "$testroot" "$ret"
119 got checkout $testroot/repo $testroot/wt >/dev/null
121 if [ "$ret" != "0" ]; then
122 echo "got checkout command failed unexpectedly"
123 test_done "$testroot" "$ret"
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
134 if [ "$ret" != "0" ]; then
135 diff -u $testroot/stdout.expected $testroot/stdout
136 test_done "$testroot" "$ret"
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
151 if [ "$ret" != "0" ]; then
152 diff -u $testroot/stdout.expected $testroot/stdout
153 test_done "$testroot" "$ret"
157 (cd $testroot/wt && got update > /dev/null)
159 if [ "$ret" != "0" ]; then
160 echo "got update command failed unexpectedly"
161 test_done "$testroot" "$ret"
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
172 if [ "$ret" != "0" ]; then
173 diff -u $testroot/stdout.expected $testroot/stdout
174 test_done "$testroot" "$ret"
178 (cd $testroot/wt && got update -b branch1 > /dev/null)
180 if [ "$ret" != "0" ]; then
181 echo "got update command failed unexpectedly"
182 test_done "$testroot" "$ret"
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
193 if [ "$ret" != "0" ]; then
194 diff -u $testroot/stdout.expected $testroot/stdout
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
206 if [ "$ret" != "0" ]; then
207 echo "got branch command failed unexpectedly"
208 test_done "$testroot" "$ret"
213 got branch -d branch2 -r $testroot/repo > $testroot/stdout
215 if [ "$ret" != "0" ]; then
216 echo "got update command failed unexpectedly"
217 test_done "$testroot" "$ret"
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
227 if [ "$ret" != "0" ]; then
228 diff -u $testroot/stdout.expected $testroot/stdout
229 test_done "$testroot" "$ret"
233 got branch -d bogus_branch_name -r $testroot/repo \
234 > $testroot/stdout 2> $testroot/stderr
236 if [ "$ret" == "0" ]; then
237 echo "got update succeeded unexpectedly"
238 test_done "$testroot" "$ret"
242 echo "got: reference refs/heads/bogus_branch_name not found" \
243 > $testroot/stderr.expected
244 cmp -s $testroot/stderr $testroot/stderr.expected
246 if [ "$ret" != "0" ]; then
247 diff -u $testroot/stderr.expected $testroot/stderr
249 test_done "$testroot" "$ret"
253 run_test test_branch_create
254 run_test test_branch_list
255 run_test test_branch_delete