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_cherrypick_basic {
20 local testroot=`test_init cherrypick_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret="$?"
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
29 (cd $testroot/repo && git checkout -q -b newbranch)
30 echo "modified delta on branch" > $testroot/repo/gamma/delta
31 git_commit $testroot/repo -m "committing to delta on newbranch"
33 echo "modified alpha on branch" > $testroot/repo/alpha
34 (cd $testroot/repo && git rm -q beta)
35 echo "new file on branch" > $testroot/repo/epsilon/new
36 (cd $testroot/repo && git add epsilon/new)
37 git_commit $testroot/repo -m "committing more changes on newbranch"
39 local branch_rev=`git_show_head $testroot/repo`
41 (cd $testroot/wt && got cherrypick $branch_rev > $testroot/stdout)
43 echo "G alpha" > $testroot/stdout.expected
44 echo "D beta" >> $testroot/stdout.expected
45 echo "A epsilon/new" >> $testroot/stdout.expected
46 echo "Merged commit $branch_rev" >> $testroot/stdout.expected
48 cmp -s $testroot/stdout.expected $testroot/stdout
49 ret="$?"
50 if [ "$ret" != "0" ]; then
51 diff -u $testroot/stdout.expected $testroot/stdout
52 test_done "$testroot" "$ret"
53 return 1
54 fi
56 echo "modified alpha on branch" > $testroot/content.expected
57 cat $testroot/wt/alpha > $testroot/content
58 cmp -s $testroot/content.expected $testroot/content
59 ret="$?"
60 if [ "$ret" != "0" ]; then
61 diff -u $testroot/content.expected $testroot/content
62 test_done "$testroot" "$ret"
63 return 1
64 fi
66 if [ -e $testroot/wt/beta ]; then
67 echo "removed file beta still exists on disk" >&2
68 test_done "$testroot" "1"
69 return 1
70 fi
72 echo "new file on branch" > $testroot/content.expected
73 cat $testroot/wt/epsilon/new > $testroot/content
74 cmp -s $testroot/content.expected $testroot/content
75 ret="$?"
76 if [ "$ret" != "0" ]; then
77 diff -u $testroot/content.expected $testroot/content
78 test_done "$testroot" "$ret"
79 return 1
80 fi
82 echo 'M alpha' > $testroot/stdout.expected
83 echo 'D beta' >> $testroot/stdout.expected
84 echo 'A epsilon/new' >> $testroot/stdout.expected
86 (cd $testroot/wt && got status > $testroot/stdout)
88 cmp -s $testroot/stdout.expected $testroot/stdout
89 ret="$?"
90 if [ "$ret" != "0" ]; then
91 diff -u $testroot/stdout.expected $testroot/stdout
92 fi
93 test_done "$testroot" "$ret"
94 }
96 function test_cherrypick_root_commit {
97 local testroot=`test_init cherrypick_root_commit`
99 got checkout $testroot/repo $testroot/wt > /dev/null
100 ret="$?"
101 if [ "$ret" != "0" ]; then
102 test_done "$testroot" "$ret"
103 return 1
104 fi
106 (cd $testroot/repo && git checkout -q -b newbranch)
107 (cd $testroot/repo && git rm -q alpha)
108 (cd $testroot/repo && git rm -q beta)
109 (cd $testroot/repo && git rm -q epsilon/zeta)
110 (cd $testroot/repo && git rm -q gamma/delta)
111 mkdir -p $testroot/repo/epsilon
112 echo "new file on branch" > $testroot/repo/epsilon/new
113 (cd $testroot/repo && git add epsilon/new)
114 git_commit $testroot/repo -m "committing on newbranch"
116 echo "modified new file on branch" >> $testroot/repo/epsilon/new
117 git_commit $testroot/repo -m "committing on newbranch again"
119 tree=`git_show_tree $testroot/repo`
120 root_commit=`git_commit_tree $testroot/repo "new root commit" $tree`
122 (cd $testroot/wt && got cherrypick $root_commit > $testroot/stdout)
124 echo "A epsilon/new" > $testroot/stdout.expected
125 echo "Merged commit $root_commit" >> $testroot/stdout.expected
127 cmp -s $testroot/stdout.expected $testroot/stdout
128 ret="$?"
129 if [ "$ret" != "0" ]; then
130 diff -u $testroot/stdout.expected $testroot/stdout
131 test_done "$testroot" "$ret"
132 return 1
133 fi
135 echo "new file on branch" > $testroot/content.expected
136 echo "modified new file on branch" >> $testroot/content.expected
137 cat $testroot/wt/epsilon/new > $testroot/content
138 cmp -s $testroot/content.expected $testroot/content
139 ret="$?"
140 if [ "$ret" != "0" ]; then
141 diff -u $testroot/content.expected $testroot/content
142 test_done "$testroot" "$ret"
143 return 1
144 fi
146 echo 'A epsilon/new' > $testroot/stdout.expected
148 (cd $testroot/wt && got status > $testroot/stdout)
150 cmp -s $testroot/stdout.expected $testroot/stdout
151 ret="$?"
152 if [ "$ret" != "0" ]; then
153 diff -u $testroot/stdout.expected $testroot/stdout
154 fi
155 test_done "$testroot" "$ret"
158 function test_cherrypick_into_work_tree_with_conflicts {
159 local testroot=`test_init cherrypick_into_work_tree_with_conflicts`
161 got checkout $testroot/repo $testroot/wt > /dev/null
162 ret="$?"
163 if [ "$ret" != "0" ]; then
164 test_done "$testroot" "$ret"
165 return 1
166 fi
168 (cd $testroot/repo && git checkout -q -b newbranch)
169 echo "modified delta on branch" > $testroot/repo/gamma/delta
170 git_commit $testroot/repo -m "committing to delta on newbranch"
172 echo "modified alpha on branch" > $testroot/repo/alpha
173 (cd $testroot/repo && git rm -q beta)
174 echo "new file on branch" > $testroot/repo/epsilon/new
175 (cd $testroot/repo && git add epsilon/new)
176 git_commit $testroot/repo -m "committing more changes on newbranch"
178 local branch_rev=`git_show_head $testroot/repo`
180 # fake a merge conflict
181 echo '<<<<<<<' > $testroot/wt/alpha
182 echo 'alpha' >> $testroot/wt/alpha
183 echo '=======' >> $testroot/wt/alpha
184 echo 'alpha, too' >> $testroot/wt/alpha
185 echo '>>>>>>>' >> $testroot/wt/alpha
186 cp $testroot/wt/alpha $testroot/content.expected
188 echo "C alpha" > $testroot/stdout.expected
189 (cd $testroot/wt && got status > $testroot/stdout)
190 cmp -s $testroot/stdout.expected $testroot/stdout
191 ret="$?"
192 if [ "$ret" != "0" ]; then
193 diff -u $testroot/stdout.expected $testroot/stdout
194 test_done "$testroot" "$ret"
195 return 1
196 fi
198 (cd $testroot/wt && got cherrypick $branch_rev \
199 > $testroot/stdout 2> $testroot/stderr)
200 ret="$?"
201 if [ "$ret" == "0" ]; then
202 echo "cherrypick succeeded unexpectedly" >&2
203 test_done "$testroot" "1"
204 return 1
205 fi
207 echo -n > $testroot/stdout.expected
208 echo -n "got: work tree contains conflicted files; " \
209 > $testroot/stderr.expected
210 echo "these conflicts must be resolved first" \
211 >> $testroot/stderr.expected
213 cmp -s $testroot/stdout.expected $testroot/stdout
214 ret="$?"
215 if [ "$ret" != "0" ]; then
216 diff -u $testroot/stdout.expected $testroot/stdout
217 test_done "$testroot" "$ret"
218 return 1
219 fi
221 cmp -s $testroot/stderr.expected $testroot/stderr
222 ret="$?"
223 if [ "$ret" != "0" ]; then
224 diff -u $testroot/stderr.expected $testroot/stderr
225 test_done "$testroot" "$ret"
226 return 1
227 fi
229 cmp -s $testroot/content.expected $testroot/wt/alpha
230 ret="$?"
231 if [ "$ret" != "0" ]; then
232 diff -u $testroot/content.expected $testroot/wt/alpha
233 fi
234 test_done "$testroot" "$ret"
237 function test_cherrypick_modified_submodule {
238 local testroot=`test_init cherrypick_modified_submodules`
240 make_single_file_repo $testroot/repo2 foo
242 (cd $testroot/repo && git submodule -q add ../repo2)
243 (cd $testroot/repo && git commit -q -m 'adding submodule')
245 got checkout $testroot/repo $testroot/wt > /dev/null
247 echo "modified foo" > $testroot/repo2/foo
248 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
250 (cd $testroot/repo && git checkout -q -b newbranch)
251 # Update the repo/repo2 submodule link on newbranch
252 (cd $testroot/repo && git -C repo2 pull -q)
253 (cd $testroot/repo && git add repo2)
254 git_commit $testroot/repo -m "modified submodule link"
255 local commit_id=`git_show_head $testroot/repo`
257 # This cherrypick is a no-op because Got's file index
258 # does not track submodules.
259 (cd $testroot/wt && got cherrypick $commit_id > $testroot/stdout)
261 echo -n > $testroot/stdout.expected
262 cmp -s $testroot/stdout.expected $testroot/stdout
263 ret="$?"
264 if [ "$ret" != "0" ]; then
265 diff -u $testroot/stdout.expected $testroot/stdout
266 fi
267 test_done "$testroot" "$ret"
270 function test_cherrypick_added_submodule {
271 local testroot=`test_init cherrypick_added_submodules`
273 got checkout $testroot/repo $testroot/wt > /dev/null
275 make_single_file_repo $testroot/repo2 foo
277 # Add the repo/repo2 submodule on newbranch
278 (cd $testroot/repo && git checkout -q -b newbranch)
279 (cd $testroot/repo && git submodule -q add ../repo2)
280 (cd $testroot/repo && git commit -q -m 'adding submodule')
281 local commit_id=`git_show_head $testroot/repo`
283 (cd $testroot/wt && got cherrypick $commit_id > $testroot/stdout)
285 echo "A .gitmodules" > $testroot/stdout.expected
286 echo "Merged commit $commit_id" >> $testroot/stdout.expected
287 cmp -s $testroot/stdout.expected $testroot/stdout
288 ret="$?"
289 if [ "$ret" != "0" ]; then
290 diff -u $testroot/stdout.expected $testroot/stdout
291 fi
292 test_done "$testroot" "$ret"
295 function test_cherrypick_conflict_wt_file_vs_repo_submodule {
296 local testroot=`test_init cherrypick_conflict_wt_file_vs_repo_submodule`
298 got checkout $testroot/repo $testroot/wt > /dev/null
300 # Add a file which will clash with the submodule
301 echo "This is a file called repo2" > $testroot/wt/repo2
302 (cd $testroot/wt && got add repo2 > /dev/null)
303 (cd $testroot/wt && got commit -m 'add file repo2' > /dev/null)
304 ret="$?"
305 if [ "$ret" != "0" ]; then
306 echo "commit failed unexpectedly" >&2
307 test_done "$testroot" "1"
308 return 1
309 fi
311 make_single_file_repo $testroot/repo2 foo
313 # Add the repo/repo2 submodule on newbranch
314 (cd $testroot/repo && git checkout -q -b newbranch)
315 (cd $testroot/repo && git submodule -q add ../repo2)
316 (cd $testroot/repo && git commit -q -m 'adding submodule')
317 local commit_id=`git_show_head $testroot/repo`
319 # Modify the clashing file such that any modifications brought
320 # in by 'got cherrypick' would require a merge.
321 echo "This file was changed" > $testroot/wt/repo2
323 (cd $testroot/wt && got update >/dev/null)
324 (cd $testroot/wt && got cherrypick $commit_id > $testroot/stdout)
326 echo "A .gitmodules" > $testroot/stdout.expected
327 echo "Merged commit $commit_id" >> $testroot/stdout.expected
328 cmp -s $testroot/stdout.expected $testroot/stdout
329 ret="$?"
330 if [ "$ret" != "0" ]; then
331 diff -u $testroot/stdout.expected $testroot/stdout
332 test_done "$testroot" "$ret"
333 return 1
334 fi
336 (cd $testroot/wt && got status > $testroot/stdout)
338 echo "A .gitmodules" > $testroot/stdout.expected
339 echo "M repo2" >> $testroot/stdout.expected
340 cmp -s $testroot/stdout.expected $testroot/stdout
341 ret="$?"
342 if [ "$ret" != "0" ]; then
343 diff -u $testroot/stdout.expected $testroot/stdout
344 fi
345 test_done "$testroot" "$ret"
348 function test_cherrypick_modified_symlinks {
349 local testroot=`test_init cherrypick_modified_symlinks`
351 (cd $testroot/repo && ln -s alpha alpha.link)
352 (cd $testroot/repo && ln -s epsilon epsilon.link)
353 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
354 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
355 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
356 (cd $testroot/repo && git add .)
357 git_commit $testroot/repo -m "add symlinks"
358 local commit_id1=`git_show_head $testroot/repo`
360 got branch -r $testroot/repo foo
362 got checkout -b foo $testroot/repo $testroot/wt > /dev/null
364 (cd $testroot/repo && ln -sf beta alpha.link)
365 (cd $testroot/repo && ln -sfh gamma epsilon.link)
366 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
367 (cd $testroot/repo && ln -sf .got/bar $testroot/repo/dotgotfoo.link)
368 (cd $testroot/repo && git rm -q nonexistent.link)
369 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
370 (cd $testroot/repo && git add .)
371 git_commit $testroot/repo -m "change symlinks"
372 local commit_id2=`git_show_head $testroot/repo`
374 (cd $testroot/wt && got cherrypick $commit_id2 > $testroot/stdout)
376 echo "G alpha.link" > $testroot/stdout.expected
377 echo "G epsilon/beta.link" >> $testroot/stdout.expected
378 echo "A dotgotfoo.link" >> $testroot/stdout.expected
379 echo "G epsilon.link" >> $testroot/stdout.expected
380 echo "D nonexistent.link" >> $testroot/stdout.expected
381 echo "A zeta.link" >> $testroot/stdout.expected
382 echo "Merged commit $commit_id2" >> $testroot/stdout.expected
383 cmp -s $testroot/stdout.expected $testroot/stdout
384 ret="$?"
385 if [ "$ret" != "0" ]; then
386 diff -u $testroot/stdout.expected $testroot/stdout
387 test_done "$testroot" "$ret"
388 return 1
389 fi
391 if ! [ -h $testroot/wt/alpha.link ]; then
392 echo "alpha.link is not a symlink"
393 test_done "$testroot" "1"
394 return 1
395 fi
397 readlink $testroot/wt/alpha.link > $testroot/stdout
398 echo "beta" > $testroot/stdout.expected
399 cmp -s $testroot/stdout.expected $testroot/stdout
400 ret="$?"
401 if [ "$ret" != "0" ]; then
402 diff -u $testroot/stdout.expected $testroot/stdout
403 test_done "$testroot" "$ret"
404 return 1
405 fi
407 if ! [ -h $testroot/wt/epsilon.link ]; then
408 echo "epsilon.link is not a symlink"
409 test_done "$testroot" "1"
410 return 1
411 fi
413 readlink $testroot/wt/epsilon.link > $testroot/stdout
414 echo "gamma" > $testroot/stdout.expected
415 cmp -s $testroot/stdout.expected $testroot/stdout
416 ret="$?"
417 if [ "$ret" != "0" ]; then
418 diff -u $testroot/stdout.expected $testroot/stdout
419 test_done "$testroot" "$ret"
420 return 1
421 fi
423 if [ -h $testroot/wt/passwd.link ]; then
424 echo -n "passwd.link symlink points outside of work tree: " >&2
425 readlink $testroot/wt/passwd.link >&2
426 test_done "$testroot" "1"
427 return 1
428 fi
430 echo -n "/etc/passwd" > $testroot/content.expected
431 cp $testroot/wt/passwd.link $testroot/content
433 cmp -s $testroot/content.expected $testroot/content
434 ret="$?"
435 if [ "$ret" != "0" ]; then
436 diff -u $testroot/content.expected $testroot/content
437 test_done "$testroot" "$ret"
438 return 1
439 fi
441 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
442 echo "../gamma/delta" > $testroot/stdout.expected
443 cmp -s $testroot/stdout.expected $testroot/stdout
444 ret="$?"
445 if [ "$ret" != "0" ]; then
446 diff -u $testroot/stdout.expected $testroot/stdout
447 test_done "$testroot" "$ret"
448 return 1
449 fi
451 if [ -h $testroot/wt/nonexistent.link ]; then
452 echo -n "nonexistent.link still exists on disk: " >&2
453 readlink $testroot/wt/nonexistent.link >&2
454 test_done "$testroot" "1"
455 return 1
456 fi
458 test_done "$testroot" "0"
461 function test_cherrypick_symlink_conflicts {
462 local testroot=`test_init cherrypick_symlink_conflicts`
464 (cd $testroot/repo && ln -s alpha alpha.link)
465 (cd $testroot/repo && ln -s epsilon epsilon.link)
466 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
467 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
468 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
469 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
470 (cd $testroot/repo && git add .)
471 git_commit $testroot/repo -m "add symlinks"
472 local commit_id1=`git_show_head $testroot/repo`
474 (cd $testroot/repo && ln -sf beta alpha.link)
475 (cd $testroot/repo && ln -sf beta boo.link)
476 (cd $testroot/repo && ln -sfh gamma epsilon.link)
477 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
478 echo 'this is regular file foo' > $testroot/repo/dotgotfoo.link
479 (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
480 (cd $testroot/repo && git rm -q nonexistent.link)
481 (cd $testroot/repo && ln -sf gamma/delta zeta.link)
482 (cd $testroot/repo && ln -sf alpha new.link)
483 (cd $testroot/repo && git add .)
484 git_commit $testroot/repo -m "change symlinks"
485 local commit_id2=`git_show_head $testroot/repo`
487 got branch -r $testroot/repo -c $commit_id1 foo
488 got checkout -b foo $testroot/repo $testroot/wt > /dev/null
490 # modified symlink to file A vs modified symlink to file B
491 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
492 # modified symlink to dir A vs modified symlink to file B
493 (cd $testroot/wt && ln -sfh beta epsilon.link)
494 # modeified symlink to file A vs modified symlink to dir B
495 (cd $testroot/wt && ln -sfh ../gamma epsilon/beta.link)
496 # added regular file A vs added bad symlink to file A
497 (cd $testroot/wt && ln -sf .got/bar dotgotfoo.link)
498 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
499 # added bad symlink to file A vs added regular file A
500 echo 'this is regular file bar' > $testroot/wt/dotgotbar.link
501 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
502 # added symlink to file A vs unversioned file A
503 echo 'this is unversioned file boo' > $testroot/wt/boo.link
504 # removed symlink to non-existent file A vs modified symlink
505 # to nonexistent file B
506 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
507 # modified symlink to file A vs removed symlink to file A
508 (cd $testroot/wt && got rm zeta.link > /dev/null)
509 # added symlink to file A vs added symlink to file B
510 (cd $testroot/wt && ln -sf beta new.link)
511 (cd $testroot/wt && got add new.link > /dev/null)
512 (cd $testroot/wt && got commit -m "change on symlinks on branch foo" \
513 > /dev/null)
515 (cd $testroot/wt && got update >/dev/null)
516 (cd $testroot/wt && got cherrypick $commit_id2 > $testroot/stdout)
518 echo -n > $testroot/stdout.expected
519 echo "C alpha.link" >> $testroot/stdout.expected
520 echo "C epsilon/beta.link" >> $testroot/stdout.expected
521 echo "? boo.link" >> $testroot/stdout.expected
522 echo "C epsilon.link" >> $testroot/stdout.expected
523 echo "C dotgotbar.link" >> $testroot/stdout.expected
524 echo "C dotgotfoo.link" >> $testroot/stdout.expected
525 echo "D nonexistent.link" >> $testroot/stdout.expected
526 echo "! zeta.link" >> $testroot/stdout.expected
527 echo "C new.link" >> $testroot/stdout.expected
528 echo "Merged commit $commit_id2" >> $testroot/stdout.expected
529 echo "Files with new merge conflicts: 6" >> $testroot/stdout.expected
530 cmp -s $testroot/stdout.expected $testroot/stdout
531 ret="$?"
532 if [ "$ret" != "0" ]; then
533 diff -u $testroot/stdout.expected $testroot/stdout
534 test_done "$testroot" "$ret"
535 return 1
536 fi
538 if [ -h $testroot/wt/alpha.link ]; then
539 echo "alpha.link is a symlink"
540 test_done "$testroot" "1"
541 return 1
542 fi
544 cat > $testroot/symlink-conflict-header <<EOF
545 got: Could not install symbolic link because of merge conflict.
546 ln(1) may be used to fix the situation. If this is intended to be a
547 regular file instead then its expected contents may be filled in.
548 The following conflicting symlink target paths were found:
549 EOF
550 cp $testroot/symlink-conflict-header $testroot/content.expected
551 echo "<<<<<<< merged change: commit $commit_id2" \
552 >> $testroot/content.expected
553 echo "beta" >> $testroot/content.expected
554 echo "3-way merge base: commit $commit_id1" \
555 >> $testroot/content.expected
556 echo "alpha" >> $testroot/content.expected
557 echo "=======" >> $testroot/content.expected
558 echo "gamma/delta" >> $testroot/content.expected
559 echo '>>>>>>>' >> $testroot/content.expected
560 echo -n "" >> $testroot/content.expected
562 cp $testroot/wt/alpha.link $testroot/content
563 cmp -s $testroot/content.expected $testroot/content
564 ret="$?"
565 if [ "$ret" != "0" ]; then
566 diff -u $testroot/content.expected $testroot/content
567 test_done "$testroot" "$ret"
568 return 1
569 fi
571 if [ -h $testroot/wt/boo.link ]; then
572 echo "boo.link is a symlink"
573 test_done "$testroot" "1"
574 return 1
575 fi
577 echo "this is unversioned file boo" > $testroot/content.expected
578 cp $testroot/wt/boo.link $testroot/content
579 cmp -s $testroot/content.expected $testroot/content
580 ret="$?"
581 if [ "$ret" != "0" ]; then
582 diff -u $testroot/content.expected $testroot/content
583 test_done "$testroot" "$ret"
584 return 1
585 fi
587 if [ -h $testroot/wt/epsilon.link ]; then
588 echo "epsilon.link is a symlink"
589 test_done "$testroot" "1"
590 return 1
591 fi
593 cp $testroot/symlink-conflict-header $testroot/content.expected
594 echo "<<<<<<< merged change: commit $commit_id2" \
595 >> $testroot/content.expected
596 echo "gamma" >> $testroot/content.expected
597 echo "3-way merge base: commit $commit_id1" \
598 >> $testroot/content.expected
599 echo "epsilon" >> $testroot/content.expected
600 echo "=======" >> $testroot/content.expected
601 echo "beta" >> $testroot/content.expected
602 echo '>>>>>>>' >> $testroot/content.expected
603 echo -n "" >> $testroot/content.expected
605 cp $testroot/wt/epsilon.link $testroot/content
606 cmp -s $testroot/content.expected $testroot/content
607 ret="$?"
608 if [ "$ret" != "0" ]; then
609 diff -u $testroot/content.expected $testroot/content
610 test_done "$testroot" "$ret"
611 return 1
612 fi
614 if [ -h $testroot/wt/passwd.link ]; then
615 echo -n "passwd.link symlink points outside of work tree: " >&2
616 readlink $testroot/wt/passwd.link >&2
617 test_done "$testroot" "1"
618 return 1
619 fi
621 echo -n "/etc/passwd" > $testroot/content.expected
622 cp $testroot/wt/passwd.link $testroot/content
624 cmp -s $testroot/content.expected $testroot/content
625 ret="$?"
626 if [ "$ret" != "0" ]; then
627 diff -u $testroot/content.expected $testroot/content
628 test_done "$testroot" "$ret"
629 return 1
630 fi
632 if [ -h $testroot/wt/epsilon/beta.link ]; then
633 echo "epsilon/beta.link is a symlink"
634 test_done "$testroot" "1"
635 return 1
636 fi
638 cp $testroot/symlink-conflict-header $testroot/content.expected
639 echo "<<<<<<< merged change: commit $commit_id2" \
640 >> $testroot/content.expected
641 echo "../gamma/delta" >> $testroot/content.expected
642 echo "3-way merge base: commit $commit_id1" \
643 >> $testroot/content.expected
644 echo "../beta" >> $testroot/content.expected
645 echo "=======" >> $testroot/content.expected
646 echo "../gamma" >> $testroot/content.expected
647 echo '>>>>>>>' >> $testroot/content.expected
648 echo -n "" >> $testroot/content.expected
650 cp $testroot/wt/epsilon/beta.link $testroot/content
651 cmp -s $testroot/content.expected $testroot/content
652 ret="$?"
653 if [ "$ret" != "0" ]; then
654 diff -u $testroot/content.expected $testroot/content
655 test_done "$testroot" "$ret"
656 return 1
657 fi
659 if [ -h $testroot/wt/nonexistent.link ]; then
660 echo -n "nonexistent.link still exists on disk: " >&2
661 readlink $testroot/wt/nonexistent.link >&2
662 test_done "$testroot" "1"
663 return 1
664 fi
666 if [ -h $testroot/wt/dotgotfoo.link ]; then
667 echo "dotgotfoo.link is a symlink"
668 test_done "$testroot" "1"
669 return 1
670 fi
672 echo "<<<<<<< merged change: commit $commit_id2" \
673 > $testroot/content.expected
674 echo "this is regular file foo" >> $testroot/content.expected
675 echo "=======" >> $testroot/content.expected
676 echo -n ".got/bar" >> $testroot/content.expected
677 echo '>>>>>>>' >> $testroot/content.expected
678 cp $testroot/wt/dotgotfoo.link $testroot/content
679 cmp -s $testroot/content.expected $testroot/content
680 ret="$?"
681 if [ "$ret" != "0" ]; then
682 diff -u $testroot/content.expected $testroot/content
683 test_done "$testroot" "$ret"
684 return 1
685 fi
687 if [ -h $testroot/wt/dotgotbar.link ]; then
688 echo "dotgotbar.link is a symlink"
689 test_done "$testroot" "1"
690 return 1
691 fi
692 echo "<<<<<<< merged change: commit $commit_id2" \
693 > $testroot/content.expected
694 echo -n ".got/bar" >> $testroot/content.expected
695 echo "=======" >> $testroot/content.expected
696 echo "this is regular file bar" >> $testroot/content.expected
697 echo '>>>>>>>' >> $testroot/content.expected
698 echo -n "" >> $testroot/content.expected
699 cp $testroot/wt/dotgotbar.link $testroot/content
700 cmp -s $testroot/content.expected $testroot/content
701 ret="$?"
702 if [ "$ret" != "0" ]; then
703 diff -u $testroot/content.expected $testroot/content
704 test_done "$testroot" "$ret"
705 return 1
706 fi
708 if [ -h $testroot/wt/new.link ]; then
709 echo "new.link is a symlink"
710 test_done "$testroot" "1"
711 return 1
712 fi
714 cp $testroot/symlink-conflict-header $testroot/content.expected
715 echo "<<<<<<< merged change: commit $commit_id2" \
716 >> $testroot/content.expected
717 echo "alpha" >> $testroot/content.expected
718 echo "=======" >> $testroot/content.expected
719 echo "beta" >> $testroot/content.expected
720 echo '>>>>>>>' >> $testroot/content.expected
721 echo -n "" >> $testroot/content.expected
723 cp $testroot/wt/new.link $testroot/content
724 cmp -s $testroot/content.expected $testroot/content
725 ret="$?"
726 if [ "$ret" != "0" ]; then
727 diff -u $testroot/content.expected $testroot/content
728 test_done "$testroot" "$ret"
729 return 1
730 fi
732 echo "A dotgotfoo.link" > $testroot/stdout.expected
733 echo "M new.link" >> $testroot/stdout.expected
734 echo "D nonexistent.link" >> $testroot/stdout.expected
735 (cd $testroot/wt && got status > $testroot/stdout)
736 if [ "$ret" != "0" ]; then
737 diff -u $testroot/stdout.expected $testroot/stdout
738 test_done "$testroot" "$ret"
739 return 1
740 fi
742 test_done "$testroot" "0"
745 run_test test_cherrypick_basic
746 run_test test_cherrypick_root_commit
747 run_test test_cherrypick_into_work_tree_with_conflicts
748 run_test test_cherrypick_modified_submodule
749 run_test test_cherrypick_added_submodule
750 run_test test_cherrypick_conflict_wt_file_vs_repo_submodule
751 run_test test_cherrypick_modified_symlinks
752 run_test test_cherrypick_symlink_conflicts