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 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
42 if [ "$ret" != "0" ]; then
43 test_done
"$testroot" "$ret"
47 (cd $testroot/wt
&& got rebase newbranch
> /dev
/null
)
49 if [ "$ret" != "0" ]; then
50 echo "got rebase failed unexpectedly"
51 test_done
"$testroot" "$ret"
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
)
61 if [ "$ret" != "0" ]; then
62 echo "got update failed unexpectedly"
63 test_done
"$testroot" "$ret"
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
77 if [ "$ret" != "0" ]; then
78 diff -u $testroot/stdout.expected
$testroot/stdout
79 test_done
"$testroot" "$ret"
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
87 if [ "$ret" != "0" ]; then
88 diff -u $testroot/content.expected
$testroot/content
89 test_done
"$testroot" "$ret"
93 echo "modified alpha on branch" > $testroot/content.expected
94 cat $testroot/wt
/alpha
> $testroot/content
95 cmp -s $testroot/content.expected
$testroot/content
97 if [ "$ret" != "0" ]; then
98 diff -u $testroot/content.expected
$testroot/content
99 test_done
"$testroot" "$ret"
103 if [ -e $testroot/wt
/beta
]; then
104 echo "removed file beta still exists on disk" >&2
105 test_done
"$testroot" "1"
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
113 if [ "$ret" != "0" ]; then
114 diff -u $testroot/content.expected
$testroot/content
115 test_done
"$testroot" "$ret"
119 (cd $testroot/wt
&& got status
> $testroot/stdout
)
121 echo -n > $testroot/stdout.expected
122 cmp -s $testroot/stdout.expected
$testroot/stdout
124 if [ "$ret" != "0" ]; then
125 diff -u $testroot/stdout.expected
$testroot/stdout
126 test_done
"$testroot" "$ret"
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
137 if [ "$ret" != "0" ]; then
138 diff -u $testroot/stdout.expected
$testroot/stdout
139 test_done
"$testroot" "$ret"
143 (cd $testroot/wt
&& got update
> $testroot/stdout
)
144 echo "Already up-to-date" > $testroot/stdout.expected
145 cmp -s $testroot/stdout.expected
$testroot/stdout
147 if [ "$ret" != "0" ]; then
148 diff -u $testroot/stdout.expected
$testroot/stdout
150 test_done
"$testroot" "$ret"
153 test_integrate_requires_rebase_first
() {
154 local testroot
=`test_init integrate_requires_rebase_first`
155 local init_commit
=`git_show_head $testroot/repo`
157 (cd $testroot/repo
&& git checkout
-q -b newbranch
)
158 echo "modified delta on branch" > $testroot/repo
/gamma
/delta
159 git_commit
$testroot/repo
-m "committing to delta on newbranch"
161 echo "modified alpha on branch" > $testroot/repo
/alpha
162 (cd $testroot/repo
&& git
rm -q beta
)
163 echo "new file on branch" > $testroot/repo
/epsilon
/new
164 (cd $testroot/repo
&& git add epsilon
/new
)
165 git_commit
$testroot/repo
-m "committing more changes on newbranch"
167 local orig_commit1
=`git_show_parent_commit $testroot/repo`
168 local orig_commit2
=`git_show_head $testroot/repo`
170 (cd $testroot/repo
&& git checkout
-q master
)
171 echo "modified zeta on master" > $testroot/repo
/epsilon
/zeta
172 git_commit
$testroot/repo
-m "committing to zeta on master"
173 local master_commit
=`git_show_head $testroot/repo`
175 (cd $testroot/repo
&& git checkout
-q newbranch
)
176 local new_commit1
=`git_show_parent_commit $testroot/repo`
177 local new_commit2
=`git_show_head $testroot/repo`
179 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
181 if [ "$ret" != "0" ]; then
182 test_done
"$testroot" "$ret"
186 (cd $testroot/wt
&& got integrate newbranch \
187 > $testroot/stdout
2> $testroot/stderr
)
189 if [ "$ret" = "0" ]; then
190 echo "got integrate succeeded unexpectedly"
191 test_done
"$testroot" "$ret"
195 echo -n > $testroot/stdout.expected
196 cmp -s $testroot/stdout.expected
$testroot/stdout
198 if [ "$ret" != "0" ]; then
199 diff -u $testroot/stdout.expected
$testroot/stdout
200 test_done
"$testroot" "$ret"
204 echo "got: specified branch must be rebased first" \
205 > $testroot/stderr.expected
206 cmp -s $testroot/stderr.expected
$testroot/stderr
208 if [ "$ret" != "0" ]; then
209 diff -u $testroot/stderr.expected
$testroot/stderr
210 test_done
"$testroot" "$ret"
214 (cd $testroot/repo
&& got log
-c master | \
215 grep ^commit
> $testroot/stdout
)
216 echo "commit $master_commit (master)" > $testroot/stdout.expected
217 echo "commit $init_commit" >> $testroot/stdout.expected
218 cmp -s $testroot/stdout.expected
$testroot/stdout
220 if [ "$ret" != "0" ]; then
221 diff -u $testroot/stdout.expected
$testroot/stdout
222 test_done
"$testroot" "$ret"
226 (cd $testroot/repo
&& got log
-c newbranch | \
227 grep ^commit
> $testroot/stdout
)
228 echo "commit $new_commit2 (newbranch)" \
229 > $testroot/stdout.expected
230 echo "commit $new_commit1" >> $testroot/stdout.expected
231 echo "commit $init_commit" >> $testroot/stdout.expected
232 cmp -s $testroot/stdout.expected
$testroot/stdout
234 if [ "$ret" != "0" ]; then
235 diff -u $testroot/stdout.expected
$testroot/stdout
236 test_done
"$testroot" "$ret"
240 (cd $testroot/repo
&& got branch
-l > $testroot/stdout
)
242 if [ "$ret" != "0" ]; then
243 echo "got rebase failed unexpectedly"
244 test_done
"$testroot" "$ret"
248 echo " master: $master_commit" > $testroot/stdout.expected
249 echo " newbranch: $new_commit2" >> $testroot/stdout.expected
250 cmp -s $testroot/stdout.expected
$testroot/stdout
252 if [ "$ret" != "0" ]; then
253 diff -u $testroot/stdout.expected
$testroot/stdout
255 test_done
"$testroot" "$ret"
258 test_integrate_path_prefix
() {
259 local testroot
=`test_init integrate_path_prefix`
261 (cd $testroot/repo
&& git checkout
-q -b newbranch
)
262 echo "modified delta on branch" > $testroot/repo
/gamma
/delta
263 git_commit
$testroot/repo
-m "committing to delta on newbranch"
265 echo "modified alpha on branch" > $testroot/repo
/alpha
266 (cd $testroot/repo
&& git
rm -q beta
)
267 echo "new file on branch" > $testroot/repo
/epsilon
/new
268 (cd $testroot/repo
&& git add epsilon
/new
)
269 git_commit
$testroot/repo
-m "committing more changes on newbranch"
271 local orig_commit1
=`git_show_parent_commit $testroot/repo`
272 local orig_commit2
=`git_show_head $testroot/repo`
274 (cd $testroot/repo
&& git checkout
-q master
)
275 echo "modified zeta on master" > $testroot/repo
/epsilon
/zeta
276 git_commit
$testroot/repo
-m "committing to zeta on master"
277 local master_commit
=`git_show_head $testroot/repo`
279 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
281 if [ "$ret" != "0" ]; then
282 test_done
"$testroot" "$ret"
286 (cd $testroot/wt
&& got rebase newbranch
> /dev
/null
)
288 if [ "$ret" != "0" ]; then
289 echo "got rebase failed unexpectedly"
290 test_done
"$testroot" "$ret"
294 (cd $testroot/repo
&& git checkout
-q newbranch
)
295 local new_commit1
=`git_show_parent_commit $testroot/repo`
296 local new_commit2
=`git_show_head $testroot/repo`
299 got checkout
-b master
-p epsilon
$testroot/repo
$testroot/wt \
302 if [ "$ret" != "0" ]; then
303 echo "got checkout failed unexpectedly"
304 test_done
"$testroot" "$ret"
308 (cd $testroot/wt
&& got integrate newbranch
> $testroot/stdout
)
310 echo "A new" > $testroot/stdout.expected
311 echo "Integrated refs/heads/newbranch into refs/heads/master" \
312 >> $testroot/stdout.expected
313 cmp -s $testroot/stdout.expected
$testroot/stdout
315 if [ "$ret" != "0" ]; then
316 diff -u $testroot/stdout.expected
$testroot/stdout
318 test_done
"$testroot" "$ret"
321 test_integrate_backwards_in_time
() {
322 local testroot
=`test_init integrate_backwards_in_time`
324 (cd $testroot/repo
&& git checkout
-q -b newbranch
)
325 echo "modified delta on branch" > $testroot/repo
/gamma
/delta
326 git_commit
$testroot/repo
-m "committing to delta on newbranch"
328 echo "modified alpha on branch" > $testroot/repo
/alpha
329 (cd $testroot/repo
&& git
rm -q beta
)
330 echo "new file on branch" > $testroot/repo
/epsilon
/new
331 (cd $testroot/repo
&& git add epsilon
/new
)
332 git_commit
$testroot/repo
-m "committing more changes on newbranch"
334 local orig_commit1
=`git_show_parent_commit $testroot/repo`
335 local orig_commit2
=`git_show_head $testroot/repo`
337 (cd $testroot/repo
&& git checkout
-q master
)
338 echo "modified zeta on master" > $testroot/repo
/epsilon
/zeta
339 git_commit
$testroot/repo
-m "committing to zeta on master"
340 local master_commit
=`git_show_head $testroot/repo`
342 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
344 if [ "$ret" != "0" ]; then
345 test_done
"$testroot" "$ret"
349 (cd $testroot/wt
&& got rebase newbranch
> /dev
/null
)
351 if [ "$ret" != "0" ]; then
352 echo "got rebase failed unexpectedly"
353 test_done
"$testroot" "$ret"
357 (cd $testroot/repo
&& git checkout
-q newbranch
)
358 local new_commit1
=`git_show_parent_commit $testroot/repo`
359 local new_commit2
=`git_show_head $testroot/repo`
361 # attempt to integrate master into newbranch (wrong way around)
362 (cd $testroot/wt
&& got update
-b newbranch
> /dev
/null
)
364 if [ "$ret" != "0" ]; then
365 echo "got update failed unexpectedly"
366 test_done
"$testroot" "$ret"
370 (cd $testroot/wt
&& got integrate master \
371 > $testroot/stdout
2> $testroot/stderr
)
373 if [ "$ret" = "0" ]; then
374 echo "got integrate succeeded unexpectedly"
375 test_done
"$testroot" "$ret"
379 echo -n > $testroot/stdout.expected
380 cmp -s $testroot/stdout.expected
$testroot/stdout
382 if [ "$ret" != "0" ]; then
383 diff -u $testroot/stdout.expected
$testroot/stdout
384 test_done
"$testroot" "$ret"
388 echo "got: specified branch must be rebased first" \
389 > $testroot/stderr.expected
390 cmp -s $testroot/stderr.expected
$testroot/stderr
392 if [ "$ret" != "0" ]; then
393 diff -u $testroot/stderr.expected
$testroot/stderr
395 test_done
"$testroot" "$ret"
398 test_integrate_replace_symlink_with_file
() {
399 local testroot
=`test_init integrate_replace_symlink_with_file`
401 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
403 if [ "$ret" != "0" ]; then
404 echo "checkout failed unexpectedly" >&2
405 test_done
"$testroot" "$ret"
409 (cd $testroot/wt
&& ln -s alpha alpha.link
)
410 (cd $testroot/wt
&& got add alpha alpha.link
>/dev
/null
)
411 (cd $testroot/wt
&& got commit
-m "add regular file and symlink" \
414 (cd $testroot/wt
&& got br replace_symlink_with_file
>/dev
/null
)
415 (cd $testroot/wt
&& rm alpha.link
>/dev
/null
)
416 (cd $testroot/wt
&& cp alpha alpha.link
)
417 (cd $testroot/wt
&& got stage alpha.link
>/dev
/null
)
418 (cd $testroot/wt
&& got commit
-m "replace symlink" >/dev
/null
)
420 (cd $testroot/wt
&& got up
-b master
>/dev
/null
)
421 (cd $testroot/wt
&& got integrate replace_symlink_with_file \
424 echo "U alpha.link" > $testroot/stdout.expected
425 echo -n "Integrated refs/heads/replace_symlink_with_file " \
426 >> $testroot/stdout.expected
427 echo "into refs/heads/master" >> $testroot/stdout.expected
428 cmp -s $testroot/stdout.expected
$testroot/stdout
430 if [ "$ret" != "0" ]; then
431 diff -u $testroot/stdout.expected
$testroot/stdout
432 test_done
"$testroot" "$ret"
436 if [ -h $testroot/wt
/alpha.link
]; then
437 echo "alpha.link is still a symlink"
438 test_done
"$testroot" "1"
442 echo "alpha" > $testroot/content.expected
443 cat $testroot/wt
/alpha.link
> $testroot/content
445 cmp -s $testroot/content.expected
$testroot/content
447 if [ "$ret" != "0" ]; then
448 diff -u $testroot/content.expected
$testroot/content
450 test_done
"$testroot" "$ret"
453 test_integrate_replace_file_with_symlink
() {
454 local testroot
=`test_init integrate_replace_file_with_symlink`
456 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
458 if [ "$ret" != "0" ]; then
459 echo "checkout failed unexpectedly" >&2
460 test_done
"$testroot" "$ret"
464 (cd $testroot/wt
&& got br replace_file_with_symlink
>/dev
/null
)
465 (cd $testroot/wt
&& rm alpha
)
466 (cd $testroot/wt
&& ln -s beta alpha
)
467 (cd $testroot/wt
&& got commit
-m "replace regular file with symlink" \
470 (cd $testroot/wt
&& got up
-b master
>/dev
/null
)
471 (cd $testroot/wt
&& got integrate replace_file_with_symlink \
474 echo "U alpha" > $testroot/stdout.expected
475 echo -n "Integrated refs/heads/replace_file_with_symlink " \
476 >> $testroot/stdout.expected
477 echo "into refs/heads/master" >> $testroot/stdout.expected
478 cmp -s $testroot/stdout.expected
$testroot/stdout
480 if [ "$ret" != "0" ]; then
481 diff -u $testroot/stdout.expected
$testroot/stdout
482 test_done
"$testroot" "$ret"
486 if ! [ -h $testroot/wt
/alpha
]; then
487 echo "alpha is not a symlink"
488 test_done
"$testroot" "1"
492 readlink
$testroot/wt
/alpha
> $testroot/stdout
493 echo "beta" > $testroot/stdout.expected
494 cmp -s $testroot/stdout.expected
$testroot/stdout
496 if [ "$ret" != "0" ]; then
497 diff -u $testroot/stdout.expected
$testroot/stdout
499 test_done
"$testroot" "$ret"
503 run_test test_integrate_basic
504 run_test test_integrate_requires_rebase_first
505 run_test test_integrate_path_prefix
506 run_test test_integrate_backwards_in_time
507 run_test test_integrate_replace_symlink_with_file
508 run_test test_integrate_replace_file_with_symlink