portable: release 0.93
[got-portable.git] / regress / cmdline / integrate.sh
blobfea0fbd0c0b880d3f283fc17453e349290b0a480
1 #!/bin/sh
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.
17 . ./common.sh
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
41 ret=$?
42 if [ $ret -ne 0 ]; then
43 test_done "$testroot" "$ret"
44 return 1
47 (cd $testroot/wt && got rebase newbranch > /dev/null)
48 ret=$?
49 if [ $ret -ne 0 ]; then
50 echo "got rebase failed unexpectedly"
51 test_done "$testroot" "$ret"
52 return 1
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 -ne 0 ]; then
62 echo "got update failed unexpectedly"
63 test_done "$testroot" "$ret"
64 return 1
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 -ne 0 ]; then
78 diff -u $testroot/stdout.expected $testroot/stdout
79 test_done "$testroot" "$ret"
80 return 1
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 -ne 0 ]; then
88 diff -u $testroot/content.expected $testroot/content
89 test_done "$testroot" "$ret"
90 return 1
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 -ne 0 ]; then
98 diff -u $testroot/content.expected $testroot/content
99 test_done "$testroot" "$ret"
100 return 1
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
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 -ne 0 ]; then
114 diff -u $testroot/content.expected $testroot/content
115 test_done "$testroot" "$ret"
116 return 1
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 -ne 0 ]; then
125 diff -u $testroot/stdout.expected $testroot/stdout
126 test_done "$testroot" "$ret"
127 return 1
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 -ne 0 ]; then
138 diff -u $testroot/stdout.expected $testroot/stdout
139 test_done "$testroot" "$ret"
140 return 1
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
146 ret=$?
147 if [ $ret -ne 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
180 ret=$?
181 if [ $ret -ne 0 ]; then
182 test_done "$testroot" "$ret"
183 return 1
186 (cd $testroot/wt && got integrate newbranch \
187 > $testroot/stdout 2> $testroot/stderr)
188 ret=$?
189 if [ $ret -eq 0 ]; then
190 echo "got integrate succeeded unexpectedly"
191 test_done "$testroot" "1"
192 return 1
195 echo -n > $testroot/stdout.expected
196 cmp -s $testroot/stdout.expected $testroot/stdout
197 ret=$?
198 if [ $ret -ne 0 ]; then
199 diff -u $testroot/stdout.expected $testroot/stdout
200 test_done "$testroot" "$ret"
201 return 1
204 echo "got: specified branch must be rebased first" \
205 > $testroot/stderr.expected
206 cmp -s $testroot/stderr.expected $testroot/stderr
207 ret=$?
208 if [ $ret -ne 0 ]; then
209 diff -u $testroot/stderr.expected $testroot/stderr
210 test_done "$testroot" "$ret"
211 return 1
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
219 ret=$?
220 if [ $ret -ne 0 ]; then
221 diff -u $testroot/stdout.expected $testroot/stdout
222 test_done "$testroot" "$ret"
223 return 1
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
233 ret=$?
234 if [ $ret -ne 0 ]; then
235 diff -u $testroot/stdout.expected $testroot/stdout
236 test_done "$testroot" "$ret"
237 return 1
240 (cd $testroot/repo && got branch -l > $testroot/stdout)
241 ret=$?
242 if [ $ret -ne 0 ]; then
243 echo "got rebase failed unexpectedly"
244 test_done "$testroot" "$ret"
245 return 1
248 echo " master: $master_commit" > $testroot/stdout.expected
249 echo " newbranch: $new_commit2" >> $testroot/stdout.expected
250 cmp -s $testroot/stdout.expected $testroot/stdout
251 ret=$?
252 if [ $ret -ne 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
280 ret=$?
281 if [ $ret -ne 0 ]; then
282 test_done "$testroot" "$ret"
283 return 1
286 (cd $testroot/wt && got rebase newbranch > /dev/null)
287 ret=$?
288 if [ $ret -ne 0 ]; then
289 echo "got rebase failed unexpectedly"
290 test_done "$testroot" "$ret"
291 return 1
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`
298 rm -r $testroot/wt
299 got checkout -b master -p epsilon $testroot/repo $testroot/wt \
300 > /dev/null
301 ret=$?
302 if [ $ret -ne 0 ]; then
303 echo "got checkout failed unexpectedly"
304 test_done "$testroot" "$ret"
305 return 1
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
314 ret=$?
315 if [ $ret -ne 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
343 ret=$?
344 if [ $ret -ne 0 ]; then
345 test_done "$testroot" "$ret"
346 return 1
349 (cd $testroot/wt && got rebase newbranch > /dev/null)
350 ret=$?
351 if [ $ret -ne 0 ]; then
352 echo "got rebase failed unexpectedly"
353 test_done "$testroot" "$ret"
354 return 1
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)
363 ret=$?
364 if [ $ret -ne 0 ]; then
365 echo "got update failed unexpectedly"
366 test_done "$testroot" "$ret"
367 return 1
370 (cd $testroot/wt && got integrate master \
371 > $testroot/stdout 2> $testroot/stderr)
372 ret=$?
373 if [ $ret -eq 0 ]; then
374 echo "got integrate succeeded unexpectedly"
375 test_done "$testroot" "1"
376 return 1
379 echo -n > $testroot/stdout.expected
380 cmp -s $testroot/stdout.expected $testroot/stdout
381 ret=$?
382 if [ $ret -ne 0 ]; then
383 diff -u $testroot/stdout.expected $testroot/stdout
384 test_done "$testroot" "$ret"
385 return 1
388 echo "got: specified branch must be rebased first" \
389 > $testroot/stderr.expected
390 cmp -s $testroot/stderr.expected $testroot/stderr
391 ret=$?
392 if [ $ret -ne 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
402 ret=$?
403 if [ $ret -ne 0 ]; then
404 echo "checkout failed unexpectedly" >&2
405 test_done "$testroot" "$ret"
406 return 1
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" \
412 >/dev/null)
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 \
422 > $testroot/stdout)
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
429 ret=$?
430 if [ $ret -ne 0 ]; then
431 diff -u $testroot/stdout.expected $testroot/stdout
432 test_done "$testroot" "$ret"
433 return 1
436 if [ -h $testroot/wt/alpha.link ]; then
437 echo "alpha.link is still a symlink"
438 test_done "$testroot" "1"
439 return 1
442 echo "alpha" > $testroot/content.expected
443 cat $testroot/wt/alpha.link > $testroot/content
445 cmp -s $testroot/content.expected $testroot/content
446 ret=$?
447 if [ $ret -ne 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
457 ret=$?
458 if [ $ret -ne 0 ]; then
459 echo "checkout failed unexpectedly" >&2
460 test_done "$testroot" "$ret"
461 return 1
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" \
468 >/dev/null)
470 (cd $testroot/wt && got up -b master >/dev/null)
471 (cd $testroot/wt && got integrate replace_file_with_symlink \
472 > $testroot/stdout)
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
479 ret=$?
480 if [ $ret -ne 0 ]; then
481 diff -u $testroot/stdout.expected $testroot/stdout
482 test_done "$testroot" "$ret"
483 return 1
486 if ! [ -h $testroot/wt/alpha ]; then
487 echo "alpha is not a symlink"
488 test_done "$testroot" "1"
489 return 1
492 readlink $testroot/wt/alpha > $testroot/stdout
493 echo "beta" > $testroot/stdout.expected
494 cmp -s $testroot/stdout.expected $testroot/stdout
495 ret=$?
496 if [ $ret -ne 0 ]; then
497 diff -u $testroot/stdout.expected $testroot/stdout
499 test_done "$testroot" "$ret"
502 test_integrate_into_nonbranch() {
503 local testroot=`test_init test_integrate_into_nonbranch`
505 got checkout $testroot/repo $testroot/wt > /dev/null
506 ret=$?
507 if [ $ret -ne 0 ]; then
508 echo "checkout failed unexpectedly" >&2
509 test_done "$testroot" "$ret"
510 return 1
513 local commit=`git_show_head $testroot/repo`
514 (cd $testroot/repo && got ref -c $commit refs/remotes/origin/master)
516 echo "modified alpha on branch" > $testroot/repo/alpha
517 git_commit $testroot/repo -m "committing to alpha on master"
519 (cd $testroot/wt && got up -b origin/master > /dev/null)
520 ret=$?
521 if [ $ret -ne 0 ]; then
522 echo "got branch failed unexpectedly"
523 test_done "$testroot" "$ret"
524 return 1
527 (cd $testroot/wt && got integrate master \
528 > $testroot/stdout 2> $testroot/stderr)
529 ret=$?
530 if [ $ret -eq 0 ]; then
531 echo "got integrate succeeded unexpectedly"
532 test_done "$testroot" "1"
533 return 1
536 echo -n "got: will not integrate into a reference outside the " \
537 > $testroot/stderr.expected
538 echo "\"refs/heads/\" reference namespace" >> $testroot/stderr.expected
539 cmp -s $testroot/stderr.expected $testroot/stderr
540 ret=$?
541 if [ $ret -ne 0 ]; then
542 diff -u $testroot/stderr.expected $testroot/stderr
544 test_done "$testroot" "$ret"
547 test_parseargs "$@"
548 run_test test_integrate_basic
549 run_test test_integrate_requires_rebase_first
550 run_test test_integrate_path_prefix
551 run_test test_integrate_backwards_in_time
552 run_test test_integrate_replace_symlink_with_file
553 run_test test_integrate_replace_file_with_symlink
554 run_test test_integrate_into_nonbranch