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 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 echo "modified new file on branch" > $testroot/repo/epsilon/new
42 git_commit $testroot/repo -m "committing more changes on newbranch"
43 local branch_rev2=`git_show_head $testroot/repo`
45 (cd $testroot/wt && got cherrypick $branch_rev > $testroot/stdout)
47 echo "G alpha" > $testroot/stdout.expected
48 echo "D beta" >> $testroot/stdout.expected
49 echo "A epsilon/new" >> $testroot/stdout.expected
50 echo "Merged commit $branch_rev" >> $testroot/stdout.expected
52 cmp -s $testroot/stdout.expected $testroot/stdout
53 ret="$?"
54 if [ "$ret" != "0" ]; then
55 diff -u $testroot/stdout.expected $testroot/stdout
56 test_done "$testroot" "$ret"
57 return 1
58 fi
60 echo "modified alpha on branch" > $testroot/content.expected
61 cat $testroot/wt/alpha > $testroot/content
62 cmp -s $testroot/content.expected $testroot/content
63 ret="$?"
64 if [ "$ret" != "0" ]; then
65 diff -u $testroot/content.expected $testroot/content
66 test_done "$testroot" "$ret"
67 return 1
68 fi
70 if [ -e $testroot/wt/beta ]; then
71 echo "removed file beta still exists on disk" >&2
72 test_done "$testroot" "1"
73 return 1
74 fi
76 echo "new file on branch" > $testroot/content.expected
77 cat $testroot/wt/epsilon/new > $testroot/content
78 cmp -s $testroot/content.expected $testroot/content
79 ret="$?"
80 if [ "$ret" != "0" ]; then
81 diff -u $testroot/content.expected $testroot/content
82 test_done "$testroot" "$ret"
83 return 1
84 fi
86 echo 'M alpha' > $testroot/stdout.expected
87 echo 'D beta' >> $testroot/stdout.expected
88 echo 'A epsilon/new' >> $testroot/stdout.expected
90 (cd $testroot/wt && got status > $testroot/stdout)
92 cmp -s $testroot/stdout.expected $testroot/stdout
93 ret="$?"
94 if [ "$ret" != "0" ]; then
95 diff -u $testroot/stdout.expected $testroot/stdout
96 test_done "$testroot" "$ret"
97 return 1
98 fi
100 (cd $testroot/wt && got cherrypick $branch_rev2 > $testroot/stdout)
102 echo "G epsilon/new" > $testroot/stdout.expected
103 echo "Merged commit $branch_rev2" >> $testroot/stdout.expected
105 cmp -s $testroot/stdout.expected $testroot/stdout
106 ret="$?"
107 if [ "$ret" != "0" ]; then
108 diff -u $testroot/stdout.expected $testroot/stdout
109 test_done "$testroot" "$ret"
110 return 1
111 fi
113 echo 'M alpha' > $testroot/stdout.expected
114 echo 'D beta' >> $testroot/stdout.expected
115 echo 'A epsilon/new' >> $testroot/stdout.expected
117 (cd $testroot/wt && got status > $testroot/stdout)
119 cmp -s $testroot/stdout.expected $testroot/stdout
120 ret="$?"
121 if [ "$ret" != "0" ]; then
122 diff -u $testroot/stdout.expected $testroot/stdout
123 fi
124 test_done "$testroot" "$ret"
127 test_cherrypick_root_commit() {
128 local testroot=`test_init cherrypick_root_commit`
130 got checkout $testroot/repo $testroot/wt > /dev/null
131 ret="$?"
132 if [ "$ret" != "0" ]; then
133 test_done "$testroot" "$ret"
134 return 1
135 fi
137 (cd $testroot/repo && git checkout -q -b newbranch)
138 (cd $testroot/repo && git rm -q alpha)
139 (cd $testroot/repo && git rm -q beta)
140 (cd $testroot/repo && git rm -q epsilon/zeta)
141 (cd $testroot/repo && git rm -q gamma/delta)
142 mkdir -p $testroot/repo/epsilon
143 echo "new file on branch" > $testroot/repo/epsilon/new
144 (cd $testroot/repo && git add epsilon/new)
145 git_commit $testroot/repo -m "committing on newbranch"
147 echo "modified new file on branch" >> $testroot/repo/epsilon/new
148 git_commit $testroot/repo -m "committing on newbranch again"
150 tree=`git_show_tree $testroot/repo`
151 root_commit=`git_commit_tree $testroot/repo "new root commit" $tree`
153 (cd $testroot/wt && got cherrypick $root_commit > $testroot/stdout)
155 echo "A epsilon/new" > $testroot/stdout.expected
156 echo "Merged commit $root_commit" >> $testroot/stdout.expected
158 cmp -s $testroot/stdout.expected $testroot/stdout
159 ret="$?"
160 if [ "$ret" != "0" ]; then
161 diff -u $testroot/stdout.expected $testroot/stdout
162 test_done "$testroot" "$ret"
163 return 1
164 fi
166 echo "new file on branch" > $testroot/content.expected
167 echo "modified new file on branch" >> $testroot/content.expected
168 cat $testroot/wt/epsilon/new > $testroot/content
169 cmp -s $testroot/content.expected $testroot/content
170 ret="$?"
171 if [ "$ret" != "0" ]; then
172 diff -u $testroot/content.expected $testroot/content
173 test_done "$testroot" "$ret"
174 return 1
175 fi
177 echo 'A epsilon/new' > $testroot/stdout.expected
179 (cd $testroot/wt && got status > $testroot/stdout)
181 cmp -s $testroot/stdout.expected $testroot/stdout
182 ret="$?"
183 if [ "$ret" != "0" ]; then
184 diff -u $testroot/stdout.expected $testroot/stdout
185 fi
186 test_done "$testroot" "$ret"
189 test_cherrypick_into_work_tree_with_conflicts() {
190 local testroot=`test_init cherrypick_into_work_tree_with_conflicts`
192 got checkout $testroot/repo $testroot/wt > /dev/null
193 ret="$?"
194 if [ "$ret" != "0" ]; then
195 test_done "$testroot" "$ret"
196 return 1
197 fi
199 (cd $testroot/repo && git checkout -q -b newbranch)
200 echo "modified delta on branch" > $testroot/repo/gamma/delta
201 git_commit $testroot/repo -m "committing to delta on newbranch"
203 echo "modified alpha on branch" > $testroot/repo/alpha
204 (cd $testroot/repo && git rm -q beta)
205 echo "new file on branch" > $testroot/repo/epsilon/new
206 (cd $testroot/repo && git add epsilon/new)
207 git_commit $testroot/repo -m "committing more changes on newbranch"
209 local branch_rev=`git_show_head $testroot/repo`
211 # fake a merge conflict
212 echo '<<<<<<<' > $testroot/wt/alpha
213 echo 'alpha' >> $testroot/wt/alpha
214 echo '=======' >> $testroot/wt/alpha
215 echo 'alpha, too' >> $testroot/wt/alpha
216 echo '>>>>>>>' >> $testroot/wt/alpha
217 cp $testroot/wt/alpha $testroot/content.expected
219 echo "C alpha" > $testroot/stdout.expected
220 (cd $testroot/wt && got status > $testroot/stdout)
221 cmp -s $testroot/stdout.expected $testroot/stdout
222 ret="$?"
223 if [ "$ret" != "0" ]; then
224 diff -u $testroot/stdout.expected $testroot/stdout
225 test_done "$testroot" "$ret"
226 return 1
227 fi
229 (cd $testroot/wt && got cherrypick $branch_rev \
230 > $testroot/stdout 2> $testroot/stderr)
231 ret="$?"
232 if [ "$ret" = "0" ]; then
233 echo "cherrypick succeeded unexpectedly" >&2
234 test_done "$testroot" "1"
235 return 1
236 fi
238 echo -n > $testroot/stdout.expected
239 echo -n "got: work tree contains conflicted files; " \
240 > $testroot/stderr.expected
241 echo "these conflicts must be resolved first" \
242 >> $testroot/stderr.expected
244 cmp -s $testroot/stdout.expected $testroot/stdout
245 ret="$?"
246 if [ "$ret" != "0" ]; then
247 diff -u $testroot/stdout.expected $testroot/stdout
248 test_done "$testroot" "$ret"
249 return 1
250 fi
252 cmp -s $testroot/stderr.expected $testroot/stderr
253 ret="$?"
254 if [ "$ret" != "0" ]; then
255 diff -u $testroot/stderr.expected $testroot/stderr
256 test_done "$testroot" "$ret"
257 return 1
258 fi
260 cmp -s $testroot/content.expected $testroot/wt/alpha
261 ret="$?"
262 if [ "$ret" != "0" ]; then
263 diff -u $testroot/content.expected $testroot/wt/alpha
264 fi
265 test_done "$testroot" "$ret"
268 test_cherrypick_into_work_tree_with_mixed_commits() {
269 local testroot=`test_init cherrypick_into_work_tree_with_mixed_commits`
270 local first_rev=`git_show_head $testroot/repo`
272 echo "modified alpha" > $testroot/repo/alpha
273 git_commit $testroot/repo -m "committing to alpha"
274 local second_rev=`git_show_head $testroot/repo`
276 got checkout $testroot/repo $testroot/wt > /dev/null
277 ret="$?"
278 if [ "$ret" != "0" ]; then
279 test_done "$testroot" "$ret"
280 return 1
281 fi
283 (cd $testroot/repo && git checkout -q -b newbranch)
284 echo "modified delta on branch" > $testroot/repo/gamma/delta
285 git_commit $testroot/repo -m "committing to delta on newbranch"
287 (cd $testroot/repo && git rm -q beta)
288 echo "new file on branch" > $testroot/repo/epsilon/new
289 (cd $testroot/repo && git add epsilon/new)
290 git_commit $testroot/repo -m "committing more changes on newbranch"
292 local branch_rev=`git_show_head $testroot/repo`
294 (cd $testroot/wt && got update -c $first_rev alpha >/dev/null)
296 (cd $testroot/wt && got cherrypick $branch_rev \
297 > $testroot/stdout 2> $testroot/stderr)
298 ret="$?"
299 if [ "$ret" = "0" ]; then
300 echo "cherrypick succeeded unexpectedly" >&2
301 test_done "$testroot" "1"
302 return 1
303 fi
305 echo -n > $testroot/stdout.expected
306 echo -n "got: work tree contains files from multiple base commits; " \
307 > $testroot/stderr.expected
308 echo "the entire work tree must be updated first" \
309 >> $testroot/stderr.expected
311 cmp -s $testroot/stdout.expected $testroot/stdout
312 ret="$?"
313 if [ "$ret" != "0" ]; then
314 diff -u $testroot/stdout.expected $testroot/stdout
315 test_done "$testroot" "$ret"
316 return 1
317 fi
319 cmp -s $testroot/stderr.expected $testroot/stderr
320 ret="$?"
321 if [ "$ret" != "0" ]; then
322 diff -u $testroot/stderr.expected $testroot/stderr
323 fi
324 test_done "$testroot" "$ret"
328 test_cherrypick_modified_submodule() {
329 local testroot=`test_init cherrypick_modified_submodules`
331 make_single_file_repo $testroot/repo2 foo
333 (cd $testroot/repo && git submodule -q add ../repo2)
334 (cd $testroot/repo && git commit -q -m 'adding submodule')
336 got checkout $testroot/repo $testroot/wt > /dev/null
338 echo "modified foo" > $testroot/repo2/foo
339 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
341 (cd $testroot/repo && git checkout -q -b newbranch)
342 # Update the repo/repo2 submodule link on newbranch
343 (cd $testroot/repo && git -C repo2 pull -q)
344 (cd $testroot/repo && git add repo2)
345 git_commit $testroot/repo -m "modified submodule link"
346 local commit_id=`git_show_head $testroot/repo`
348 # This cherrypick is a no-op because Got's file index
349 # does not track submodules.
350 (cd $testroot/wt && got cherrypick $commit_id > $testroot/stdout)
352 echo -n > $testroot/stdout.expected
353 cmp -s $testroot/stdout.expected $testroot/stdout
354 ret="$?"
355 if [ "$ret" != "0" ]; then
356 diff -u $testroot/stdout.expected $testroot/stdout
357 fi
358 test_done "$testroot" "$ret"
361 test_cherrypick_added_submodule() {
362 local testroot=`test_init cherrypick_added_submodules`
364 got checkout $testroot/repo $testroot/wt > /dev/null
366 make_single_file_repo $testroot/repo2 foo
368 # Add the repo/repo2 submodule on newbranch
369 (cd $testroot/repo && git checkout -q -b newbranch)
370 (cd $testroot/repo && git submodule -q add ../repo2)
371 (cd $testroot/repo && git commit -q -m 'adding submodule')
372 local commit_id=`git_show_head $testroot/repo`
374 (cd $testroot/wt && got cherrypick $commit_id > $testroot/stdout)
376 echo "A .gitmodules" > $testroot/stdout.expected
377 echo "Merged commit $commit_id" >> $testroot/stdout.expected
378 cmp -s $testroot/stdout.expected $testroot/stdout
379 ret="$?"
380 if [ "$ret" != "0" ]; then
381 diff -u $testroot/stdout.expected $testroot/stdout
382 fi
383 test_done "$testroot" "$ret"
386 test_cherrypick_conflict_wt_file_vs_repo_submodule() {
387 local testroot=`test_init cherrypick_conflict_wt_file_vs_repo_submodule`
389 got checkout $testroot/repo $testroot/wt > /dev/null
391 # Add a file which will clash with the submodule
392 echo "This is a file called repo2" > $testroot/wt/repo2
393 (cd $testroot/wt && got add repo2 > /dev/null)
394 (cd $testroot/wt && got commit -m 'add file repo2' > /dev/null)
395 ret="$?"
396 if [ "$ret" != "0" ]; then
397 echo "commit failed unexpectedly" >&2
398 test_done "$testroot" "1"
399 return 1
400 fi
402 make_single_file_repo $testroot/repo2 foo
404 # Add the repo/repo2 submodule on newbranch
405 (cd $testroot/repo && git checkout -q -b newbranch)
406 (cd $testroot/repo && git submodule -q add ../repo2)
407 (cd $testroot/repo && git commit -q -m 'adding submodule')
408 local commit_id=`git_show_head $testroot/repo`
410 # Modify the clashing file such that any modifications brought
411 # in by 'got cherrypick' would require a merge.
412 echo "This file was changed" > $testroot/wt/repo2
414 (cd $testroot/wt && got update >/dev/null)
415 (cd $testroot/wt && got cherrypick $commit_id > $testroot/stdout)
417 echo "A .gitmodules" > $testroot/stdout.expected
418 echo "Merged commit $commit_id" >> $testroot/stdout.expected
419 cmp -s $testroot/stdout.expected $testroot/stdout
420 ret="$?"
421 if [ "$ret" != "0" ]; then
422 diff -u $testroot/stdout.expected $testroot/stdout
423 test_done "$testroot" "$ret"
424 return 1
425 fi
427 (cd $testroot/wt && got status > $testroot/stdout)
429 echo "A .gitmodules" > $testroot/stdout.expected
430 echo "M repo2" >> $testroot/stdout.expected
431 cmp -s $testroot/stdout.expected $testroot/stdout
432 ret="$?"
433 if [ "$ret" != "0" ]; then
434 diff -u $testroot/stdout.expected $testroot/stdout
435 fi
436 test_done "$testroot" "$ret"
439 test_cherrypick_modified_symlinks() {
440 local testroot=`test_init cherrypick_modified_symlinks`
442 (cd $testroot/repo && ln -s alpha alpha.link)
443 (cd $testroot/repo && ln -s epsilon epsilon.link)
444 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
445 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
446 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
447 (cd $testroot/repo && git add .)
448 git_commit $testroot/repo -m "add symlinks"
449 local commit_id1=`git_show_head $testroot/repo`
451 got branch -r $testroot/repo foo
453 got checkout -b foo $testroot/repo $testroot/wt > /dev/null
455 (cd $testroot/repo && ln -sf beta alpha.link)
456 (cd $testroot/repo && ln -sfh gamma epsilon.link)
457 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
458 (cd $testroot/repo && ln -sf .got/bar $testroot/repo/dotgotfoo.link)
459 (cd $testroot/repo && git rm -q nonexistent.link)
460 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
461 (cd $testroot/repo && git add .)
462 git_commit $testroot/repo -m "change symlinks"
463 local commit_id2=`git_show_head $testroot/repo`
465 (cd $testroot/wt && got cherrypick $commit_id2 > $testroot/stdout)
467 echo "G alpha.link" > $testroot/stdout.expected
468 echo "G epsilon/beta.link" >> $testroot/stdout.expected
469 echo "A dotgotfoo.link" >> $testroot/stdout.expected
470 echo "G epsilon.link" >> $testroot/stdout.expected
471 echo "D nonexistent.link" >> $testroot/stdout.expected
472 echo "A zeta.link" >> $testroot/stdout.expected
473 echo "Merged commit $commit_id2" >> $testroot/stdout.expected
474 cmp -s $testroot/stdout.expected $testroot/stdout
475 ret="$?"
476 if [ "$ret" != "0" ]; then
477 diff -u $testroot/stdout.expected $testroot/stdout
478 test_done "$testroot" "$ret"
479 return 1
480 fi
482 if ! [ -h $testroot/wt/alpha.link ]; then
483 echo "alpha.link is not a symlink"
484 test_done "$testroot" "1"
485 return 1
486 fi
488 readlink $testroot/wt/alpha.link > $testroot/stdout
489 echo "beta" > $testroot/stdout.expected
490 cmp -s $testroot/stdout.expected $testroot/stdout
491 ret="$?"
492 if [ "$ret" != "0" ]; then
493 diff -u $testroot/stdout.expected $testroot/stdout
494 test_done "$testroot" "$ret"
495 return 1
496 fi
498 if ! [ -h $testroot/wt/epsilon.link ]; then
499 echo "epsilon.link is not a symlink"
500 test_done "$testroot" "1"
501 return 1
502 fi
504 readlink $testroot/wt/epsilon.link > $testroot/stdout
505 echo "gamma" > $testroot/stdout.expected
506 cmp -s $testroot/stdout.expected $testroot/stdout
507 ret="$?"
508 if [ "$ret" != "0" ]; then
509 diff -u $testroot/stdout.expected $testroot/stdout
510 test_done "$testroot" "$ret"
511 return 1
512 fi
514 if [ -h $testroot/wt/passwd.link ]; then
515 echo -n "passwd.link symlink points outside of work tree: " >&2
516 readlink $testroot/wt/passwd.link >&2
517 test_done "$testroot" "1"
518 return 1
519 fi
521 echo -n "/etc/passwd" > $testroot/content.expected
522 cp $testroot/wt/passwd.link $testroot/content
524 cmp -s $testroot/content.expected $testroot/content
525 ret="$?"
526 if [ "$ret" != "0" ]; then
527 diff -u $testroot/content.expected $testroot/content
528 test_done "$testroot" "$ret"
529 return 1
530 fi
532 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
533 echo "../gamma/delta" > $testroot/stdout.expected
534 cmp -s $testroot/stdout.expected $testroot/stdout
535 ret="$?"
536 if [ "$ret" != "0" ]; then
537 diff -u $testroot/stdout.expected $testroot/stdout
538 test_done "$testroot" "$ret"
539 return 1
540 fi
542 if [ -h $testroot/wt/nonexistent.link ]; then
543 echo -n "nonexistent.link still exists on disk: " >&2
544 readlink $testroot/wt/nonexistent.link >&2
545 test_done "$testroot" "1"
546 return 1
547 fi
549 test_done "$testroot" "0"
552 test_cherrypick_symlink_conflicts() {
553 local testroot=`test_init cherrypick_symlink_conflicts`
555 (cd $testroot/repo && ln -s alpha alpha.link)
556 (cd $testroot/repo && ln -s epsilon epsilon.link)
557 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
558 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
559 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
560 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
561 (cd $testroot/repo && git add .)
562 git_commit $testroot/repo -m "add symlinks"
563 local commit_id1=`git_show_head $testroot/repo`
565 (cd $testroot/repo && ln -sf beta alpha.link)
566 (cd $testroot/repo && ln -sf beta boo.link)
567 (cd $testroot/repo && ln -sfh gamma epsilon.link)
568 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
569 echo 'this is regular file foo' > $testroot/repo/dotgotfoo.link
570 (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
571 (cd $testroot/repo && git rm -q nonexistent.link)
572 (cd $testroot/repo && ln -sf gamma/delta zeta.link)
573 (cd $testroot/repo && ln -sf alpha new.link)
574 (cd $testroot/repo && git add .)
575 git_commit $testroot/repo -m "change symlinks"
576 local commit_id2=`git_show_head $testroot/repo`
578 got branch -r $testroot/repo -c $commit_id1 foo
579 got checkout -b foo $testroot/repo $testroot/wt > /dev/null
581 # modified symlink to file A vs modified symlink to file B
582 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
583 # modified symlink to dir A vs modified symlink to file B
584 (cd $testroot/wt && ln -sfh beta epsilon.link)
585 # modeified symlink to file A vs modified symlink to dir B
586 (cd $testroot/wt && ln -sfh ../gamma epsilon/beta.link)
587 # added regular file A vs added bad symlink to file A
588 (cd $testroot/wt && ln -sf .got/bar dotgotfoo.link)
589 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
590 # added bad symlink to file A vs added regular file A
591 echo 'this is regular file bar' > $testroot/wt/dotgotbar.link
592 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
593 # added symlink to file A vs unversioned file A
594 echo 'this is unversioned file boo' > $testroot/wt/boo.link
595 # removed symlink to non-existent file A vs modified symlink
596 # to nonexistent file B
597 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
598 # modified symlink to file A vs removed symlink to file A
599 (cd $testroot/wt && got rm zeta.link > /dev/null)
600 # added symlink to file A vs added symlink to file B
601 (cd $testroot/wt && ln -sf beta new.link)
602 (cd $testroot/wt && got add new.link > /dev/null)
603 (cd $testroot/wt && got commit -S -m "change symlinks on foo" \
604 > /dev/null)
606 (cd $testroot/wt && got update >/dev/null)
607 (cd $testroot/wt && got cherrypick $commit_id2 > $testroot/stdout)
609 echo -n > $testroot/stdout.expected
610 echo "C alpha.link" >> $testroot/stdout.expected
611 echo "C epsilon/beta.link" >> $testroot/stdout.expected
612 echo "? boo.link" >> $testroot/stdout.expected
613 echo "C epsilon.link" >> $testroot/stdout.expected
614 echo "C dotgotbar.link" >> $testroot/stdout.expected
615 echo "C dotgotfoo.link" >> $testroot/stdout.expected
616 echo "D nonexistent.link" >> $testroot/stdout.expected
617 echo "! zeta.link" >> $testroot/stdout.expected
618 echo "C new.link" >> $testroot/stdout.expected
619 echo "Merged commit $commit_id2" >> $testroot/stdout.expected
620 echo "Files with new merge conflicts: 6" >> $testroot/stdout.expected
621 cmp -s $testroot/stdout.expected $testroot/stdout
622 ret="$?"
623 if [ "$ret" != "0" ]; then
624 diff -u $testroot/stdout.expected $testroot/stdout
625 test_done "$testroot" "$ret"
626 return 1
627 fi
629 if [ -h $testroot/wt/alpha.link ]; then
630 echo "alpha.link is a symlink"
631 test_done "$testroot" "1"
632 return 1
633 fi
635 echo "<<<<<<< merged change: commit $commit_id2" \
636 > $testroot/content.expected
637 echo "beta" >> $testroot/content.expected
638 echo "3-way merge base: commit $commit_id1" \
639 >> $testroot/content.expected
640 echo "alpha" >> $testroot/content.expected
641 echo "=======" >> $testroot/content.expected
642 echo "gamma/delta" >> $testroot/content.expected
643 echo '>>>>>>>' >> $testroot/content.expected
644 echo -n "" >> $testroot/content.expected
646 cp $testroot/wt/alpha.link $testroot/content
647 cmp -s $testroot/content.expected $testroot/content
648 ret="$?"
649 if [ "$ret" != "0" ]; then
650 diff -u $testroot/content.expected $testroot/content
651 test_done "$testroot" "$ret"
652 return 1
653 fi
655 if [ -h $testroot/wt/boo.link ]; then
656 echo "boo.link is a symlink"
657 test_done "$testroot" "1"
658 return 1
659 fi
661 echo "this is unversioned file boo" > $testroot/content.expected
662 cp $testroot/wt/boo.link $testroot/content
663 cmp -s $testroot/content.expected $testroot/content
664 ret="$?"
665 if [ "$ret" != "0" ]; then
666 diff -u $testroot/content.expected $testroot/content
667 test_done "$testroot" "$ret"
668 return 1
669 fi
671 if [ -h $testroot/wt/epsilon.link ]; then
672 echo "epsilon.link is a symlink"
673 test_done "$testroot" "1"
674 return 1
675 fi
677 echo "<<<<<<< merged change: commit $commit_id2" \
678 > $testroot/content.expected
679 echo "gamma" >> $testroot/content.expected
680 echo "3-way merge base: commit $commit_id1" \
681 >> $testroot/content.expected
682 echo "epsilon" >> $testroot/content.expected
683 echo "=======" >> $testroot/content.expected
684 echo "beta" >> $testroot/content.expected
685 echo '>>>>>>>' >> $testroot/content.expected
686 echo -n "" >> $testroot/content.expected
688 cp $testroot/wt/epsilon.link $testroot/content
689 cmp -s $testroot/content.expected $testroot/content
690 ret="$?"
691 if [ "$ret" != "0" ]; then
692 diff -u $testroot/content.expected $testroot/content
693 test_done "$testroot" "$ret"
694 return 1
695 fi
697 if [ -h $testroot/wt/passwd.link ]; then
698 echo -n "passwd.link symlink points outside of work tree: " >&2
699 readlink $testroot/wt/passwd.link >&2
700 test_done "$testroot" "1"
701 return 1
702 fi
704 echo -n "/etc/passwd" > $testroot/content.expected
705 cp $testroot/wt/passwd.link $testroot/content
707 cmp -s $testroot/content.expected $testroot/content
708 ret="$?"
709 if [ "$ret" != "0" ]; then
710 diff -u $testroot/content.expected $testroot/content
711 test_done "$testroot" "$ret"
712 return 1
713 fi
715 if [ -h $testroot/wt/epsilon/beta.link ]; then
716 echo "epsilon/beta.link is a symlink"
717 test_done "$testroot" "1"
718 return 1
719 fi
721 echo "<<<<<<< merged change: commit $commit_id2" \
722 > $testroot/content.expected
723 echo "../gamma/delta" >> $testroot/content.expected
724 echo "3-way merge base: commit $commit_id1" \
725 >> $testroot/content.expected
726 echo "../beta" >> $testroot/content.expected
727 echo "=======" >> $testroot/content.expected
728 echo "../gamma" >> $testroot/content.expected
729 echo '>>>>>>>' >> $testroot/content.expected
730 echo -n "" >> $testroot/content.expected
732 cp $testroot/wt/epsilon/beta.link $testroot/content
733 cmp -s $testroot/content.expected $testroot/content
734 ret="$?"
735 if [ "$ret" != "0" ]; then
736 diff -u $testroot/content.expected $testroot/content
737 test_done "$testroot" "$ret"
738 return 1
739 fi
741 if [ -h $testroot/wt/nonexistent.link ]; then
742 echo -n "nonexistent.link still exists on disk: " >&2
743 readlink $testroot/wt/nonexistent.link >&2
744 test_done "$testroot" "1"
745 return 1
746 fi
748 if [ -h $testroot/wt/dotgotfoo.link ]; then
749 echo "dotgotfoo.link is a symlink"
750 test_done "$testroot" "1"
751 return 1
752 fi
754 echo "<<<<<<< merged change: commit $commit_id2" \
755 > $testroot/content.expected
756 echo "this is regular file foo" >> $testroot/content.expected
757 echo "=======" >> $testroot/content.expected
758 echo -n ".got/bar" >> $testroot/content.expected
759 echo '>>>>>>>' >> $testroot/content.expected
760 cp $testroot/wt/dotgotfoo.link $testroot/content
761 cmp -s $testroot/content.expected $testroot/content
762 ret="$?"
763 if [ "$ret" != "0" ]; then
764 diff -u $testroot/content.expected $testroot/content
765 test_done "$testroot" "$ret"
766 return 1
767 fi
769 if [ -h $testroot/wt/dotgotbar.link ]; then
770 echo "dotgotbar.link is a symlink"
771 test_done "$testroot" "1"
772 return 1
773 fi
774 echo "<<<<<<< merged change: commit $commit_id2" \
775 > $testroot/content.expected
776 echo -n ".got/bar" >> $testroot/content.expected
777 echo "=======" >> $testroot/content.expected
778 echo "this is regular file bar" >> $testroot/content.expected
779 echo '>>>>>>>' >> $testroot/content.expected
780 echo -n "" >> $testroot/content.expected
781 cp $testroot/wt/dotgotbar.link $testroot/content
782 cmp -s $testroot/content.expected $testroot/content
783 ret="$?"
784 if [ "$ret" != "0" ]; then
785 diff -u $testroot/content.expected $testroot/content
786 test_done "$testroot" "$ret"
787 return 1
788 fi
790 if [ -h $testroot/wt/new.link ]; then
791 echo "new.link is a symlink"
792 test_done "$testroot" "1"
793 return 1
794 fi
796 echo "<<<<<<< merged change: commit $commit_id2" \
797 > $testroot/content.expected
798 echo "alpha" >> $testroot/content.expected
799 echo "=======" >> $testroot/content.expected
800 echo "beta" >> $testroot/content.expected
801 echo '>>>>>>>' >> $testroot/content.expected
802 echo -n "" >> $testroot/content.expected
804 cp $testroot/wt/new.link $testroot/content
805 cmp -s $testroot/content.expected $testroot/content
806 ret="$?"
807 if [ "$ret" != "0" ]; then
808 diff -u $testroot/content.expected $testroot/content
809 test_done "$testroot" "$ret"
810 return 1
811 fi
813 echo "A dotgotfoo.link" > $testroot/stdout.expected
814 echo "M new.link" >> $testroot/stdout.expected
815 echo "D nonexistent.link" >> $testroot/stdout.expected
816 (cd $testroot/wt && got status > $testroot/stdout)
817 if [ "$ret" != "0" ]; then
818 diff -u $testroot/stdout.expected $testroot/stdout
819 test_done "$testroot" "$ret"
820 return 1
821 fi
823 test_done "$testroot" "0"
826 test_cherrypick_with_path_prefix_and_empty_tree() {
827 local testroot=`test_init cherrypick_with_path_prefix_and_empty_tree 1`
829 (cd $testroot/repo && git commit --allow-empty \
830 -m "initial empty commit" >/dev/null)
832 (cd $testroot/repo && got br bar >/dev/null)
834 mkdir -p $testroot/repo/epsilon
835 echo "file foo" > $testroot/repo/epsilon/foo
836 (cd $testroot/repo && git add .)
837 git_commit $testroot/repo -m "add file foo"
838 local commit_id=`git_show_head $testroot/repo`
840 got checkout -b bar $testroot/repo $testroot/wt > /dev/null
841 ret="$?"
842 if [ "$ret" != "0" ]; then
843 echo "got checkout failed unexpectedly" >&2
844 test_done "$testroot" "$ret"
845 return 1
846 fi
848 mkdir -p $testroot/wt/epsilon
849 echo "new file" > $testroot/wt/epsilon/new
850 (cd $testroot/wt && got add epsilon/new >/dev/null)
851 (cd $testroot/wt && got commit -m "add file on branch bar" > /dev/null)
853 got checkout -b bar -p epsilon $testroot/repo $testroot/wt2 > /dev/null
854 ret="$?"
855 if [ "$ret" != "0" ]; then
856 echo "got checkout failed unexpectedly" >&2
857 test_done "$testroot" "$ret"
858 return 1
859 fi
860 (cd $testroot/wt2 && got cherrypick $commit_id > $testroot/stdout)
862 echo "A foo" > $testroot/stdout.expected
863 echo "Merged commit $commit_id" >> $testroot/stdout.expected
865 cmp -s $testroot/stdout.expected $testroot/stdout
866 ret="$?"
867 if [ "$ret" != "0" ]; then
868 diff -u $testroot/stdout.expected $testroot/stdout
869 fi
870 test_done "$testroot" "$ret"
873 test_cherrypick_conflict_no_eol() {
874 local testroot=`test_init cherrypick_conflict_no_eol 1`
875 local content_a="aaa\naaa\naaa\naaa\naaa\naaa\n"
876 local content_b="aaa\naaa\nbbb\naaa\naaa\naaa\naaa"
877 local content_c="aaa\naaa\nccc\naaa\naaa\naaa\naaa"
879 printf "$content_a" > $testroot/repo/a
880 (cd $testroot/repo && git add a)
881 git_commit $testroot/repo -m "initial commit"
883 (cd $testroot/repo && got branch newbranch)
885 printf "$content_b" > $testroot/repo/a
886 git_commit $testroot/repo -m "change bbb"
888 printf "$content_c" > $testroot/repo/a
889 git_commit $testroot/repo -m "change ccc"
890 local ccc_commit=`git_show_head $testroot/repo`
892 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
893 ret="$?"
894 if [ "$ret" != "0" ]; then
895 test_done "$testroot" "$ret"
896 return 1
897 fi
899 (cd $testroot/wt && got cherrypick $ccc_commit > $testroot/stdout)
901 echo "C a" > $testroot/stdout.expected
902 echo "Merged commit $ccc_commit" >> $testroot/stdout.expected
903 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
905 cmp -s $testroot/stdout.expected $testroot/stdout
906 ret="$?"
907 if [ "$ret" != "0" ]; then
908 diff -u $testroot/stdout.expected $testroot/stdout
909 fi
910 test_done "$testroot" "$ret"
913 test_cherrypick_conflict_no_eol2() {
914 local testroot=`test_init cherrypick_conflict_no_eol2 1`
915 local content_a="aaa\naaa\naaa\naaa\naaa\naaa"
916 local content_b="aaa\naaa\nbbb\naaa\naaa\naaa"
917 local content_c="aaa\naaa\nbbb\naaa\naaa\naaa\n"
919 printf "$content_a" > $testroot/repo/a
920 (cd $testroot/repo && git add a)
921 git_commit $testroot/repo -m "initial commit"
923 (cd $testroot/repo && got branch newbranch)
925 printf "$content_b" > $testroot/repo/a
926 git_commit $testroot/repo -m "change bbb"
928 printf "$content_c" > $testroot/repo/a
929 git_commit $testroot/repo -m "change ccc"
930 local ccc_commit=`git_show_head $testroot/repo`
932 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
933 ret="$?"
934 if [ "$ret" != "0" ]; then
935 test_done "$testroot" "$ret"
936 return 1
937 fi
939 (cd $testroot/wt && got cherrypick $ccc_commit \
940 > $testroot/stdout 2> $testroot/stderr)
942 echo "C a" > $testroot/stdout.expected
943 echo "Merged commit $ccc_commit" >> $testroot/stdout.expected
944 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
946 cmp -s $testroot/stdout.expected $testroot/stdout
947 ret="$?"
948 if [ "$ret" != "0" ]; then
949 diff -u $testroot/stdout.expected $testroot/stdout
950 fi
951 test_done "$testroot" "$ret"
954 test_cherrypick_unrelated_changes() {
955 local testroot=`test_init cherrypick_unrelated_changes`
957 # Sorry about the large HERE document but I have not found
958 # a smaller reproduction recipe yet...
959 cat > $testroot/repo/reference.c <<EOF
960 const struct got_error *
961 got_ref_alloc(struct got_reference **ref, const char *name,
962 struct got_object_id *id)
964 if (!is_valid_ref_name(name))
965 return got_error_path(name, GOT_ERR_BAD_REF_NAME);
967 return alloc_ref(ref, name, id, 0);
970 static const struct got_error *
971 parse_packed_ref_line(struct got_reference **ref, const char *abs_refname,
972 const char *line)
974 struct got_object_id id;
975 const char *name;
977 *ref = NULL;
979 if (line[0] == '#' || line[0] == '^')
980 return NULL;
982 if (!got_parse_sha1_digest(id.sha1, line))
983 return got_error(GOT_ERR_BAD_REF_DATA);
985 if (abs_refname) {
986 if (strcmp(line + SHA1_DIGEST_STRING_LENGTH, abs_refname) != 0)
987 return NULL;
988 name = abs_refname;
989 } else
990 name = line + SHA1_DIGEST_STRING_LENGTH;
992 return alloc_ref(ref, name, &id, GOT_REF_IS_PACKED);
995 static const struct got_error *
996 open_packed_ref(struct got_reference **ref, FILE *f, const char **subdirs,
997 int nsubdirs, const char *refname)
999 const struct got_error *err = NULL;
1000 char *abs_refname;
1001 char *line = NULL;
1002 size_t linesize = 0;
1003 ssize_t linelen;
1004 int i, ref_is_absolute = (strncmp(refname, "refs/", 5) == 0);
1006 *ref = NULL;
1008 if (ref_is_absolute)
1009 abs_refname = (char *)refname;
1010 do {
1011 linelen = getline(&line, &linesize, f);
1012 if (linelen == -1) {
1013 if (feof(f))
1014 break;
1015 err = got_ferror(f, GOT_ERR_BAD_REF_DATA);
1016 break;
1018 if (linelen > 0 && line[linelen - 1] == '\n')
1019 line[linelen - 1] = '\0';
1020 for (i = 0; i < nsubdirs; i++) {
1021 if (!ref_is_absolute &&
1022 asprintf(&abs_refname, "refs/%s/%s", subdirs[i],
1023 refname) == -1)
1024 return got_error_from_errno("asprintf");
1025 err = parse_packed_ref_line(ref, abs_refname, line);
1026 if (!ref_is_absolute)
1027 free(abs_refname);
1028 if (err || *ref != NULL)
1029 break;
1031 if (err)
1032 break;
1033 } while (*ref == NULL);
1034 free(line);
1036 return err;
1039 static const struct got_error *
1040 open_ref(struct got_reference **ref, const char *path_refs, const char *subdir,
1041 const char *name, int lock)
1043 const struct got_error *err = NULL;
1044 char *path = NULL;
1045 char *absname = NULL;
1046 int ref_is_absolute = (strncmp(name, "refs/", 5) == 0);
1047 int ref_is_well_known = (subdir[0] == '\0' && is_well_known_ref(name));
1049 *ref = NULL;
1051 if (ref_is_absolute || ref_is_well_known) {
1052 if (asprintf(&path, "%s/%s", path_refs, name) == -1)
1053 return got_error_from_errno("asprintf");
1054 absname = (char *)name;
1055 } else {
1056 if (asprintf(&path, "%s/%s%s%s", path_refs, subdir,
1057 subdir[0] ? "/" : "", name) == -1)
1058 return got_error_from_errno("asprintf");
1060 if (asprintf(&absname, "refs/%s%s%s",
1061 subdir, subdir[0] ? "/" : "", name) == -1) {
1062 err = got_error_from_errno("asprintf");
1063 goto done;
1067 err = parse_ref_file(ref, name, absname, path, lock);
1068 done:
1069 if (!ref_is_absolute && !ref_is_well_known)
1070 free(absname);
1071 free(path);
1072 return err;
1075 const struct got_error *
1076 got_ref_open(struct got_reference **ref, struct got_repository *repo,
1077 const char *refname, int lock)
1079 const struct got_error *err = NULL;
1080 char *path_refs = NULL;
1081 const char *subdirs[] = {
1082 GOT_REF_HEADS, GOT_REF_TAGS, GOT_REF_REMOTES
1084 size_t i;
1085 int well_known = is_well_known_ref(refname);
1086 struct got_lockfile *lf = NULL;
1088 *ref = NULL;
1090 path_refs = get_refs_dir_path(repo, refname);
1091 if (path_refs == NULL) {
1092 err = got_error_from_errno2("get_refs_dir_path", refname);
1093 goto done;
1096 if (well_known) {
1097 err = open_ref(ref, path_refs, "", refname, lock);
1098 } else {
1099 char *packed_refs_path;
1100 FILE *f;
1102 /* Search on-disk refs before packed refs! */
1103 for (i = 0; i < nitems(subdirs); i++) {
1104 err = open_ref(ref, path_refs, subdirs[i], refname,
1105 lock);
1106 if ((err && err->code != GOT_ERR_NOT_REF) || *ref)
1107 goto done;
1110 packed_refs_path = got_repo_get_path_packed_refs(repo);
1111 if (packed_refs_path == NULL) {
1112 err = got_error_from_errno(
1113 "got_repo_get_path_packed_refs");
1114 goto done;
1117 if (lock) {
1118 err = got_lockfile_lock(&lf, packed_refs_path);
1119 if (err)
1120 goto done;
1122 f = fopen(packed_refs_path, "rb");
1123 free(packed_refs_path);
1124 if (f != NULL) {
1125 err = open_packed_ref(ref, f, subdirs, nitems(subdirs),
1126 refname);
1127 if (!err) {
1128 if (fclose(f) == EOF) {
1129 err = got_error_from_errno("fclose");
1130 got_ref_close(*ref);
1131 *ref = NULL;
1132 } else if (*ref)
1133 (*ref)->lf = lf;
1137 done:
1138 if (!err && *ref == NULL)
1139 err = got_error_not_ref(refname);
1140 if (err && lf)
1141 got_lockfile_unlock(lf);
1142 free(path_refs);
1143 return err;
1146 struct got_reference *
1147 got_ref_dup(struct got_reference *ref)
1149 struct got_reference *ret;
1151 ret = calloc(1, sizeof(*ret));
1152 if (ret == NULL)
1153 return NULL;
1155 ret->flags = ref->flags;
1156 if (ref->flags & GOT_REF_IS_SYMBOLIC) {
1157 ret->ref.symref.name = strdup(ref->ref.symref.name);
1158 if (ret->ref.symref.name == NULL) {
1159 free(ret);
1160 return NULL;
1162 ret->ref.symref.ref = strdup(ref->ref.symref.ref);
1163 if (ret->ref.symref.ref == NULL) {
1164 free(ret->ref.symref.name);
1165 free(ret);
1166 return NULL;
1168 } else {
1169 ret->ref.ref.name = strdup(ref->ref.ref.name);
1170 if (ret->ref.ref.name == NULL) {
1171 free(ret);
1172 return NULL;
1174 memcpy(ret->ref.ref.sha1, ref->ref.ref.sha1,
1175 sizeof(ret->ref.ref.sha1));
1178 return ret;
1181 const struct got_error *
1182 got_reflist_entry_dup(struct got_reflist_entry **newp,
1183 struct got_reflist_entry *re)
1185 const struct got_error *err = NULL;
1186 struct got_reflist_entry *new;
1188 *newp = NULL;
1190 new = malloc(sizeof(*new));
1191 if (new == NULL)
1192 return got_error_from_errno("malloc");
1194 new->ref = got_ref_dup(re->ref);
1195 if (new->ref == NULL) {
1196 err = got_error_from_errno("got_ref_dup");
1197 free(new);
1198 return err;
1201 *newp = new;
1202 return NULL;
1205 void
1206 got_ref_list_free(struct got_reflist_head *refs)
1208 struct got_reflist_entry *re;
1210 while ((re = TAILQ_FIRST(refs))) {
1211 TAILQ_REMOVE(refs, re, entry);
1212 free(re);
1216 EOF
1217 (cd $testroot/repo && git add reference.c)
1218 git_commit $testroot/repo -m "added reference.c file"
1219 local base_commit=`git_show_head $testroot/repo`
1221 got checkout $testroot/repo $testroot/wt > /dev/null
1222 ret="$?"
1223 if [ "$ret" != "0" ]; then
1224 test_done "$testroot" "$ret"
1225 return 1
1228 (cd $testroot/repo && git checkout -q -b newbranch)
1229 ed -s $testroot/repo/reference.c <<EOF
1230 91a
1231 if (!is_valid_ref_name(name))
1232 return got_error_path(name, GOT_ERR_BAD_REF_NAME);
1237 EOF
1238 git_commit $testroot/repo -m "added lines on newbranch"
1239 local branch_rev1=`git_show_head $testroot/repo`
1241 ed -s $testroot/repo/reference.c <<EOF
1242 255a
1243 got_ref_close(re->ref);
1247 EOF
1248 git_commit $testroot/repo -m "more lines on newbranch"
1250 local branch_rev2=`git_show_head $testroot/repo`
1252 (cd $testroot/wt && got cherrypick $branch_rev2 > $testroot/stdout)
1254 echo "G reference.c" > $testroot/stdout.expected
1255 echo "Merged commit $branch_rev2" >> $testroot/stdout.expected
1257 cmp -s $testroot/stdout.expected $testroot/stdout
1258 ret="$?"
1259 if [ "$ret" != "0" ]; then
1260 diff -u $testroot/stdout.expected $testroot/stdout
1261 test_done "$testroot" "$ret"
1262 return 1
1265 cat > $testroot/diff.expected <<EOF
1266 --- reference.c
1267 +++ reference.c
1268 @@ -250,6 +250,7 @@ got_ref_list_free(struct got_reflist_head *refs)
1270 while ((re = TAILQ_FIRST(refs))) {
1271 TAILQ_REMOVE(refs, re, entry);
1272 + got_ref_close(re->ref);
1273 free(re);
1276 EOF
1277 (cd $testroot/wt && got diff |
1278 egrep -v '^(diff|blob|file)' > $testroot/diff)
1279 cmp -s $testroot/diff.expected $testroot/diff
1280 ret="$?"
1281 if [ "$ret" != "0" ]; then
1282 diff -u $testroot/diff.expected $testroot/diff
1285 test_done "$testroot" "$ret"
1288 test_cherrypick_same_branch() {
1289 local testroot=`test_init cherrypick_same_branch`
1291 got checkout $testroot/repo $testroot/wt > /dev/null
1292 ret="$?"
1293 if [ "$ret" != "0" ]; then
1294 test_done "$testroot" "$ret"
1295 return 1
1298 (cd $testroot/repo && git checkout -q -b newbranch)
1299 echo "modified delta on branch" > $testroot/repo/gamma/delta
1300 git_commit $testroot/repo -m "committing to delta on newbranch"
1302 echo "modified alpha on branch" > $testroot/repo/alpha
1303 (cd $testroot/repo && git rm -q beta)
1304 echo "new file on branch" > $testroot/repo/epsilon/new
1305 (cd $testroot/repo && git add epsilon/new)
1306 git_commit $testroot/repo -m "committing more changes on newbranch"
1308 local branch_rev=`git_show_head $testroot/repo`
1310 # picking a commit from the branch's own history does not make
1311 # sense but we should have test coverage for this case regardless
1312 (cd $testroot/wt && got up -b newbranch > /dev/null)
1313 (cd $testroot/wt && got cherrypick $branch_rev > $testroot/stdout)
1315 echo "G alpha" > $testroot/stdout.expected
1316 echo "! beta" >> $testroot/stdout.expected
1317 echo "G epsilon/new" >> $testroot/stdout.expected
1318 echo "Merged commit $branch_rev" >> $testroot/stdout.expected
1320 cmp -s $testroot/stdout.expected $testroot/stdout
1321 ret="$?"
1322 if [ "$ret" != "0" ]; then
1323 diff -u $testroot/stdout.expected $testroot/stdout
1325 test_done "$testroot" "$ret"
1329 test_parseargs "$@"
1330 run_test test_cherrypick_basic
1331 run_test test_cherrypick_root_commit
1332 run_test test_cherrypick_into_work_tree_with_conflicts
1333 run_test test_cherrypick_into_work_tree_with_mixed_commits
1334 run_test test_cherrypick_modified_submodule
1335 run_test test_cherrypick_added_submodule
1336 run_test test_cherrypick_conflict_wt_file_vs_repo_submodule
1337 run_test test_cherrypick_modified_symlinks
1338 run_test test_cherrypick_symlink_conflicts
1339 run_test test_cherrypick_with_path_prefix_and_empty_tree
1340 run_test test_cherrypick_conflict_no_eol
1341 run_test test_cherrypick_conflict_no_eol2
1342 run_test test_cherrypick_unrelated_changes
1343 run_test test_cherrypick_same_branch