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_gotconfig_author {
703 local testroot=`test_init commit_gotconfig_author`
705 got checkout $testroot/repo $testroot/wt > /dev/null
707 if [ "$ret" != "0" ]; then
708 test_done "$testroot" "$ret"
711 echo 'author "Flan Luck <flan_luck@openbsd.org>"' \
712 > $testroot/repo/.git/got.conf
714 echo "modified alpha" > $testroot/wt/alpha
715 (cd $testroot/wt && got commit -m 'test gotconfig author' > /dev/null)
717 if [ "$ret" != "0" ]; then
718 test_done "$testroot" "$ret"
722 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
724 if [ "$ret" != "0" ]; then
725 test_done "$testroot" "$ret"
729 echo "from: Flan Luck <flan_luck@openbsd.org>" \
730 > $testroot/stdout.expected
731 cmp -s $testroot/stdout.expected $testroot/stdout
733 if [ "$ret" != "0" ]; then
734 diff -u $testroot/stdout.expected $testroot/stdout
736 test_done "$testroot" "$ret"
739 function test_commit_gitconfig_author {
740 local testroot=`test_init commit_gitconfig_author`
742 got checkout $testroot/repo $testroot/wt > /dev/null
744 if [ "$ret" != "0" ]; then
745 test_done "$testroot" "$ret"
749 (cd $testroot/repo && git config user.name 'Flan Luck')
750 (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
752 echo "modified alpha" > $testroot/wt/alpha
753 (cd $testroot/wt && got commit -m 'test gitconfig author' > /dev/null)
755 if [ "$ret" != "0" ]; then
756 test_done "$testroot" "$ret"
760 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
762 if [ "$ret" != "0" ]; then
763 test_done "$testroot" "$ret"
767 echo "from: Flan Luck <flan_luck@openbsd.org>" \
768 > $testroot/stdout.expected
769 cmp -s $testroot/stdout.expected $testroot/stdout
771 if [ "$ret" != "0" ]; then
772 diff -u $testroot/stdout.expected $testroot/stdout
774 test_done "$testroot" "$ret"
777 function test_commit_xbit_change {
778 local testroot=`test_init commit_xbit_change`
780 got checkout $testroot/repo $testroot/wt > /dev/null
782 if [ "$ret" != "0" ]; then
783 test_done "$testroot" "$ret"
787 chmod +x $testroot/wt/alpha
789 echo 'm alpha' > $testroot/stdout.expected
790 (cd $testroot/wt && got status > $testroot/stdout)
792 cmp -s $testroot/stdout.expected $testroot/stdout
794 if [ "$ret" != "0" ]; then
795 diff -u $testroot/stdout.expected $testroot/stdout
796 test_done "$testroot" "$ret"
800 (cd $testroot/wt && got commit -mx > $testroot/stdout)
802 if [ "$ret" != "0" ]; then
803 echo "got commit failed unexpectedly"
804 test_done "$testroot" "$ret"
808 local commit_id=`git_show_head $testroot/repo`
809 echo 'm alpha' > $testroot/stdout.expected
810 echo "Created commit $commit_id" >> $testroot/stdout.expected
811 cmp -s $testroot/stdout.expected $testroot/stdout
813 if [ "$ret" != "0" ]; then
814 diff -u $testroot/stdout.expected $testroot/stdout
815 test_done "$testroot" "$ret"
819 (cd $testroot/wt && got status > $testroot/stdout)
821 echo -n > $testroot/stdout.expected
822 cmp -s $testroot/stdout.expected $testroot/stdout
824 if [ "$ret" != "0" ]; then
825 diff -u $testroot/stdout.expected $testroot/stdout
826 test_done "$testroot" "$ret"
830 chmod -x $testroot/wt/alpha
832 echo 'm alpha' > $testroot/stdout.expected
833 (cd $testroot/wt && got status > $testroot/stdout)
835 cmp -s $testroot/stdout.expected $testroot/stdout
837 if [ "$ret" != "0" ]; then
838 diff -u $testroot/stdout.expected $testroot/stdout
839 test_done "$testroot" "$ret"
843 (cd $testroot/wt && got commit -mx > $testroot/stdout)
845 if [ "$ret" != "0" ]; then
846 echo "got commit failed unexpectedly"
847 test_done "$testroot" "$ret"
851 local commit_id=`git_show_head $testroot/repo`
852 echo 'm alpha' > $testroot/stdout.expected
853 echo "Created commit $commit_id" >> $testroot/stdout.expected
854 cmp -s $testroot/stdout.expected $testroot/stdout
856 if [ "$ret" != "0" ]; then
857 diff -u $testroot/stdout.expected $testroot/stdout
858 test_done "$testroot" "$ret"
862 chmod +x $testroot/wt/alpha
864 echo 'm alpha' > $testroot/stdout.expected
865 (cd $testroot/wt && got status > $testroot/stdout)
867 cmp -s $testroot/stdout.expected $testroot/stdout
869 if [ "$ret" != "0" ]; then
870 diff -u $testroot/stdout.expected $testroot/stdout
872 test_done "$testroot" "$ret"
875 function commit_check_mode {
877 local expected_mode="$2"
879 chmod 644 $testroot/wt/alpha
880 echo a >> $testroot/wt/alpha
881 chmod $mode $testroot/wt/alpha
883 (cd $testroot/wt && got commit -mm > $testroot/stdout)
885 if [ "$ret" != "0" ]; then
886 echo "got commit failed unexpectedly"
887 test_done "$testroot" "$ret"
891 local commit_id=`git_show_head $testroot/repo`
892 echo 'M alpha' > $testroot/stdout.expected
893 echo "Created commit $commit_id" >> $testroot/stdout.expected
894 cmp -s $testroot/stdout.expected $testroot/stdout
896 if [ "$ret" != "0" ]; then
897 diff -u $testroot/stdout.expected $testroot/stdout
898 test_done "$testroot" "$ret"
901 local tree_id=$(got cat -r $testroot/repo $commit_id | \
902 grep ^tree | cut -d' ' -f2)
903 local alpha_id=$(got cat -r $testroot/repo $tree_id | \
904 grep 'alpha$' | cut -d' ' -f1)
905 echo "$alpha_id $expected_mode alpha" > $testroot/stdout.expected
906 got cat -r $testroot/repo $tree_id | grep 'alpha$' > $testroot/stdout
907 cmp -s $testroot/stdout.expected $testroot/stdout
909 if [ "$ret" != "0" ]; then
910 diff -u $testroot/stdout.expected $testroot/stdout
915 function test_commit_normalizes_filemodes {
916 local testroot=`test_init commit_normalizes_filemodes`
918 got checkout $testroot/repo $testroot/wt > /dev/null
920 if [ "$ret" != "0" ]; then
921 test_done "$testroot" "$ret"
925 modes="600 400 460 640 440 660 444 666"
927 commit_check_mode "$m" "0100644"
929 if [ "$ret" != "0" ]; then
933 if [ "$ret" != "0" ]; then
934 test_done "$testroot" "$ret"
937 modes="700 500 570 750 550 770 555 777"
939 commit_check_mode "$m" "0100755"
941 if [ "$ret" != "0" ]; then
945 if [ "$ret" != "0" ]; then
946 test_done "$testroot" "$ret"
949 test_done "$testroot" "$ret"
952 function test_commit_with_unrelated_submodule {
953 local testroot=`test_init commit_with_unrelated_submodule`
955 make_single_file_repo $testroot/repo2 foo
957 (cd $testroot/repo && git submodule -q add ../repo2)
958 (cd $testroot/repo && git commit -q -m 'adding submodule')
960 got checkout $testroot/repo $testroot/wt > /dev/null
962 if [ "$ret" != "0" ]; then
963 echo "checkout failed unexpectedly" >&2
964 test_done "$testroot" "$ret"
968 echo "modified alpha" > $testroot/wt/alpha
970 echo "" > $testroot/stdout.expected
972 (cd $testroot/wt && got commit -m 'modify alpha' > $testroot/stdout)
974 if [ "$ret" != "0" ]; then
975 echo "commit failed unexpectedly" >&2
976 test_done "$testroot" "$ret"
980 local head_rev=`git_show_head $testroot/repo`
981 echo "M alpha" > $testroot/stdout.expected
982 echo "Created commit $head_rev" >> $testroot/stdout.expected
984 cmp -s $testroot/stdout.expected $testroot/stdout
986 if [ "$ret" != "0" ]; then
987 diff -u $testroot/stdout.expected $testroot/stdout
989 test_done "$testroot" "$ret"
992 function check_symlinks {
994 if ! [ -h $wtpath/alpha.link ]; then
995 echo "alpha.link is not a symlink"
999 readlink $wtpath/alpha.link > $testroot/stdout
1000 echo "alpha" > $testroot/stdout.expected
1001 cmp -s $testroot/stdout.expected $testroot/stdout
1003 if [ "$ret" != "0" ]; then
1004 diff -u $testroot/stdout.expected $testroot/stdout
1008 if ! [ -h $wtpath/epsilon.link ]; then
1009 echo "epsilon.link is not a symlink"
1013 readlink $wtpath/epsilon.link > $testroot/stdout
1014 echo "epsilon" > $testroot/stdout.expected
1015 cmp -s $testroot/stdout.expected $testroot/stdout
1017 if [ "$ret" != "0" ]; then
1018 diff -u $testroot/stdout.expected $testroot/stdout
1022 if [ -h $wtpath/passwd.link ]; then
1023 echo -n "passwd.link is a symlink and points outside of work tree: " >&2
1024 readlink $wtpath/passwd.link >&2
1028 echo -n "/etc/passwd" > $testroot/content.expected
1029 cp $wtpath/passwd.link $testroot/content
1031 if [ "$ret" != "0" ]; then
1032 echo "cp command failed unexpectedly" >&2
1036 cmp -s $testroot/content.expected $testroot/content
1038 if [ "$ret" != "0" ]; then
1039 diff -u $testroot/content.expected $testroot/content
1043 readlink $wtpath/epsilon/beta.link > $testroot/stdout
1044 echo "../beta" > $testroot/stdout.expected
1045 cmp -s $testroot/stdout.expected $testroot/stdout
1047 if [ "$ret" != "0" ]; then
1048 diff -u $testroot/stdout.expected $testroot/stdout
1052 readlink $wtpath/nonexistent.link > $testroot/stdout
1053 echo "nonexistent" > $testroot/stdout.expected
1054 cmp -s $testroot/stdout.expected $testroot/stdout
1056 if [ "$ret" != "0" ]; then
1057 diff -u $testroot/stdout.expected $testroot/stdout
1064 function test_commit_symlink {
1065 local testroot=`test_init commit_symlink`
1067 got checkout $testroot/repo $testroot/wt > /dev/null
1069 if [ "$ret" != "0" ]; then
1070 test_done "$testroot" "$ret"
1074 (cd $testroot/wt && ln -s alpha alpha.link)
1075 (cd $testroot/wt && ln -s epsilon epsilon.link)
1076 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1077 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
1078 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
1079 (cd $testroot/wt && got add alpha.link epsilon.link passwd.link \
1080 epsilon/beta.link nonexistent.link > /dev/null)
1082 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1083 > $testroot/stdout 2> $testroot/stderr)
1085 if [ "$ret" == "0" ]; then
1086 echo "got commit succeeded unexpectedly" >&2
1087 test_done "$testroot" "$ret"
1090 echo -n "got: $testroot/wt/passwd.link: " > $testroot/stderr.expected
1091 echo "symbolic link points outside of paths under version control" \
1092 >> $testroot/stderr.expected
1093 cmp -s $testroot/stderr.expected $testroot/stderr
1095 if [ "$ret" != "0" ]; then
1096 diff -u $testroot/stderr.expected $testroot/stderr
1097 test_done "$testroot" "$ret"
1101 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1104 local head_rev=`git_show_head $testroot/repo`
1105 echo "A alpha.link" > $testroot/stdout.expected
1106 echo "A epsilon.link" >> $testroot/stdout.expected
1107 echo "A nonexistent.link" >> $testroot/stdout.expected
1108 echo "A passwd.link" >> $testroot/stdout.expected
1109 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1110 echo "Created commit $head_rev" >> $testroot/stdout.expected
1112 cmp -s $testroot/stdout.expected $testroot/stdout
1114 if [ "$ret" != "0" ]; then
1115 diff -u $testroot/stdout.expected $testroot/stdout
1116 test_done "$testroot" "$ret"
1120 # verify created in-repository tree
1121 got checkout $testroot/repo $testroot/wt2 > /dev/null
1123 if [ "$ret" != "0" ]; then
1124 test_done "$testroot" "$ret"
1127 check_symlinks $testroot/wt2
1129 if [ "$ret" != "0" ]; then
1130 test_done "$testroot" "$ret"
1134 if ! [ -h $testroot/wt/passwd.link ]; then
1135 echo 'passwd.link is not a symlink' >&2
1136 test_done "$testroot" 1
1140 # 'got update' should reinstall passwd.link as a regular file
1141 (cd $testroot/wt && got update > /dev/null)
1142 check_symlinks $testroot/wt
1144 if [ "$ret" != "0" ]; then
1145 test_done "$testroot" "$ret"
1149 (cd $testroot/wt && ln -sf beta alpha.link)
1150 (cd $testroot/wt && ln -sfh gamma epsilon.link)
1151 rm $testroot/wt/epsilon/beta.link
1152 echo "this is a regular file" > $testroot/wt/epsilon/beta.link
1153 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
1154 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
1155 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
1156 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
1157 (cd $testroot/wt && ln -sf alpha new.link)
1158 (cd $testroot/wt && got add new.link > /dev/null)
1160 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1161 > $testroot/stdout 2> $testroot/stderr)
1163 if [ "$ret" == "0" ]; then
1164 echo "got commit succeeded unexpectedly" >&2
1165 test_done "$testroot" "$ret"
1168 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
1169 echo "symbolic link points outside of paths under version control" \
1170 >> $testroot/stderr.expected
1171 cmp -s $testroot/stderr.expected $testroot/stderr
1173 if [ "$ret" != "0" ]; then
1174 diff -u $testroot/stderr.expected $testroot/stderr
1175 test_done "$testroot" "$ret"
1179 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1182 local head_rev=`git_show_head $testroot/repo`
1183 echo "A dotgotbar.link" > $testroot/stdout.expected
1184 echo "A new.link" >> $testroot/stdout.expected
1185 echo "M alpha.link" >> $testroot/stdout.expected
1186 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1187 echo "M epsilon.link" >> $testroot/stdout.expected
1188 echo "D nonexistent.link" >> $testroot/stdout.expected
1189 echo "Created commit $head_rev" >> $testroot/stdout.expected
1191 cmp -s $testroot/stdout.expected $testroot/stdout
1193 if [ "$ret" != "0" ]; then
1194 diff -u $testroot/stdout.expected $testroot/stdout
1195 test_done "$testroot" "$ret"
1199 got tree -r $testroot/repo -c $head_rev -R > $testroot/stdout
1200 cat > $testroot/stdout.expected <<EOF
1204 dotgotbar.link@ -> .got/bar
1208 epsilon.link@ -> gamma
1212 passwd.link@ -> /etc/passwd
1214 cmp -s $testroot/stdout.expected $testroot/stdout
1216 if [ "$ret" != "0" ]; then
1217 diff -u $testroot/stdout.expected $testroot/stdout
1219 test_done "$testroot" "$ret"
1222 function test_commit_fix_bad_symlink {
1223 local testroot=`test_init commit_fix_bad_symlink`
1225 got checkout $testroot/repo $testroot/wt > /dev/null
1227 if [ "$ret" != "0" ]; then
1228 echo "got checkout failed unexpectedly" >&2
1229 test_done "$testroot" "$ret"
1233 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1234 (cd $testroot/wt && got add passwd.link > /dev/null)
1236 (cd $testroot/wt && got commit -S -m 'commit bad symlink' \
1239 if ! [ -h $testroot/wt/passwd.link ]; then
1240 echo 'passwd.link is not a symlink' >&2
1241 test_done "$testroot" 1
1244 (cd $testroot/wt && got update >/dev/null)
1245 if [ -h $testroot/wt/passwd.link ]; then
1246 echo "passwd.link is a symlink but should be a regular file" >&2
1247 test_done "$testroot" "1"
1251 # create another work tree which will contain the "bad" symlink
1252 got checkout $testroot/repo $testroot/wt2 > /dev/null
1254 if [ "$ret" != "0" ]; then
1255 echo "got checkout failed unexpectedly" >&2
1256 test_done "$testroot" "$ret"
1260 # change "bad" symlink back into a "good" symlink
1261 (cd $testroot/wt && ln -sfh alpha passwd.link)
1263 (cd $testroot/wt && got commit -m 'fix bad symlink' \
1266 local head_rev=`git_show_head $testroot/repo`
1267 echo "M passwd.link" > $testroot/stdout.expected
1268 echo "Created commit $head_rev" >> $testroot/stdout.expected
1270 cmp -s $testroot/stdout.expected $testroot/stdout
1272 if [ "$ret" != "0" ]; then
1273 diff -u $testroot/stdout.expected $testroot/stdout
1274 test_done "$testroot" "$ret"
1278 if ! [ -h $testroot/wt/passwd.link ]; then
1279 echo 'passwd.link is not a symlink' >&2
1280 test_done "$testroot" 1
1284 readlink $testroot/wt/passwd.link > $testroot/stdout
1285 echo "alpha" > $testroot/stdout.expected
1286 cmp -s $testroot/stdout.expected $testroot/stdout
1288 if [ "$ret" != "0" ]; then
1289 diff -u $testroot/stdout.expected $testroot/stdout
1293 # Update the other work tree; the bad symlink should be fixed
1294 (cd $testroot/wt2 && got update > /dev/null)
1296 if [ "$ret" != "0" ]; then
1297 echo "got checkout failed unexpectedly" >&2
1298 test_done "$testroot" "$ret"
1302 if ! [ -h $testroot/wt2/passwd.link ]; then
1303 echo 'passwd.link is not a symlink' >&2
1304 test_done "$testroot" 1
1308 readlink $testroot/wt2/passwd.link > $testroot/stdout
1309 echo "alpha" > $testroot/stdout.expected
1310 cmp -s $testroot/stdout.expected $testroot/stdout
1312 if [ "$ret" != "0" ]; then
1313 diff -u $testroot/stdout.expected $testroot/stdout
1317 test_done "$testroot" "0"
1321 run_test test_commit_basic
1322 run_test test_commit_new_subdir
1323 run_test test_commit_subdir
1324 run_test test_commit_single_file
1325 run_test test_commit_out_of_date
1326 run_test test_commit_added_subdirs
1327 run_test test_commit_deleted_subdirs
1328 run_test test_commit_rejects_conflicted_file
1329 run_test test_commit_single_file_multiple
1330 run_test test_commit_added_and_modified_in_same_dir
1331 run_test test_commit_path_prefix
1332 run_test test_commit_dir_path
1333 run_test test_commit_selected_paths
1334 run_test test_commit_outside_refs_heads
1335 run_test test_commit_no_email
1336 run_test test_commit_tree_entry_sorting
1337 run_test test_commit_gotconfig_author
1338 run_test test_commit_gitconfig_author
1339 run_test test_commit_xbit_change
1340 run_test test_commit_normalizes_filemodes
1341 run_test test_commit_with_unrelated_submodule
1342 run_test test_commit_symlink
1343 run_test test_commit_fix_bad_symlink