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 function test_commit_basic {
20 local testroot=`test_init commit_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
29 echo "modified alpha" > $testroot/wt/alpha
30 (cd $testroot/wt && got rm beta >/dev/null)
31 echo "new file" > $testroot/wt/new
32 (cd $testroot/wt && got add new >/dev/null)
34 (cd $testroot/wt && got commit -m 'test commit_basic' > $testroot/stdout)
36 local head_rev=`git_show_head $testroot/repo`
37 echo "A new" > $testroot/stdout.expected
38 echo "M alpha" >> $testroot/stdout.expected
39 echo "D beta" >> $testroot/stdout.expected
40 echo "Created commit $head_rev" >> $testroot/stdout.expected
42 cmp -s $testroot/stdout.expected $testroot/stdout
44 if [ "$ret" != "0" ]; then
45 diff -u $testroot/stdout.expected $testroot/stdout
47 test_done "$testroot" "$ret"
50 function test_commit_new_subdir {
51 local testroot=`test_init commit_new_subdir`
53 got checkout $testroot/repo $testroot/wt > /dev/null
55 if [ "$ret" != "0" ]; then
56 test_done "$testroot" "$ret"
60 mkdir -p $testroot/wt/d
61 echo "new file" > $testroot/wt/d/new
62 echo "another new file" > $testroot/wt/d/new2
63 (cd $testroot/wt && got add d/new >/dev/null)
64 (cd $testroot/wt && got add d/new2 >/dev/null)
67 got commit -m 'test commit_new_subdir' > $testroot/stdout)
69 local head_rev=`git_show_head $testroot/repo`
70 echo "A d/new" > $testroot/stdout.expected
71 echo "A d/new2" >> $testroot/stdout.expected
72 echo "Created commit $head_rev" >> $testroot/stdout.expected
74 cmp -s $testroot/stdout.expected $testroot/stdout
76 if [ "$ret" != "0" ]; then
77 diff -u $testroot/stdout.expected $testroot/stdout
79 test_done "$testroot" "$ret"
82 function test_commit_subdir {
83 local testroot=`test_init commit_subdir`
85 got checkout $testroot/repo $testroot/wt > /dev/null
87 if [ "$ret" != "0" ]; then
88 test_done "$testroot" "$ret"
92 echo "modified alpha" > $testroot/wt/alpha
93 echo "modified zeta" > $testroot/wt/epsilon/zeta
96 got commit -m 'test commit_subdir' epsilon > $testroot/stdout)
98 local head_rev=`git_show_head $testroot/repo`
99 echo "M epsilon/zeta" >> $testroot/stdout.expected
100 echo "Created commit $head_rev" >> $testroot/stdout.expected
102 cmp -s $testroot/stdout.expected $testroot/stdout
104 if [ "$ret" != "0" ]; then
105 diff -u $testroot/stdout.expected $testroot/stdout
107 test_done "$testroot" "$ret"
110 function test_commit_single_file {
111 local testroot=`test_init commit_single_file`
113 got checkout $testroot/repo $testroot/wt > /dev/null
115 if [ "$ret" != "0" ]; then
116 test_done "$testroot" "$ret"
120 echo "modified alpha" > $testroot/wt/alpha
121 echo "modified zeta" > $testroot/wt/epsilon/zeta
123 (cd $testroot/wt && got commit -m 'changed zeta' epsilon/zeta \
126 local head_rev=`git_show_head $testroot/repo`
127 echo "M epsilon/zeta" >> $testroot/stdout.expected
128 echo "Created commit $head_rev" >> $testroot/stdout.expected
130 cmp -s $testroot/stdout.expected $testroot/stdout
132 if [ "$ret" != "0" ]; then
133 diff -u $testroot/stdout.expected $testroot/stdout
135 test_done "$testroot" "$ret"
138 function test_commit_out_of_date {
139 local testroot=`test_init commit_out_of_date`
140 local first_commit=`git_show_head $testroot/repo`
142 got checkout $testroot/repo $testroot/wt > /dev/null
144 if [ "$ret" != "0" ]; then
145 test_done "$testroot" "$ret"
149 echo "modified alpha" > $testroot/repo/alpha
150 git_commit $testroot/repo -m "modified alpha"
152 echo "modified alpha" > $testroot/wt/alpha
154 (cd $testroot/wt && got commit -m 'test commit_out_of_date' \
155 > $testroot/stdout 2> $testroot/stderr)
157 echo -n > $testroot/stdout.expected
158 echo "got: work tree must be updated before these" \
159 "changes can be committed" > $testroot/stderr.expected
161 cmp -s $testroot/stdout.expected $testroot/stdout
163 if [ "$ret" != "0" ]; then
164 diff -u $testroot/stdout.expected $testroot/stdout
165 test_done "$testroot" "$ret"
169 cmp -s $testroot/stderr.expected $testroot/stderr
171 if [ "$ret" != "0" ]; then
172 diff -u $testroot/stderr.expected $testroot/stderr
173 test_done "$testroot" "$ret"
177 echo "alpha" > $testroot/repo/alpha
178 git_commit $testroot/repo -m "reset alpha contents"
179 (cd $testroot/wt && got update -c $first_commit > /dev/null)
181 echo "modified alpha" > $testroot/wt/alpha
183 (cd $testroot/wt && got commit -m 'changed alpha ' > $testroot/stdout)
185 if [ "$ret" != "0" ]; then
186 echo "commit failed unexpectedly" >&2
187 test_done "$testroot" "1"
191 local head_rev=`git_show_head $testroot/repo`
192 echo "M alpha" > $testroot/stdout.expected
193 echo "Created commit $head_rev" >> $testroot/stdout.expected
194 cmp -s $testroot/stdout.expected $testroot/stdout
196 if [ "$ret" != "0" ]; then
197 diff -u $testroot/stdout.expected $testroot/stdout
199 test_done "$testroot" "$ret"
202 function test_commit_added_subdirs {
203 local testroot=`test_init commit_added_subdirs`
205 got checkout $testroot/repo $testroot/wt > /dev/null
207 if [ "$ret" != "0" ]; then
208 test_done "$testroot" "$ret"
212 mkdir -p $testroot/wt/d
213 echo "new file" > $testroot/wt/d/new
214 echo "new file 2" > $testroot/wt/d/new2
215 mkdir -p $testroot/wt/d/f
216 echo "new file 3" > $testroot/wt/d/f/new3
217 mkdir -p $testroot/wt/d/f/g
218 echo "new file 4" > $testroot/wt/d/f/g/new4
220 (cd $testroot/wt && got add $testroot/wt/*/new* \
221 $testroot/wt/*/*/new* $testroot/wt/*/*/*/new* > /dev/null)
223 (cd $testroot/wt && got commit -m 'test commit_added_subdirs' \
224 > $testroot/stdout 2> $testroot/stderr)
226 local head_rev=`git_show_head $testroot/repo`
227 echo "A d/f/g/new4" > $testroot/stdout.expected
228 echo "A d/f/new3" >> $testroot/stdout.expected
229 echo "A d/new" >> $testroot/stdout.expected
230 echo "A d/new2" >> $testroot/stdout.expected
231 echo "Created commit $head_rev" >> $testroot/stdout.expected
233 cmp -s $testroot/stdout.expected $testroot/stdout
235 if [ "$ret" != "0" ]; then
236 diff -u $testroot/stdout.expected $testroot/stdout
238 test_done "$testroot" "$ret"
241 function test_commit_deleted_subdirs {
242 local testroot=`test_init commit_deleted_subdirs`
244 got checkout $testroot/repo $testroot/wt > /dev/null
246 if [ "$ret" != "0" ]; then
247 test_done "$testroot" "$ret"
251 (cd $testroot/wt && got rm -R $testroot/wt/{epsilon,gamma} >/dev/null)
253 (cd $testroot/wt && got commit -m 'test commit_deleted_subdirs' \
254 > $testroot/stdout 2> $testroot/stderr)
256 local head_rev=`git_show_head $testroot/repo`
257 echo "D epsilon/zeta" > $testroot/stdout.expected
258 echo "D gamma/delta" >> $testroot/stdout.expected
259 echo "Created commit $head_rev" >> $testroot/stdout.expected
261 cmp -s $testroot/stdout.expected $testroot/stdout
263 if [ "$ret" != "0" ]; then
264 diff -u $testroot/stdout.expected $testroot/stdout
265 test_done "$testroot" "$ret"
269 got tree -r $testroot/repo > $testroot/stdout
271 echo "alpha" > $testroot/stdout.expected
272 echo "beta" >> $testroot/stdout.expected
274 cmp -s $testroot/stdout.expected $testroot/stdout
276 if [ "$ret" != "0" ]; then
277 diff -u $testroot/stdout.expected $testroot/stdout
279 test_done "$testroot" "$ret"
282 function test_commit_rejects_conflicted_file {
283 local testroot=`test_init commit_rejects_conflicted_file`
285 local initial_rev=`git_show_head $testroot/repo`
287 got checkout $testroot/repo $testroot/wt > /dev/null
289 if [ "$ret" != "0" ]; then
290 test_done "$testroot" "$ret"
294 echo "modified alpha" > $testroot/wt/alpha
295 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
297 (cd $testroot/wt && got update -c $initial_rev > /dev/null)
299 echo "modified alpha, too" > $testroot/wt/alpha
301 echo "C alpha" > $testroot/stdout.expected
302 echo -n "Updated to commit " >> $testroot/stdout.expected
303 git_show_head $testroot/repo >> $testroot/stdout.expected
304 echo >> $testroot/stdout.expected
305 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
307 (cd $testroot/wt && got update > $testroot/stdout)
309 cmp -s $testroot/stdout.expected $testroot/stdout
311 if [ "$ret" != "0" ]; then
312 diff -u $testroot/stdout.expected $testroot/stdout
313 test_done "$testroot" "$ret"
317 (cd $testroot/wt && got commit -m 'commit it' > $testroot/stdout \
320 echo -n > $testroot/stdout.expected
321 echo "got: cannot commit file in conflicted status" \
322 > $testroot/stderr.expected
324 cmp -s $testroot/stdout.expected $testroot/stdout
326 if [ "$ret" != "0" ]; then
327 diff -u $testroot/stdout.expected $testroot/stdout
328 test_done "$testroot" "$ret"
331 cmp -s $testroot/stderr.expected $testroot/stderr
333 if [ "$ret" != "0" ]; then
334 diff -u $testroot/stderr.expected $testroot/stderr
336 test_done "$testroot" "$ret"
339 function test_commit_single_file_multiple {
340 local testroot=`test_init commit_single_file_multiple`
342 got checkout $testroot/repo $testroot/wt > /dev/null
344 if [ "$ret" != "0" ]; then
345 test_done "$testroot" "$ret"
350 echo "modified alpha" >> $testroot/wt/alpha
352 (cd $testroot/wt && \
353 got commit -m "changed alpha" > $testroot/stdout)
355 local head_rev=`git_show_head $testroot/repo`
356 echo "M alpha" > $testroot/stdout.expected
357 echo "Created commit $head_rev" >> $testroot/stdout.expected
359 cmp -s $testroot/stdout.expected $testroot/stdout
361 if [ "$ret" != "0" ]; then
362 diff -u $testroot/stdout.expected $testroot/stdout
363 test_done "$testroot" "$ret"
368 test_done "$testroot" "0"
371 function test_commit_added_and_modified_in_same_dir {
372 local testroot=`test_init commit_added_and_modified_in_same_dir`
374 got checkout $testroot/repo $testroot/wt > /dev/null
376 if [ "$ret" != "0" ]; then
377 test_done "$testroot" "$ret"
381 echo "modified zeta" > $testroot/wt/epsilon/zeta
382 echo "new file" > $testroot/wt/epsilon/new
383 (cd $testroot/wt && got add epsilon/new >/dev/null)
385 (cd $testroot/wt && got commit \
386 -m 'added and modified in same dir' > $testroot/stdout \
389 local head_rev=`git_show_head $testroot/repo`
390 echo "A epsilon/new" > $testroot/stdout.expected
391 echo "M epsilon/zeta" >> $testroot/stdout.expected
392 echo "Created commit $head_rev" >> $testroot/stdout.expected
394 cmp -s $testroot/stdout.expected $testroot/stdout
396 if [ "$ret" != "0" ]; then
397 diff -u $testroot/stdout.expected $testroot/stdout
399 test_done "$testroot" "$ret"
402 function test_commit_path_prefix {
403 local testroot=`test_init commit_path_prefix`
404 local commit1=`git_show_head $testroot/repo`
406 got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
408 if [ "$ret" != "0" ]; then
409 test_done "$testroot" "$ret"
413 echo "modified delta" > $testroot/wt/delta
415 (cd $testroot/wt && got commit -m 'changed gamma/delta' > $testroot/stdout)
417 local commit2=`git_show_head $testroot/repo`
418 echo "M delta" > $testroot/stdout.expected
419 echo "Created commit $commit2" >> $testroot/stdout.expected
421 cmp -s $testroot/stdout.expected $testroot/stdout
423 if [ "$ret" != "0" ]; then
424 diff -u $testroot/stdout.expected $testroot/stdout
425 test_done "$testroot" "$ret"
429 echo "diff $commit1 $commit2" > $testroot/stdout.expected
430 echo -n 'blob - ' >> $testroot/stdout.expected
431 got tree -r $testroot/repo -c $commit1 -i gamma | grep 'delta$' \
432 | cut -d' ' -f 1 >> $testroot/stdout.expected
433 echo -n 'blob + ' >> $testroot/stdout.expected
434 got tree -r $testroot/repo -c $commit2 -i gamma | grep 'delta$' | \
435 cut -d' ' -f 1 >> $testroot/stdout.expected
436 echo '--- gamma/delta' >> $testroot/stdout.expected
437 echo '+++ gamma/delta' >> $testroot/stdout.expected
438 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
439 echo '-delta' >> $testroot/stdout.expected
440 echo '+modified delta' >> $testroot/stdout.expected
442 got diff -r $testroot/repo $commit1 $commit2 > $testroot/stdout
443 cmp -s $testroot/stdout.expected $testroot/stdout
445 if [ "$ret" != "0" ]; then
446 diff -u $testroot/stdout.expected $testroot/stdout
447 test_done "$testroot" "$ret"
451 (cd $testroot/wt && got rm delta > /dev/null)
452 echo new > $testroot/wt/new
453 (cd $testroot/wt && got add new > /dev/null)
455 (cd $testroot/wt && got commit -m 'remove gamma/delta; add gamma/new' \
458 local commit3=`git_show_head $testroot/repo`
459 echo "A new" > $testroot/stdout.expected
460 echo "D delta" >> $testroot/stdout.expected
461 echo "Created commit $commit3" >> $testroot/stdout.expected
463 cmp -s $testroot/stdout.expected $testroot/stdout
465 if [ "$ret" != "0" ]; then
466 diff -u $testroot/stdout.expected $testroot/stdout
467 test_done "$testroot" "$ret"
471 echo "diff $commit2 $commit3" > $testroot/stdout.expected
472 echo -n 'blob - ' >> $testroot/stdout.expected
473 got tree -r $testroot/repo -c $commit2 -i gamma | grep 'delta$' \
474 | cut -d' ' -f 1 | sed -e 's/$/ (mode 644)/' \
475 >> $testroot/stdout.expected
476 echo 'blob + /dev/null' >> $testroot/stdout.expected
477 echo '--- gamma/delta' >> $testroot/stdout.expected
478 echo '+++ /dev/null' >> $testroot/stdout.expected
479 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
480 echo '-modified delta' >> $testroot/stdout.expected
481 echo 'blob - /dev/null' >> $testroot/stdout.expected
482 echo -n 'blob + ' >> $testroot/stdout.expected
483 got tree -r $testroot/repo -c $commit3 -i gamma | grep 'new$' | \
484 cut -d' ' -f 1 | sed -e 's/$/ (mode 644)/' \
485 >> $testroot/stdout.expected
486 echo '--- /dev/null' >> $testroot/stdout.expected
487 echo '+++ gamma/new' >> $testroot/stdout.expected
488 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
489 echo '+new' >> $testroot/stdout.expected
491 got diff -r $testroot/repo $commit2 $commit3 > $testroot/stdout
492 cmp -s $testroot/stdout.expected $testroot/stdout
494 if [ "$ret" != "0" ]; then
495 diff -u $testroot/stdout.expected $testroot/stdout
497 test_done "$testroot" "$ret"
501 function test_commit_dir_path {
502 local testroot=`test_init commit_dir_path`
504 got checkout $testroot/repo $testroot/wt > /dev/null
506 if [ "$ret" != "0" ]; then
507 test_done "$testroot" "$ret"
511 echo "modified alpha" > $testroot/wt/alpha
512 echo "modified zeta" > $testroot/wt/epsilon/zeta
514 (cd $testroot/wt && got commit -m 'changed zeta' epsilon \
517 local head_rev=`git_show_head $testroot/repo`
518 echo "M epsilon/zeta" >> $testroot/stdout.expected
519 echo "Created commit $head_rev" >> $testroot/stdout.expected
521 cmp -s $testroot/stdout.expected $testroot/stdout
523 if [ "$ret" != "0" ]; then
524 diff -u $testroot/stdout.expected $testroot/stdout
525 test_done "$testroot" "$ret"
529 echo "M alpha" > $testroot/stdout.expected
530 (cd $testroot/wt && got status > $testroot/stdout)
531 cmp -s $testroot/stdout.expected $testroot/stdout
533 if [ "$ret" != "0" ]; then
534 diff -u $testroot/stdout.expected $testroot/stdout
536 test_done "$testroot" "$ret"
539 function test_commit_selected_paths {
540 local testroot=`test_init commit_selected_paths`
542 got checkout $testroot/repo $testroot/wt > /dev/null
544 if [ "$ret" != "0" ]; then
545 test_done "$testroot" "$ret"
549 echo "modified alpha" > $testroot/wt/alpha
550 echo "modified delta" > $testroot/wt/gamma/delta
551 echo "modified zeta" > $testroot/wt/epsilon/zeta
552 (cd $testroot/wt && got rm beta >/dev/null)
553 echo "new file" > $testroot/wt/new
554 (cd $testroot/wt && got add new >/dev/null)
556 (cd $testroot/wt && got commit -m 'many paths' nonexistent alpha \
557 > $testroot/stdout 2> $testroot/stderr)
559 if [ "$ret" == "0" ]; then
560 echo "commit succeeded unexpectedly" >&2
561 test_done "$testroot" "1"
564 echo "got: nonexistent: bad path" > $testroot/stderr.expected
566 cmp -s $testroot/stderr.expected $testroot/stderr
568 if [ "$ret" != "0" ]; then
569 diff -u $testroot/stderr.expected $testroot/stderr
570 test_done "$testroot" "$ret"
574 (cd $testroot/wt && got commit -m 'many paths' \
575 beta new gamma > $testroot/stdout)
577 local head_rev=`git_show_head $testroot/repo`
578 echo "A new" > $testroot/stdout.expected
579 echo "D beta" >> $testroot/stdout.expected
580 echo "M gamma/delta" >> $testroot/stdout.expected
581 echo "Created commit $head_rev" >> $testroot/stdout.expected
583 cmp -s $testroot/stdout.expected $testroot/stdout
585 if [ "$ret" != "0" ]; then
586 diff -u $testroot/stdout.expected $testroot/stdout
588 test_done "$testroot" "$ret"
591 function test_commit_outside_refs_heads {
592 local testroot=`test_init commit_outside_refs_heads`
594 got ref -r $testroot/repo -c master refs/remotes/origin/master
596 got checkout -b refs/remotes/origin/master \
597 $testroot/repo $testroot/wt > /dev/null
599 if [ "$ret" != "0" ]; then
600 test_done "$testroot" "$ret"
604 echo "modified alpha" > $testroot/wt/alpha
606 (cd $testroot/wt && got commit -m 'change alpha' \
607 > $testroot/stdout 2> $testroot/stderr)
609 if [ "$ret" == "0" ]; then
610 echo "commit succeeded unexpectedly" >&2
611 test_done "$testroot" "1"
615 echo -n > $testroot/stdout.expected
616 cmp -s $testroot/stdout.expected $testroot/stdout
618 if [ "$ret" != "0" ]; then
619 diff -u $testroot/stdout.expected $testroot/stdout
620 test_done "$testroot" "$ret"
624 echo -n "got: will not commit to a branch outside the " \
625 > $testroot/stderr.expected
626 echo '"refs/heads/" reference namespace' \
627 >> $testroot/stderr.expected
628 cmp -s $testroot/stderr.expected $testroot/stderr
630 if [ "$ret" != "0" ]; then
631 diff -u $testroot/stderr.expected $testroot/stderr
633 test_done "$testroot" "$ret"
636 function test_commit_no_email {
637 local testroot=`test_init commit_no_email`
639 got checkout $testroot/repo $testroot/wt > /dev/null
641 if [ "$ret" != "0" ]; then
642 test_done "$testroot" "$ret"
646 echo "modified alpha" > $testroot/wt/alpha
647 (cd $testroot/wt && env GOT_AUTHOR=":flan_hacker:" \
648 got commit -m 'test no email' > $testroot/stdout \
651 echo -n "got: GOT_AUTHOR environment variable contains no email " \
652 > $testroot/stderr.expected
653 echo -n "address; an email address is required for compatibility "\
654 >> $testroot/stderr.expected
655 echo "with Git" >> $testroot/stderr.expected
656 cmp -s $testroot/stderr.expected $testroot/stderr
658 if [ "$ret" != "0" ]; then
659 diff -u $testroot/stderr.expected $testroot/stderr
660 test_done "$testroot" "$ret"
664 echo -n > $testroot/stdout.expected
665 cmp -s $testroot/stdout.expected $testroot/stdout
667 if [ "$ret" != "0" ]; then
668 diff -u $testroot/stdout.expected $testroot/stdout
670 test_done "$testroot" "$ret"
673 function test_commit_tree_entry_sorting {
674 local testroot=`test_init commit_tree_entry_sorting`
676 got checkout $testroot/repo $testroot/wt > /dev/null
678 if [ "$ret" != "0" ]; then
679 test_done "$testroot" "$ret"
683 # Git's index gets corrupted when tree entries are written in the
684 # order defined by got_path_cmp() rather than Git's own ordering.
685 # Create a new tree where a directory "got" and a file "got-version"
686 # would sort in the wrong order according to Git's opinion.
687 mkdir $testroot/wt/got
688 touch $testroot/wt/got/foo
689 echo foo > $testroot/wt/got-version
690 echo zzz > $testroot/wt/zzz
691 (cd $testroot/wt && got add got-version got/foo zzz > /dev/null)
693 (cd $testroot/wt && got commit -m 'test' > /dev/null)
695 # Let git-fsck verify the newly written tree to make sure Git is happy
696 (cd $testroot/repo && git fsck --strict \
697 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
699 test_done "$testroot" "$ret"
702 function test_commit_gitconfig_author {
703 local testroot=`test_init commit_gitconfig_author`
705 got checkout $testroot/repo $testroot/wt > /dev/null
707 if [ "$ret" != "0" ]; then
708 test_done "$testroot" "$ret"
712 (cd $testroot/repo && git config user.name 'Flan Luck')
713 (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
715 echo "modified alpha" > $testroot/wt/alpha
716 (cd $testroot/wt && got commit -m 'test gitconfig author' > /dev/null)
718 if [ "$ret" != "0" ]; then
719 test_done "$testroot" "$ret"
723 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
725 if [ "$ret" != "0" ]; then
726 test_done "$testroot" "$ret"
730 echo "from: Flan Luck <flan_luck@openbsd.org>" \
731 > $testroot/stdout.expected
732 cmp -s $testroot/stdout.expected $testroot/stdout
734 if [ "$ret" != "0" ]; then
735 diff -u $testroot/stdout.expected $testroot/stdout
737 test_done "$testroot" "$ret"
740 function test_commit_xbit_change {
741 local testroot=`test_init commit_xbit_change`
743 got checkout $testroot/repo $testroot/wt > /dev/null
745 if [ "$ret" != "0" ]; then
746 test_done "$testroot" "$ret"
750 chmod +x $testroot/wt/alpha
752 echo 'm alpha' > $testroot/stdout.expected
753 (cd $testroot/wt && got status > $testroot/stdout)
755 cmp -s $testroot/stdout.expected $testroot/stdout
757 if [ "$ret" != "0" ]; then
758 diff -u $testroot/stdout.expected $testroot/stdout
759 test_done "$testroot" "$ret"
763 (cd $testroot/wt && got commit -mx > $testroot/stdout)
765 if [ "$ret" != "0" ]; then
766 echo "got commit failed unexpectedly"
767 test_done "$testroot" "$ret"
771 local commit_id=`git_show_head $testroot/repo`
772 echo 'm alpha' > $testroot/stdout.expected
773 echo "Created commit $commit_id" >> $testroot/stdout.expected
774 cmp -s $testroot/stdout.expected $testroot/stdout
776 if [ "$ret" != "0" ]; then
777 diff -u $testroot/stdout.expected $testroot/stdout
778 test_done "$testroot" "$ret"
782 (cd $testroot/wt && got status > $testroot/stdout)
784 echo -n > $testroot/stdout.expected
785 cmp -s $testroot/stdout.expected $testroot/stdout
787 if [ "$ret" != "0" ]; then
788 diff -u $testroot/stdout.expected $testroot/stdout
789 test_done "$testroot" "$ret"
793 chmod -x $testroot/wt/alpha
795 echo 'm alpha' > $testroot/stdout.expected
796 (cd $testroot/wt && got status > $testroot/stdout)
798 cmp -s $testroot/stdout.expected $testroot/stdout
800 if [ "$ret" != "0" ]; then
801 diff -u $testroot/stdout.expected $testroot/stdout
802 test_done "$testroot" "$ret"
806 (cd $testroot/wt && got commit -mx > $testroot/stdout)
808 if [ "$ret" != "0" ]; then
809 echo "got commit failed unexpectedly"
810 test_done "$testroot" "$ret"
814 local commit_id=`git_show_head $testroot/repo`
815 echo 'm alpha' > $testroot/stdout.expected
816 echo "Created commit $commit_id" >> $testroot/stdout.expected
817 cmp -s $testroot/stdout.expected $testroot/stdout
819 if [ "$ret" != "0" ]; then
820 diff -u $testroot/stdout.expected $testroot/stdout
821 test_done "$testroot" "$ret"
825 chmod +x $testroot/wt/alpha
827 echo 'm alpha' > $testroot/stdout.expected
828 (cd $testroot/wt && got status > $testroot/stdout)
830 cmp -s $testroot/stdout.expected $testroot/stdout
832 if [ "$ret" != "0" ]; then
833 diff -u $testroot/stdout.expected $testroot/stdout
835 test_done "$testroot" "$ret"
838 function commit_check_mode {
840 local expected_mode="$2"
842 chmod 644 $testroot/wt/alpha
843 echo a >> $testroot/wt/alpha
844 chmod $mode $testroot/wt/alpha
846 (cd $testroot/wt && got commit -mm > $testroot/stdout)
848 if [ "$ret" != "0" ]; then
849 echo "got commit failed unexpectedly"
850 test_done "$testroot" "$ret"
854 local commit_id=`git_show_head $testroot/repo`
855 echo 'M alpha' > $testroot/stdout.expected
856 echo "Created commit $commit_id" >> $testroot/stdout.expected
857 cmp -s $testroot/stdout.expected $testroot/stdout
859 if [ "$ret" != "0" ]; then
860 diff -u $testroot/stdout.expected $testroot/stdout
861 test_done "$testroot" "$ret"
864 local tree_id=$(got cat -r $testroot/repo $commit_id | \
865 grep ^tree | cut -d' ' -f2)
866 local alpha_id=$(got cat -r $testroot/repo $tree_id | \
867 grep 'alpha$' | cut -d' ' -f1)
868 echo "$alpha_id $expected_mode alpha" > $testroot/stdout.expected
869 got cat -r $testroot/repo $tree_id | grep 'alpha$' > $testroot/stdout
870 cmp -s $testroot/stdout.expected $testroot/stdout
872 if [ "$ret" != "0" ]; then
873 diff -u $testroot/stdout.expected $testroot/stdout
878 function test_commit_normalizes_filemodes {
879 local testroot=`test_init commit_normalizes_filemodes`
881 got checkout $testroot/repo $testroot/wt > /dev/null
883 if [ "$ret" != "0" ]; then
884 test_done "$testroot" "$ret"
888 modes="600 400 460 640 440 660 444 666"
890 commit_check_mode "$m" "0100644"
892 if [ "$ret" != "0" ]; then
896 if [ "$ret" != "0" ]; then
897 test_done "$testroot" "$ret"
900 modes="700 500 570 750 550 770 555 777"
902 commit_check_mode "$m" "0100755"
904 if [ "$ret" != "0" ]; then
908 if [ "$ret" != "0" ]; then
909 test_done "$testroot" "$ret"
912 test_done "$testroot" "$ret"
915 function test_commit_with_unrelated_submodule {
916 local testroot=`test_init commit_with_unrelated_submodule`
918 make_single_file_repo $testroot/repo2 foo
920 (cd $testroot/repo && git submodule -q add ../repo2)
921 (cd $testroot/repo && git commit -q -m 'adding submodule')
923 got checkout $testroot/repo $testroot/wt > /dev/null
925 if [ "$ret" != "0" ]; then
926 echo "checkout failed unexpectedly" >&2
927 test_done "$testroot" "$ret"
931 echo "modified alpha" > $testroot/wt/alpha
933 echo "" > $testroot/stdout.expected
935 (cd $testroot/wt && got commit -m 'modify alpha' > $testroot/stdout)
937 if [ "$ret" != "0" ]; then
938 echo "commit failed unexpectedly" >&2
939 test_done "$testroot" "$ret"
943 local head_rev=`git_show_head $testroot/repo`
944 echo "M alpha" > $testroot/stdout.expected
945 echo "Created commit $head_rev" >> $testroot/stdout.expected
947 cmp -s $testroot/stdout.expected $testroot/stdout
949 if [ "$ret" != "0" ]; then
950 diff -u $testroot/stdout.expected $testroot/stdout
952 test_done "$testroot" "$ret"
955 function check_symlinks {
957 if ! [ -h $wtpath/alpha.link ]; then
958 echo "alpha.link is not a symlink"
962 readlink $wtpath/alpha.link > $testroot/stdout
963 echo "alpha" > $testroot/stdout.expected
964 cmp -s $testroot/stdout.expected $testroot/stdout
966 if [ "$ret" != "0" ]; then
967 diff -u $testroot/stdout.expected $testroot/stdout
971 if ! [ -h $wtpath/epsilon.link ]; then
972 echo "epsilon.link is not a symlink"
976 readlink $wtpath/epsilon.link > $testroot/stdout
977 echo "epsilon" > $testroot/stdout.expected
978 cmp -s $testroot/stdout.expected $testroot/stdout
980 if [ "$ret" != "0" ]; then
981 diff -u $testroot/stdout.expected $testroot/stdout
985 if [ -h $wtpath/passwd.link ]; then
986 echo -n "passwd.link is a symlink and points outside of work tree: " >&2
987 readlink $wtpath/passwd.link >&2
991 echo -n "/etc/passwd" > $testroot/content.expected
992 cp $wtpath/passwd.link $testroot/content
994 if [ "$ret" != "0" ]; then
995 echo "cp command failed unexpectedly" >&2
999 cmp -s $testroot/content.expected $testroot/content
1001 if [ "$ret" != "0" ]; then
1002 diff -u $testroot/content.expected $testroot/content
1006 readlink $wtpath/epsilon/beta.link > $testroot/stdout
1007 echo "../beta" > $testroot/stdout.expected
1008 cmp -s $testroot/stdout.expected $testroot/stdout
1010 if [ "$ret" != "0" ]; then
1011 diff -u $testroot/stdout.expected $testroot/stdout
1015 readlink $wtpath/nonexistent.link > $testroot/stdout
1016 echo "nonexistent" > $testroot/stdout.expected
1017 cmp -s $testroot/stdout.expected $testroot/stdout
1019 if [ "$ret" != "0" ]; then
1020 diff -u $testroot/stdout.expected $testroot/stdout
1027 function test_commit_symlink {
1028 local testroot=`test_init commit_symlink`
1030 got checkout $testroot/repo $testroot/wt > /dev/null
1032 if [ "$ret" != "0" ]; then
1033 test_done "$testroot" "$ret"
1037 (cd $testroot/wt && ln -s alpha alpha.link)
1038 (cd $testroot/wt && ln -s epsilon epsilon.link)
1039 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1040 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
1041 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
1042 (cd $testroot/wt && got add alpha.link epsilon.link passwd.link \
1043 epsilon/beta.link nonexistent.link > /dev/null)
1045 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1046 > $testroot/stdout 2> $testroot/stderr)
1048 if [ "$ret" == "0" ]; then
1049 echo "got commit succeeded unexpectedly" >&2
1050 test_done "$testroot" "$ret"
1053 echo -n "got: $testroot/wt/passwd.link: " > $testroot/stderr.expected
1054 echo "symbolic link points outside of paths under version control" \
1055 >> $testroot/stderr.expected
1056 cmp -s $testroot/stderr.expected $testroot/stderr
1058 if [ "$ret" != "0" ]; then
1059 diff -u $testroot/stderr.expected $testroot/stderr
1060 test_done "$testroot" "$ret"
1064 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1067 local head_rev=`git_show_head $testroot/repo`
1068 echo "A alpha.link" > $testroot/stdout.expected
1069 echo "A epsilon.link" >> $testroot/stdout.expected
1070 echo "A nonexistent.link" >> $testroot/stdout.expected
1071 echo "A passwd.link" >> $testroot/stdout.expected
1072 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1073 echo "Created commit $head_rev" >> $testroot/stdout.expected
1075 cmp -s $testroot/stdout.expected $testroot/stdout
1077 if [ "$ret" != "0" ]; then
1078 diff -u $testroot/stdout.expected $testroot/stdout
1079 test_done "$testroot" "$ret"
1083 # verify created in-repository tree
1084 got checkout $testroot/repo $testroot/wt2 > /dev/null
1086 if [ "$ret" != "0" ]; then
1087 test_done "$testroot" "$ret"
1090 check_symlinks $testroot/wt2
1092 if [ "$ret" != "0" ]; then
1093 test_done "$testroot" "$ret"
1097 if ! [ -h $testroot/wt/passwd.link ]; then
1098 echo 'passwd.link is not a symlink' >&2
1099 test_done "$testroot" 1
1103 # 'got update' should reinstall passwd.link as a regular file
1104 (cd $testroot/wt && got update > /dev/null)
1105 check_symlinks $testroot/wt
1107 if [ "$ret" != "0" ]; then
1108 test_done "$testroot" "$ret"
1112 (cd $testroot/wt && ln -sf beta alpha.link)
1113 (cd $testroot/wt && ln -sfh gamma epsilon.link)
1114 rm $testroot/wt/epsilon/beta.link
1115 echo "this is a regular file" > $testroot/wt/epsilon/beta.link
1116 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
1117 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
1118 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
1119 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
1120 (cd $testroot/wt && ln -sf alpha new.link)
1121 (cd $testroot/wt && got add new.link > /dev/null)
1123 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1124 > $testroot/stdout 2> $testroot/stderr)
1126 if [ "$ret" == "0" ]; then
1127 echo "got commit succeeded unexpectedly" >&2
1128 test_done "$testroot" "$ret"
1131 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
1132 echo "symbolic link points outside of paths under version control" \
1133 >> $testroot/stderr.expected
1134 cmp -s $testroot/stderr.expected $testroot/stderr
1136 if [ "$ret" != "0" ]; then
1137 diff -u $testroot/stderr.expected $testroot/stderr
1138 test_done "$testroot" "$ret"
1142 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1145 local head_rev=`git_show_head $testroot/repo`
1146 echo "A dotgotbar.link" > $testroot/stdout.expected
1147 echo "A new.link" >> $testroot/stdout.expected
1148 echo "M alpha.link" >> $testroot/stdout.expected
1149 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1150 echo "M epsilon.link" >> $testroot/stdout.expected
1151 echo "D nonexistent.link" >> $testroot/stdout.expected
1152 echo "Created commit $head_rev" >> $testroot/stdout.expected
1154 cmp -s $testroot/stdout.expected $testroot/stdout
1156 if [ "$ret" != "0" ]; then
1157 diff -u $testroot/stdout.expected $testroot/stdout
1158 test_done "$testroot" "$ret"
1162 got tree -r $testroot/repo -c $head_rev -R > $testroot/stdout
1163 cat > $testroot/stdout.expected <<EOF
1167 dotgotbar.link@ -> .got/bar
1171 epsilon.link@ -> gamma
1175 passwd.link@ -> /etc/passwd
1177 cmp -s $testroot/stdout.expected $testroot/stdout
1179 if [ "$ret" != "0" ]; then
1180 diff -u $testroot/stdout.expected $testroot/stdout
1182 test_done "$testroot" "$ret"
1185 function test_commit_fix_bad_symlink {
1186 local testroot=`test_init commit_fix_bad_symlink`
1188 got checkout $testroot/repo $testroot/wt > /dev/null
1190 if [ "$ret" != "0" ]; then
1191 echo "got checkout failed unexpectedly" >&2
1192 test_done "$testroot" "$ret"
1196 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1197 (cd $testroot/wt && got add passwd.link > /dev/null)
1199 (cd $testroot/wt && got commit -S -m 'commit bad symlink' \
1202 if ! [ -h $testroot/wt/passwd.link ]; then
1203 echo 'passwd.link is not a symlink' >&2
1204 test_done "$testroot" 1
1207 (cd $testroot/wt && got update >/dev/null)
1208 if [ -h $testroot/wt/passwd.link ]; then
1209 echo "passwd.link is a symlink but should be a regular file" >&2
1210 test_done "$testroot" "1"
1214 # create another work tree which will contain the "bad" symlink
1215 got checkout $testroot/repo $testroot/wt2 > /dev/null
1217 if [ "$ret" != "0" ]; then
1218 echo "got checkout failed unexpectedly" >&2
1219 test_done "$testroot" "$ret"
1223 # change "bad" symlink back into a "good" symlink
1224 (cd $testroot/wt && ln -sfh alpha passwd.link)
1226 (cd $testroot/wt && got commit -m 'fix bad symlink' \
1229 local head_rev=`git_show_head $testroot/repo`
1230 echo "M passwd.link" > $testroot/stdout.expected
1231 echo "Created commit $head_rev" >> $testroot/stdout.expected
1233 cmp -s $testroot/stdout.expected $testroot/stdout
1235 if [ "$ret" != "0" ]; then
1236 diff -u $testroot/stdout.expected $testroot/stdout
1237 test_done "$testroot" "$ret"
1241 if ! [ -h $testroot/wt/passwd.link ]; then
1242 echo 'passwd.link is not a symlink' >&2
1243 test_done "$testroot" 1
1247 readlink $testroot/wt/passwd.link > $testroot/stdout
1248 echo "alpha" > $testroot/stdout.expected
1249 cmp -s $testroot/stdout.expected $testroot/stdout
1251 if [ "$ret" != "0" ]; then
1252 diff -u $testroot/stdout.expected $testroot/stdout
1256 # Update the other work tree; the bad symlink should be fixed
1257 (cd $testroot/wt2 && got update > /dev/null)
1259 if [ "$ret" != "0" ]; then
1260 echo "got checkout failed unexpectedly" >&2
1261 test_done "$testroot" "$ret"
1265 if ! [ -h $testroot/wt2/passwd.link ]; then
1266 echo 'passwd.link is not a symlink' >&2
1267 test_done "$testroot" 1
1271 readlink $testroot/wt2/passwd.link > $testroot/stdout
1272 echo "alpha" > $testroot/stdout.expected
1273 cmp -s $testroot/stdout.expected $testroot/stdout
1275 if [ "$ret" != "0" ]; then
1276 diff -u $testroot/stdout.expected $testroot/stdout
1280 test_done "$testroot" "0"
1284 run_test test_commit_basic
1285 run_test test_commit_new_subdir
1286 run_test test_commit_subdir
1287 run_test test_commit_single_file
1288 run_test test_commit_out_of_date
1289 run_test test_commit_added_subdirs
1290 run_test test_commit_deleted_subdirs
1291 run_test test_commit_rejects_conflicted_file
1292 run_test test_commit_single_file_multiple
1293 run_test test_commit_added_and_modified_in_same_dir
1294 run_test test_commit_path_prefix
1295 run_test test_commit_dir_path
1296 run_test test_commit_selected_paths
1297 run_test test_commit_outside_refs_heads
1298 run_test test_commit_no_email
1299 run_test test_commit_tree_entry_sorting
1300 run_test test_commit_gitconfig_author
1301 run_test test_commit_xbit_change
1302 run_test test_commit_normalizes_filemodes
1303 run_test test_commit_with_unrelated_submodule
1304 run_test test_commit_symlink
1305 run_test test_commit_fix_bad_symlink