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_integrate_basic {
20 local testroot=`test_init integrate_basic`
22 (cd $testroot/repo && git checkout -q -b newbranch)
23 echo "modified delta on branch" > $testroot/repo/gamma/delta
24 git_commit $testroot/repo -m "committing to delta on newbranch"
26 echo "modified alpha on branch" > $testroot/repo/alpha
27 (cd $testroot/repo && git rm -q beta)
28 echo "new file on branch" > $testroot/repo/epsilon/new
29 (cd $testroot/repo && git add epsilon/new)
30 git_commit $testroot/repo -m "committing more changes on newbranch"
32 local orig_commit1=`git_show_parent_commit $testroot/repo`
33 local orig_commit2=`git_show_head $testroot/repo`
35 (cd $testroot/repo && git checkout -q master)
36 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
37 git_commit $testroot/repo -m "committing to zeta on master"
38 local master_commit=`git_show_head $testroot/repo`
40 got checkout $testroot/repo $testroot/wt > /dev/null
41 ret="$?"
42 if [ "$ret" != "0" ]; then
43 test_done "$testroot" "$ret"
44 return 1
45 fi
47 (cd $testroot/wt && got rebase newbranch > /dev/null)
48 ret="$?"
49 if [ "$ret" != "0" ]; then
50 echo "got rebase failed unexpectedly"
51 test_done "$testroot" "$ret"
52 return 1
53 fi
55 (cd $testroot/repo && git checkout -q newbranch)
56 local new_commit1=`git_show_parent_commit $testroot/repo`
57 local new_commit2=`git_show_head $testroot/repo`
59 (cd $testroot/wt && got update -b master > /dev/null)
60 ret="$?"
61 if [ "$ret" != "0" ]; then
62 echo "got update failed unexpectedly"
63 test_done "$testroot" "$ret"
64 return 1
65 fi
67 (cd $testroot/wt && got integrate newbranch > $testroot/stdout)
69 echo "U alpha" > $testroot/stdout.expected
70 echo "D beta" >> $testroot/stdout.expected
71 echo "A epsilon/new" >> $testroot/stdout.expected
72 echo "U gamma/delta" >> $testroot/stdout.expected
73 echo "Integrated refs/heads/newbranch into refs/heads/master" \
74 >> $testroot/stdout.expected
75 cmp -s $testroot/stdout.expected $testroot/stdout
76 ret="$?"
77 if [ "$ret" != "0" ]; then
78 diff -u $testroot/stdout.expected $testroot/stdout
79 test_done "$testroot" "$ret"
80 return 1
81 fi
83 echo "modified delta on branch" > $testroot/content.expected
84 cat $testroot/wt/gamma/delta > $testroot/content
85 cmp -s $testroot/content.expected $testroot/content
86 ret="$?"
87 if [ "$ret" != "0" ]; then
88 diff -u $testroot/content.expected $testroot/content
89 test_done "$testroot" "$ret"
90 return 1
91 fi
93 echo "modified alpha on branch" > $testroot/content.expected
94 cat $testroot/wt/alpha > $testroot/content
95 cmp -s $testroot/content.expected $testroot/content
96 ret="$?"
97 if [ "$ret" != "0" ]; then
98 diff -u $testroot/content.expected $testroot/content
99 test_done "$testroot" "$ret"
100 return 1
101 fi
103 if [ -e $testroot/wt/beta ]; then
104 echo "removed file beta still exists on disk" >&2
105 test_done "$testroot" "1"
106 return 1
107 fi
109 echo "new file on branch" > $testroot/content.expected
110 cat $testroot/wt/epsilon/new > $testroot/content
111 cmp -s $testroot/content.expected $testroot/content
112 ret="$?"
113 if [ "$ret" != "0" ]; then
114 diff -u $testroot/content.expected $testroot/content
115 test_done "$testroot" "$ret"
116 return 1
117 fi
119 (cd $testroot/wt && got status > $testroot/stdout)
121 echo -n > $testroot/stdout.expected
122 cmp -s $testroot/stdout.expected $testroot/stdout
123 ret="$?"
124 if [ "$ret" != "0" ]; then
125 diff -u $testroot/stdout.expected $testroot/stdout
126 test_done "$testroot" "$ret"
127 return 1
128 fi
130 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
131 echo "commit $new_commit2 (master, newbranch)" \
132 > $testroot/stdout.expected
133 echo "commit $new_commit1" >> $testroot/stdout.expected
134 echo "commit $master_commit" >> $testroot/stdout.expected
135 cmp -s $testroot/stdout.expected $testroot/stdout
136 ret="$?"
137 if [ "$ret" != "0" ]; then
138 diff -u $testroot/stdout.expected $testroot/stdout
139 fi
140 test_done "$testroot" "$ret"
143 function test_integrate_requires_rebase_first {
144 local testroot=`test_init integrate_requires_rebase_first`
145 local init_commit=`git_show_head $testroot/repo`
147 (cd $testroot/repo && git checkout -q -b newbranch)
148 echo "modified delta on branch" > $testroot/repo/gamma/delta
149 git_commit $testroot/repo -m "committing to delta on newbranch"
151 echo "modified alpha on branch" > $testroot/repo/alpha
152 (cd $testroot/repo && git rm -q beta)
153 echo "new file on branch" > $testroot/repo/epsilon/new
154 (cd $testroot/repo && git add epsilon/new)
155 git_commit $testroot/repo -m "committing more changes on newbranch"
157 local orig_commit1=`git_show_parent_commit $testroot/repo`
158 local orig_commit2=`git_show_head $testroot/repo`
160 (cd $testroot/repo && git checkout -q master)
161 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
162 git_commit $testroot/repo -m "committing to zeta on master"
163 local master_commit=`git_show_head $testroot/repo`
165 (cd $testroot/repo && git checkout -q newbranch)
166 local new_commit1=`git_show_parent_commit $testroot/repo`
167 local new_commit2=`git_show_head $testroot/repo`
169 got checkout -b master $testroot/repo $testroot/wt > /dev/null
170 ret="$?"
171 if [ "$ret" != "0" ]; then
172 test_done "$testroot" "$ret"
173 return 1
174 fi
176 (cd $testroot/wt && got integrate newbranch \
177 > $testroot/stdout 2> $testroot/stderr)
178 ret="$?"
179 if [ "$ret" == "0" ]; then
180 echo "got integrate succeeded unexpectedly"
181 test_done "$testroot" "$ret"
182 return 1
183 fi
185 echo -n > $testroot/stdout.expected
186 cmp -s $testroot/stdout.expected $testroot/stdout
187 ret="$?"
188 if [ "$ret" != "0" ]; then
189 diff -u $testroot/stdout.expected $testroot/stdout
190 test_done "$testroot" "$ret"
191 return 1
192 fi
194 echo "got: specified branch must be rebased first" \
195 > $testroot/stderr.expected
196 cmp -s $testroot/stderr.expected $testroot/stderr
197 ret="$?"
198 if [ "$ret" != "0" ]; then
199 diff -u $testroot/stderr.expected $testroot/stderr
200 test_done "$testroot" "$ret"
201 return 1
202 fi
204 (cd $testroot/repo && got log -c master | \
205 grep ^commit > $testroot/stdout)
206 echo "commit $master_commit (master)" > $testroot/stdout.expected
207 echo "commit $init_commit" >> $testroot/stdout.expected
208 cmp -s $testroot/stdout.expected $testroot/stdout
209 ret="$?"
210 if [ "$ret" != "0" ]; then
211 diff -u $testroot/stdout.expected $testroot/stdout
212 test_done "$testroot" "$ret"
213 return 1
214 fi
216 (cd $testroot/repo && got log -c newbranch | \
217 grep ^commit > $testroot/stdout)
218 echo "commit $new_commit2 (newbranch)" \
219 > $testroot/stdout.expected
220 echo "commit $new_commit1" >> $testroot/stdout.expected
221 echo "commit $init_commit" >> $testroot/stdout.expected
222 cmp -s $testroot/stdout.expected $testroot/stdout
223 ret="$?"
224 if [ "$ret" != "0" ]; then
225 diff -u $testroot/stdout.expected $testroot/stdout
226 test_done "$testroot" "$ret"
227 return 1
228 fi
230 (cd $testroot/repo && got branch -l > $testroot/stdout)
231 ret="$?"
232 if [ "$ret" != "0" ]; then
233 echo "got rebase failed unexpectedly"
234 test_done "$testroot" "$ret"
235 return 1
236 fi
238 echo " master: $master_commit" > $testroot/stdout.expected
239 echo " newbranch: $new_commit2" >> $testroot/stdout.expected
240 cmp -s $testroot/stdout.expected $testroot/stdout
241 ret="$?"
242 if [ "$ret" != "0" ]; then
243 diff -u $testroot/stdout.expected $testroot/stdout
244 fi
245 test_done "$testroot" "$ret"
248 function test_integrate_path_prefix {
249 local testroot=`test_init integrate_path_prefix`
251 (cd $testroot/repo && git checkout -q -b newbranch)
252 echo "modified delta on branch" > $testroot/repo/gamma/delta
253 git_commit $testroot/repo -m "committing to delta on newbranch"
255 echo "modified alpha on branch" > $testroot/repo/alpha
256 (cd $testroot/repo && git rm -q beta)
257 echo "new file on branch" > $testroot/repo/epsilon/new
258 (cd $testroot/repo && git add epsilon/new)
259 git_commit $testroot/repo -m "committing more changes on newbranch"
261 local orig_commit1=`git_show_parent_commit $testroot/repo`
262 local orig_commit2=`git_show_head $testroot/repo`
264 (cd $testroot/repo && git checkout -q master)
265 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
266 git_commit $testroot/repo -m "committing to zeta on master"
267 local master_commit=`git_show_head $testroot/repo`
269 got checkout $testroot/repo $testroot/wt > /dev/null
270 ret="$?"
271 if [ "$ret" != "0" ]; then
272 test_done "$testroot" "$ret"
273 return 1
274 fi
276 (cd $testroot/wt && got rebase newbranch > /dev/null)
277 ret="$?"
278 if [ "$ret" != "0" ]; then
279 echo "got rebase failed unexpectedly"
280 test_done "$testroot" "$ret"
281 return 1
282 fi
284 (cd $testroot/repo && git checkout -q newbranch)
285 local new_commit1=`git_show_parent_commit $testroot/repo`
286 local new_commit2=`git_show_head $testroot/repo`
288 rm -r $testroot/wt
289 got checkout -b master -p epsilon $testroot/repo $testroot/wt \
290 > /dev/null
291 ret="$?"
292 if [ "$ret" != "0" ]; then
293 echo "got checkout failed unexpectedly"
294 test_done "$testroot" "$ret"
295 return 1
296 fi
298 (cd $testroot/wt && got integrate newbranch > $testroot/stdout)
300 echo "A new" > $testroot/stdout.expected
301 echo "Integrated refs/heads/newbranch into refs/heads/master" \
302 >> $testroot/stdout.expected
303 cmp -s $testroot/stdout.expected $testroot/stdout
304 ret="$?"
305 if [ "$ret" != "0" ]; then
306 diff -u $testroot/stdout.expected $testroot/stdout
307 fi
308 test_done "$testroot" "$ret"
311 function test_integrate_backwards_in_time {
312 local testroot=`test_init integrate_backwards_in_time`
314 (cd $testroot/repo && git checkout -q -b newbranch)
315 echo "modified delta on branch" > $testroot/repo/gamma/delta
316 git_commit $testroot/repo -m "committing to delta on newbranch"
318 echo "modified alpha on branch" > $testroot/repo/alpha
319 (cd $testroot/repo && git rm -q beta)
320 echo "new file on branch" > $testroot/repo/epsilon/new
321 (cd $testroot/repo && git add epsilon/new)
322 git_commit $testroot/repo -m "committing more changes on newbranch"
324 local orig_commit1=`git_show_parent_commit $testroot/repo`
325 local orig_commit2=`git_show_head $testroot/repo`
327 (cd $testroot/repo && git checkout -q master)
328 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
329 git_commit $testroot/repo -m "committing to zeta on master"
330 local master_commit=`git_show_head $testroot/repo`
332 got checkout $testroot/repo $testroot/wt > /dev/null
333 ret="$?"
334 if [ "$ret" != "0" ]; then
335 test_done "$testroot" "$ret"
336 return 1
337 fi
339 (cd $testroot/wt && got rebase newbranch > /dev/null)
340 ret="$?"
341 if [ "$ret" != "0" ]; then
342 echo "got rebase failed unexpectedly"
343 test_done "$testroot" "$ret"
344 return 1
345 fi
347 (cd $testroot/repo && git checkout -q newbranch)
348 local new_commit1=`git_show_parent_commit $testroot/repo`
349 local new_commit2=`git_show_head $testroot/repo`
351 # attempt to integrate master into newbranch (wrong way around)
352 (cd $testroot/wt && got update -b newbranch > /dev/null)
353 ret="$?"
354 if [ "$ret" != "0" ]; then
355 echo "got update failed unexpectedly"
356 test_done "$testroot" "$ret"
357 return 1
358 fi
360 (cd $testroot/wt && got integrate master \
361 > $testroot/stdout 2> $testroot/stderr)
362 ret="$?"
363 if [ "$ret" == "0" ]; then
364 echo "got integrate succeeded unexpectedly"
365 test_done "$testroot" "$ret"
366 return 1
367 fi
369 echo -n > $testroot/stdout.expected
370 cmp -s $testroot/stdout.expected $testroot/stdout
371 ret="$?"
372 if [ "$ret" != "0" ]; then
373 diff -u $testroot/stdout.expected $testroot/stdout
374 test_done "$testroot" "$ret"
375 return 1
376 fi
378 echo "got: specified branch must be rebased first" \
379 > $testroot/stderr.expected
380 cmp -s $testroot/stderr.expected $testroot/stderr
381 ret="$?"
382 if [ "$ret" != "0" ]; then
383 diff -u $testroot/stderr.expected $testroot/stderr
384 fi
385 test_done "$testroot" "$ret"
388 run_test test_integrate_basic
389 run_test test_integrate_requires_rebase_first
390 run_test test_integrate_path_prefix
391 run_test test_integrate_backwards_in_time