3 dc5351b4 2019-07-30 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
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.
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.
17 dc5351b4 2019-07-30 stsp . ./common.sh
19 dc5351b4 2019-07-30 stsp function test_branch_create {
20 dc5351b4 2019-07-30 stsp local testroot=`test_init branch_create`
22 dc5351b4 2019-07-30 stsp # Create a branch based on repository's HEAD reference
23 dc5351b4 2019-07-30 stsp got branch -r $testroot/repo newbranch
25 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
26 dc5351b4 2019-07-30 stsp echo "got branch command failed unexpectedly"
27 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
31 dc5351b4 2019-07-30 stsp # Ensure that Git recognizes the branch Got has created
32 dc5351b4 2019-07-30 stsp (cd $testroot/repo && git checkout -q newbranch)
34 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
35 dc5351b4 2019-07-30 stsp echo "git checkout command failed unexpectedly"
36 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
39 dc5351b4 2019-07-30 stsp echo "modified delta on branch" > $testroot/repo/gamma/delta
40 dc5351b4 2019-07-30 stsp git_commit $testroot/repo -m "committing to delta on newbranch"
42 dc5351b4 2019-07-30 stsp got checkout -b newbranch $testroot/repo $testroot/wt >/dev/null
44 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
45 dc5351b4 2019-07-30 stsp echo "got checkout command failed unexpectedly"
46 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
50 dc5351b4 2019-07-30 stsp echo "modified delta on branch" > $testroot/content.expected
51 dc5351b4 2019-07-30 stsp cat $testroot/wt/gamma/delta > $testroot/content
52 dc5351b4 2019-07-30 stsp cmp -s $testroot/content.expected $testroot/content
54 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
55 dc5351b4 2019-07-30 stsp diff -u $testroot/content.expected $testroot/content
56 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
60 dc5351b4 2019-07-30 stsp # Create a branch based on the work tree's branch
61 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got branch anotherbranch)
63 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
64 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
68 dc5351b4 2019-07-30 stsp (cd $testroot/repo && git checkout -q anotherbranch)
70 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
71 dc5351b4 2019-07-30 stsp echo "git checkout command failed unexpectedly"
72 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
76 dc5351b4 2019-07-30 stsp # Create a branch based on another specific branch
77 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got branch yetanotherbranch master)
79 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
80 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
84 dc5351b4 2019-07-30 stsp (cd $testroot/repo && git checkout -q yetanotherbranch)
86 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
87 dc5351b4 2019-07-30 stsp echo "git checkout command failed unexpectedly"
89 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
92 dc5351b4 2019-07-30 stsp function test_branch_list {
93 dc5351b4 2019-07-30 stsp local testroot=`test_init branch_list`
94 dc5351b4 2019-07-30 stsp local commit_id=`git_show_head $testroot/repo`
96 dc5351b4 2019-07-30 stsp for b in branch1 branch2 branch3; do
97 dc5351b4 2019-07-30 stsp got branch -r $testroot/repo $b
99 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
100 dc5351b4 2019-07-30 stsp echo "got branch command failed unexpectedly"
101 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
106 dc5351b4 2019-07-30 stsp got branch -l -r $testroot/repo > $testroot/stdout
107 dc5351b4 2019-07-30 stsp echo " branch1: $commit_id" > $testroot/stdout.expected
108 dc5351b4 2019-07-30 stsp echo " branch2: $commit_id" >> $testroot/stdout.expected
109 dc5351b4 2019-07-30 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
110 dc5351b4 2019-07-30 stsp echo " master: $commit_id" >> $testroot/stdout.expected
111 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
113 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
114 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
115 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
119 dc5351b4 2019-07-30 stsp got checkout $testroot/repo $testroot/wt >/dev/null
121 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
122 dc5351b4 2019-07-30 stsp echo "got checkout command failed unexpectedly"
123 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
127 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got branch -l > $testroot/stdout)
128 dc5351b4 2019-07-30 stsp echo " branch1: $commit_id" > $testroot/stdout.expected
129 dc5351b4 2019-07-30 stsp echo " branch2: $commit_id" >> $testroot/stdout.expected
130 dc5351b4 2019-07-30 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
131 dc5351b4 2019-07-30 stsp echo "* master: $commit_id" >> $testroot/stdout.expected
132 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
134 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
135 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
136 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
140 dc5351b4 2019-07-30 stsp echo "modified delta" > $testroot/repo/gamma/delta
141 dc5351b4 2019-07-30 stsp git_commit $testroot/repo -m "committing to delta"
142 dc5351b4 2019-07-30 stsp local commit_id2=`git_show_head $testroot/repo`
144 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got branch -l > $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_id2" >> $testroot/stdout.expected
149 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
151 dc5351b4 2019-07-30 stsp if [ "$ret" != "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"
157 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got update > /dev/null)
159 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
160 dc5351b4 2019-07-30 stsp echo "got update command failed unexpectedly"
161 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
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_id2" >> $testroot/stdout.expected
170 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
172 dc5351b4 2019-07-30 stsp if [ "$ret" != "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"
178 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got update -b branch1 > /dev/null)
180 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
181 dc5351b4 2019-07-30 stsp echo "got update command failed unexpectedly"
182 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
186 dc5351b4 2019-07-30 stsp (cd $testroot/wt && got branch -l > $testroot/stdout)
187 dc5351b4 2019-07-30 stsp echo "* branch1: $commit_id" > $testroot/stdout.expected
188 dc5351b4 2019-07-30 stsp echo " branch2: $commit_id" >> $testroot/stdout.expected
189 dc5351b4 2019-07-30 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
190 dc5351b4 2019-07-30 stsp echo " master: $commit_id2" >> $testroot/stdout.expected
191 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
193 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
194 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
196 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
199 dc5351b4 2019-07-30 stsp function test_branch_delete {
200 dc5351b4 2019-07-30 stsp local testroot=`test_init branch_delete`
201 dc5351b4 2019-07-30 stsp local commit_id=`git_show_head $testroot/repo`
203 dc5351b4 2019-07-30 stsp for b in branch1 branch2 branch3; do
204 dc5351b4 2019-07-30 stsp got branch -r $testroot/repo $b
206 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
207 dc5351b4 2019-07-30 stsp echo "got branch command failed unexpectedly"
208 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
213 dc5351b4 2019-07-30 stsp got branch -d branch2 -r $testroot/repo > $testroot/stdout
215 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
216 dc5351b4 2019-07-30 stsp echo "got update command failed unexpectedly"
217 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
221 dc5351b4 2019-07-30 stsp got branch -l -r $testroot/repo > $testroot/stdout
222 dc5351b4 2019-07-30 stsp echo " branch1: $commit_id" > $testroot/stdout.expected
223 dc5351b4 2019-07-30 stsp echo " branch3: $commit_id" >> $testroot/stdout.expected
224 dc5351b4 2019-07-30 stsp echo " master: $commit_id" >> $testroot/stdout.expected
225 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
227 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
228 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
229 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
233 dc5351b4 2019-07-30 stsp got branch -d bogus_branch_name -r $testroot/repo \
234 dc5351b4 2019-07-30 stsp > $testroot/stdout 2> $testroot/stderr
236 dc5351b4 2019-07-30 stsp if [ "$ret" == "0" ]; then
237 dc5351b4 2019-07-30 stsp echo "got update succeeded unexpectedly"
238 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
242 dc5351b4 2019-07-30 stsp echo "got: reference refs/heads/bogus_branch_name not found" \
243 dc5351b4 2019-07-30 stsp > $testroot/stderr.expected
244 dc5351b4 2019-07-30 stsp cmp -s $testroot/stderr $testroot/stderr.expected
246 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
247 dc5351b4 2019-07-30 stsp diff -u $testroot/stderr.expected $testroot/stderr
249 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
253 dc5351b4 2019-07-30 stsp run_test test_branch_create
254 dc5351b4 2019-07-30 stsp run_test test_branch_list
255 dc5351b4 2019-07-30 stsp run_test test_branch_delete