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 dc5351b4 2019-07-30 stsp function test_branch_create {
20 dc5351b4 2019-07-30 stsp local testroot=`test_init branch_create`
21 dc5351b4 2019-07-30 stsp
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
24 dc5351b4 2019-07-30 stsp ret="$?"
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"
28 dc5351b4 2019-07-30 stsp return 1
29 dc5351b4 2019-07-30 stsp fi
30 dc5351b4 2019-07-30 stsp
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)
33 dc5351b4 2019-07-30 stsp ret="$?"
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"
37 dc5351b4 2019-07-30 stsp return 1
38 dc5351b4 2019-07-30 stsp fi
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"
41 dc5351b4 2019-07-30 stsp
42 dc5351b4 2019-07-30 stsp got checkout -b newbranch $testroot/repo $testroot/wt >/dev/null
43 dc5351b4 2019-07-30 stsp ret="$?"
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"
47 dc5351b4 2019-07-30 stsp return 1
48 dc5351b4 2019-07-30 stsp fi
49 dc5351b4 2019-07-30 stsp
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
53 dc5351b4 2019-07-30 stsp ret="$?"
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"
57 dc5351b4 2019-07-30 stsp return 1
58 dc5351b4 2019-07-30 stsp fi
59 dc5351b4 2019-07-30 stsp
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)
62 dc5351b4 2019-07-30 stsp ret="$?"
63 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
64 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
65 dc5351b4 2019-07-30 stsp return 1
66 dc5351b4 2019-07-30 stsp fi
67 dc5351b4 2019-07-30 stsp
68 dc5351b4 2019-07-30 stsp (cd $testroot/repo && git checkout -q anotherbranch)
69 dc5351b4 2019-07-30 stsp ret="$?"
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"
73 dc5351b4 2019-07-30 stsp return 1
74 dc5351b4 2019-07-30 stsp fi
75 dc5351b4 2019-07-30 stsp
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)
78 dc5351b4 2019-07-30 stsp ret="$?"
79 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
80 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
81 dc5351b4 2019-07-30 stsp return 1
82 dc5351b4 2019-07-30 stsp fi
83 dc5351b4 2019-07-30 stsp
84 dc5351b4 2019-07-30 stsp (cd $testroot/repo && git checkout -q yetanotherbranch)
85 dc5351b4 2019-07-30 stsp ret="$?"
86 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
87 dc5351b4 2019-07-30 stsp echo "git checkout command failed unexpectedly"
88 dc5351b4 2019-07-30 stsp fi
89 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
90 dc5351b4 2019-07-30 stsp }
91 dc5351b4 2019-07-30 stsp
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`
95 dc5351b4 2019-07-30 stsp
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
98 dc5351b4 2019-07-30 stsp ret="$?"
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"
102 dc5351b4 2019-07-30 stsp return 1
103 dc5351b4 2019-07-30 stsp fi
104 dc5351b4 2019-07-30 stsp done
105 dc5351b4 2019-07-30 stsp
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
112 dc5351b4 2019-07-30 stsp ret="$?"
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"
116 dc5351b4 2019-07-30 stsp return 1
117 dc5351b4 2019-07-30 stsp fi
118 dc5351b4 2019-07-30 stsp
119 dc5351b4 2019-07-30 stsp got checkout $testroot/repo $testroot/wt >/dev/null
120 dc5351b4 2019-07-30 stsp ret="$?"
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"
124 dc5351b4 2019-07-30 stsp return 1
125 dc5351b4 2019-07-30 stsp fi
126 dc5351b4 2019-07-30 stsp
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
133 dc5351b4 2019-07-30 stsp ret="$?"
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"
137 dc5351b4 2019-07-30 stsp return 1
138 dc5351b4 2019-07-30 stsp fi
139 dc5351b4 2019-07-30 stsp
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`
143 dc5351b4 2019-07-30 stsp
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
150 dc5351b4 2019-07-30 stsp ret="$?"
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"
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 (cd $testroot/wt && got update > /dev/null)
158 dc5351b4 2019-07-30 stsp ret="$?"
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"
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_id2" >> $testroot/stdout.expected
170 dc5351b4 2019-07-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
171 dc5351b4 2019-07-30 stsp ret="$?"
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"
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 (cd $testroot/wt && got update -b branch1 > /dev/null)
179 dc5351b4 2019-07-30 stsp ret="$?"
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"
183 dc5351b4 2019-07-30 stsp return 1
184 dc5351b4 2019-07-30 stsp fi
185 dc5351b4 2019-07-30 stsp
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
192 dc5351b4 2019-07-30 stsp ret="$?"
193 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
194 dc5351b4 2019-07-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
195 dc5351b4 2019-07-30 stsp fi
196 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
197 dc5351b4 2019-07-30 stsp }
198 dc5351b4 2019-07-30 stsp
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`
202 dc5351b4 2019-07-30 stsp
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
205 dc5351b4 2019-07-30 stsp ret="$?"
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"
209 dc5351b4 2019-07-30 stsp return 1
210 dc5351b4 2019-07-30 stsp fi
211 dc5351b4 2019-07-30 stsp done
212 dc5351b4 2019-07-30 stsp
213 dc5351b4 2019-07-30 stsp got branch -d branch2 -r $testroot/repo > $testroot/stdout
214 dc5351b4 2019-07-30 stsp ret="$?"
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"
218 dc5351b4 2019-07-30 stsp return 1
219 dc5351b4 2019-07-30 stsp fi
220 dc5351b4 2019-07-30 stsp
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
226 dc5351b4 2019-07-30 stsp ret="$?"
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"
230 dc5351b4 2019-07-30 stsp return 1
231 dc5351b4 2019-07-30 stsp fi
232 dc5351b4 2019-07-30 stsp
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
235 dc5351b4 2019-07-30 stsp ret="$?"
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"
239 dc5351b4 2019-07-30 stsp return 1
240 dc5351b4 2019-07-30 stsp fi
241 dc5351b4 2019-07-30 stsp
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
245 dc5351b4 2019-07-30 stsp ret="$?"
246 dc5351b4 2019-07-30 stsp if [ "$ret" != "0" ]; then
247 dc5351b4 2019-07-30 stsp diff -u $testroot/stderr.expected $testroot/stderr
248 dc5351b4 2019-07-30 stsp fi
249 dc5351b4 2019-07-30 stsp test_done "$testroot" "$ret"
250 dc5351b4 2019-07-30 stsp }
251 dc5351b4 2019-07-30 stsp
252 dc5351b4 2019-07-30 stsp
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