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.
20 local testroot=`test_init commit_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
24 if [ $ret -ne 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 -ne 0 ]; then
45 diff -u $testroot/stdout.expected $testroot/stdout
47 test_done "$testroot" "$ret"
50 test_commit_new_subdir() {
51 local testroot=`test_init commit_new_subdir`
53 got checkout $testroot/repo $testroot/wt > /dev/null
55 if [ $ret -ne 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 -ne 0 ]; then
77 diff -u $testroot/stdout.expected $testroot/stdout
79 test_done "$testroot" "$ret"
82 test_commit_subdir() {
83 local testroot=`test_init commit_subdir`
85 got checkout $testroot/repo $testroot/wt > /dev/null
87 if [ $ret -ne 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 -ne 0 ]; then
105 diff -u $testroot/stdout.expected $testroot/stdout
107 test_done "$testroot" "$ret"
110 test_commit_single_file() {
111 local testroot=`test_init commit_single_file`
113 got checkout $testroot/repo $testroot/wt > /dev/null
115 if [ $ret -ne 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 -ne 0 ]; then
133 diff -u $testroot/stdout.expected $testroot/stdout
135 test_done "$testroot" "$ret"
138 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 0 ]; then
197 diff -u $testroot/stdout.expected $testroot/stdout
199 test_done "$testroot" "$ret"
202 test_commit_added_subdirs() {
203 local testroot=`test_init commit_added_subdirs`
205 got checkout $testroot/repo $testroot/wt > /dev/null
207 if [ $ret -ne 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 -ne 0 ]; then
236 diff -u $testroot/stdout.expected $testroot/stdout
238 test_done "$testroot" "$ret"
241 test_commit_deleted_subdirs() {
242 local testroot=`test_init commit_deleted_subdirs`
244 got checkout $testroot/repo $testroot/wt > /dev/null
246 if [ $ret -ne 0 ]; then
247 test_done "$testroot" "$ret"
251 (cd $testroot/wt && \
252 got rm -R $testroot/wt/epsilon $testroot/wt/gamma >/dev/null)
254 (cd $testroot/wt && got commit -m 'test commit_deleted_subdirs' \
255 > $testroot/stdout 2> $testroot/stderr)
257 local head_rev=`git_show_head $testroot/repo`
258 echo "D epsilon/zeta" > $testroot/stdout.expected
259 echo "D gamma/delta" >> $testroot/stdout.expected
260 echo "Created commit $head_rev" >> $testroot/stdout.expected
262 cmp -s $testroot/stdout.expected $testroot/stdout
264 if [ $ret -ne 0 ]; then
265 diff -u $testroot/stdout.expected $testroot/stdout
266 test_done "$testroot" "$ret"
270 got tree -r $testroot/repo > $testroot/stdout
272 echo "alpha" > $testroot/stdout.expected
273 echo "beta" >> $testroot/stdout.expected
275 cmp -s $testroot/stdout.expected $testroot/stdout
277 if [ $ret -ne 0 ]; then
278 diff -u $testroot/stdout.expected $testroot/stdout
280 test_done "$testroot" "$ret"
283 test_commit_rejects_conflicted_file() {
284 local testroot=`test_init commit_rejects_conflicted_file`
286 local initial_rev=`git_show_head $testroot/repo`
288 got checkout $testroot/repo $testroot/wt > /dev/null
290 if [ $ret -ne 0 ]; then
291 test_done "$testroot" "$ret"
295 echo "modified alpha" > $testroot/wt/alpha
296 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
297 local commit_id1=`git_show_head $testroot/repo`
299 (cd $testroot/wt && got update -c $initial_rev > /dev/null)
301 echo "modified alpha, too" > $testroot/wt/alpha
303 echo "C alpha" > $testroot/stdout.expected
304 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
305 git_show_head $testroot/repo >> $testroot/stdout.expected
306 echo >> $testroot/stdout.expected
307 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
309 (cd $testroot/wt && got update > $testroot/stdout)
311 cmp -s $testroot/stdout.expected $testroot/stdout
313 if [ $ret -ne 0 ]; then
314 diff -u $testroot/stdout.expected $testroot/stdout
315 test_done "$testroot" "$ret"
319 (cd $testroot/wt && got commit -m 'commit it' > $testroot/stdout \
322 if [ $ret -eq 0 ]; then
323 echo "got commit succeeded unexpectedly"
324 test_done "$testroot" "$ret"
328 echo "C alpha" > $testroot/stdout.expected
329 echo "got: cannot commit file in conflicted status" \
330 > $testroot/stderr.expected
332 cmp -s $testroot/stdout.expected $testroot/stdout
334 if [ $ret -ne 0 ]; then
335 diff -u $testroot/stdout.expected $testroot/stdout
336 test_done "$testroot" "$ret"
339 cmp -s $testroot/stderr.expected $testroot/stderr
341 if [ $ret -ne 0 ]; then
342 diff -u $testroot/stderr.expected $testroot/stderr
343 test_done "$testroot" "$ret"
347 (cd $testroot/wt && got commit -C -m 'commit it' > $testroot/stdout \
350 if [ $ret -ne 0 ]; then
351 echo "got commit failed unexpectedly"
352 test_done "$testroot" "$ret"
356 # make sure the conflicted commit produces a diff
357 local conflict_commit=`git_show_head $testroot/repo`
358 local blob_minus=`got tree -r $testroot/repo -c $commit_id1 -i | \
359 grep 'alpha$' | cut -d' ' -f1`
360 local blob_plus=`got tree -r $testroot/repo -c $conflict_commit -i | \
361 grep 'alpha$' | cut -d' ' -f1`
363 echo -n > $testroot/stderr.expected
364 cmp -s $testroot/stderr.expected $testroot/stderr
366 if [ $ret -ne 0 ]; then
367 diff -u $testroot/stderr.expected $testroot/stderr
368 test_done "$testroot" "$ret"
372 (cd $testroot/wt && got diff -c master > $testroot/stdout)
374 echo -n > $testroot/stdout.expected
375 cat > $testroot/stdout.expected <<EOF
376 diff $commit_id1 refs/heads/master
378 commit + $conflict_commit
384 +<<<<<<< merged change: commit $commit_id1
386 +||||||| 3-way merge base: commit $initial_rev
393 cmp -s $testroot/stdout.expected $testroot/stdout
395 if [ $ret -ne 0 ]; then
396 diff -u $testroot/stdout.expected $testroot/stdout
397 test_done "$testroot" "$ret"
401 (cd $testroot/wt && got status > $testroot/stdout)
403 echo -n > $testroot/stdout.expected
404 cmp -s $testroot/stdout.expected $testroot/stdout
406 if [ $ret -ne 0 ]; then
407 diff -u $testroot/stdout.expected $testroot/stdout
409 test_done "$testroot" "$ret"
412 test_commit_single_file_multiple() {
413 local testroot=`test_init commit_single_file_multiple`
415 got checkout $testroot/repo $testroot/wt > /dev/null
417 if [ $ret -ne 0 ]; then
418 test_done "$testroot" "$ret"
423 echo "modified alpha" >> $testroot/wt/alpha
425 (cd $testroot/wt && \
426 got commit -m "changed alpha" > $testroot/stdout)
428 local head_rev=`git_show_head $testroot/repo`
429 echo "M alpha" > $testroot/stdout.expected
430 echo "Created commit $head_rev" >> $testroot/stdout.expected
432 cmp -s $testroot/stdout.expected $testroot/stdout
434 if [ $ret -ne 0 ]; then
435 diff -u $testroot/stdout.expected $testroot/stdout
436 test_done "$testroot" "$ret"
441 test_done "$testroot" "0"
444 test_commit_added_and_modified_in_same_dir() {
445 local testroot=`test_init commit_added_and_modified_in_same_dir`
447 got checkout $testroot/repo $testroot/wt > /dev/null
449 if [ $ret -ne 0 ]; then
450 test_done "$testroot" "$ret"
454 echo "modified zeta" > $testroot/wt/epsilon/zeta
455 echo "new file" > $testroot/wt/epsilon/new
456 (cd $testroot/wt && got add epsilon/new >/dev/null)
458 (cd $testroot/wt && got commit \
459 -m 'added and modified in same dir' > $testroot/stdout \
462 local head_rev=`git_show_head $testroot/repo`
463 echo "A epsilon/new" > $testroot/stdout.expected
464 echo "M epsilon/zeta" >> $testroot/stdout.expected
465 echo "Created commit $head_rev" >> $testroot/stdout.expected
467 cmp -s $testroot/stdout.expected $testroot/stdout
469 if [ $ret -ne 0 ]; then
470 diff -u $testroot/stdout.expected $testroot/stdout
472 test_done "$testroot" "$ret"
475 test_commit_path_prefix() {
476 local testroot=`test_init commit_path_prefix`
477 local commit1=`git_show_head $testroot/repo`
479 got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
481 if [ $ret -ne 0 ]; then
482 test_done "$testroot" "$ret"
486 echo "modified delta" > $testroot/wt/delta
488 (cd $testroot/wt && got commit -m 'changed gamma/delta' > $testroot/stdout)
490 local commit2=`git_show_head $testroot/repo`
491 echo "M delta" > $testroot/stdout.expected
492 echo "Created commit $commit2" >> $testroot/stdout.expected
494 cmp -s $testroot/stdout.expected $testroot/stdout
496 if [ $ret -ne 0 ]; then
497 diff -u $testroot/stdout.expected $testroot/stdout
498 test_done "$testroot" "$ret"
502 echo "diff $commit1 $commit2" > $testroot/stdout.expected
503 echo "commit - $commit1" >> $testroot/stdout.expected
504 echo "commit + $commit2" >> $testroot/stdout.expected
505 echo -n 'blob - ' >> $testroot/stdout.expected
506 got tree -r $testroot/repo -c $commit1 -i gamma | grep 'delta$' \
507 | cut -d' ' -f 1 >> $testroot/stdout.expected
508 echo -n 'blob + ' >> $testroot/stdout.expected
509 got tree -r $testroot/repo -c $commit2 -i gamma | grep 'delta$' | \
510 cut -d' ' -f 1 >> $testroot/stdout.expected
511 echo '--- gamma/delta' >> $testroot/stdout.expected
512 echo '+++ gamma/delta' >> $testroot/stdout.expected
513 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
514 echo '-delta' >> $testroot/stdout.expected
515 echo '+modified delta' >> $testroot/stdout.expected
517 got diff -r $testroot/repo $commit1 $commit2 > $testroot/stdout
518 cmp -s $testroot/stdout.expected $testroot/stdout
520 if [ $ret -ne 0 ]; then
521 diff -u $testroot/stdout.expected $testroot/stdout
522 test_done "$testroot" "$ret"
526 (cd $testroot/wt && got rm delta > /dev/null)
527 echo new > $testroot/wt/new
528 (cd $testroot/wt && got add new > /dev/null)
530 (cd $testroot/wt && got commit -m 'remove gamma/delta; add gamma/new' \
533 local commit3=`git_show_head $testroot/repo`
534 echo "A new" > $testroot/stdout.expected
535 echo "D delta" >> $testroot/stdout.expected
536 echo "Created commit $commit3" >> $testroot/stdout.expected
538 cmp -s $testroot/stdout.expected $testroot/stdout
540 if [ $ret -ne 0 ]; then
541 diff -u $testroot/stdout.expected $testroot/stdout
542 test_done "$testroot" "$ret"
546 echo "diff $commit2 $commit3" > $testroot/stdout.expected
547 echo "commit - $commit2" >> $testroot/stdout.expected
548 echo "commit + $commit3" >> $testroot/stdout.expected
549 echo -n 'blob - ' >> $testroot/stdout.expected
550 got tree -r $testroot/repo -c $commit2 -i gamma | grep 'delta$' \
551 | cut -d' ' -f 1 | sed -e 's/$/ (mode 644)/' \
552 >> $testroot/stdout.expected
553 echo 'blob + /dev/null' >> $testroot/stdout.expected
554 echo '--- gamma/delta' >> $testroot/stdout.expected
555 echo '+++ /dev/null' >> $testroot/stdout.expected
556 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
557 echo '-modified delta' >> $testroot/stdout.expected
558 echo 'blob - /dev/null' >> $testroot/stdout.expected
559 echo -n 'blob + ' >> $testroot/stdout.expected
560 got tree -r $testroot/repo -c $commit3 -i gamma | grep 'new$' | \
561 cut -d' ' -f 1 | sed -e 's/$/ (mode 644)/' \
562 >> $testroot/stdout.expected
563 echo '--- /dev/null' >> $testroot/stdout.expected
564 echo '+++ gamma/new' >> $testroot/stdout.expected
565 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
566 echo '+new' >> $testroot/stdout.expected
568 got diff -r $testroot/repo $commit2 $commit3 > $testroot/stdout
569 cmp -s $testroot/stdout.expected $testroot/stdout
571 if [ $ret -ne 0 ]; then
572 diff -u $testroot/stdout.expected $testroot/stdout
574 test_done "$testroot" "$ret"
578 test_commit_dir_path() {
579 local testroot=`test_init commit_dir_path`
581 got checkout $testroot/repo $testroot/wt > /dev/null
583 if [ $ret -ne 0 ]; then
584 test_done "$testroot" "$ret"
588 echo "modified alpha" > $testroot/wt/alpha
589 echo "modified zeta" > $testroot/wt/epsilon/zeta
591 (cd $testroot/wt && got commit -m 'changed zeta' epsilon \
594 local head_rev=`git_show_head $testroot/repo`
595 echo "M epsilon/zeta" >> $testroot/stdout.expected
596 echo "Created commit $head_rev" >> $testroot/stdout.expected
598 cmp -s $testroot/stdout.expected $testroot/stdout
600 if [ $ret -ne 0 ]; then
601 diff -u $testroot/stdout.expected $testroot/stdout
602 test_done "$testroot" "$ret"
606 echo "M alpha" > $testroot/stdout.expected
607 (cd $testroot/wt && got status > $testroot/stdout)
608 cmp -s $testroot/stdout.expected $testroot/stdout
610 if [ $ret -ne 0 ]; then
611 diff -u $testroot/stdout.expected $testroot/stdout
613 test_done "$testroot" "$ret"
616 test_commit_selected_paths() {
617 local testroot=`test_init commit_selected_paths`
619 got checkout $testroot/repo $testroot/wt > /dev/null
621 if [ $ret -ne 0 ]; then
622 test_done "$testroot" "$ret"
626 echo "modified alpha" > $testroot/wt/alpha
627 echo "modified delta" > $testroot/wt/gamma/delta
628 echo "modified zeta" > $testroot/wt/epsilon/zeta
629 (cd $testroot/wt && got rm beta >/dev/null)
630 echo "new file" > $testroot/wt/new
631 (cd $testroot/wt && got add new >/dev/null)
633 (cd $testroot/wt && got commit -m 'many paths' nonexistent alpha \
634 > $testroot/stdout 2> $testroot/stderr)
636 if [ $ret -eq 0 ]; then
637 echo "commit succeeded unexpectedly" >&2
638 test_done "$testroot" "1"
641 echo "got: nonexistent: bad path" > $testroot/stderr.expected
643 cmp -s $testroot/stderr.expected $testroot/stderr
645 if [ $ret -ne 0 ]; then
646 diff -u $testroot/stderr.expected $testroot/stderr
647 test_done "$testroot" "$ret"
651 (cd $testroot/wt && got commit -m 'many paths' \
652 beta new gamma > $testroot/stdout)
654 local head_rev=`git_show_head $testroot/repo`
655 echo "A new" > $testroot/stdout.expected
656 echo "D beta" >> $testroot/stdout.expected
657 echo "M gamma/delta" >> $testroot/stdout.expected
658 echo "Created commit $head_rev" >> $testroot/stdout.expected
660 cmp -s $testroot/stdout.expected $testroot/stdout
662 if [ $ret -ne 0 ]; then
663 diff -u $testroot/stdout.expected $testroot/stdout
665 test_done "$testroot" "$ret"
668 test_commit_outside_refs_heads() {
669 local testroot=`test_init commit_outside_refs_heads`
671 got ref -r $testroot/repo -c master refs/remotes/origin/master
673 got checkout -b refs/remotes/origin/master \
674 $testroot/repo $testroot/wt > /dev/null
676 if [ $ret -ne 0 ]; then
677 test_done "$testroot" "$ret"
681 echo "modified alpha" > $testroot/wt/alpha
683 (cd $testroot/wt && got commit -m 'change alpha' \
684 > $testroot/stdout 2> $testroot/stderr)
686 if [ $ret -eq 0 ]; then
687 echo "commit succeeded unexpectedly" >&2
688 test_done "$testroot" "1"
692 echo -n > $testroot/stdout.expected
693 cmp -s $testroot/stdout.expected $testroot/stdout
695 if [ $ret -ne 0 ]; then
696 diff -u $testroot/stdout.expected $testroot/stdout
697 test_done "$testroot" "$ret"
701 echo -n "got: will not commit to a branch outside the " \
702 > $testroot/stderr.expected
703 echo '"refs/heads/" reference namespace' \
704 >> $testroot/stderr.expected
705 cmp -s $testroot/stderr.expected $testroot/stderr
707 if [ $ret -ne 0 ]; then
708 diff -u $testroot/stderr.expected $testroot/stderr
710 test_done "$testroot" "$ret"
713 test_commit_no_email() {
714 local testroot=`test_init commit_no_email`
717 errmsg="commit author's email address is required for"
718 errmsg="$errmsg compatibility with Git"
720 got checkout $testroot/repo $testroot/wt > /dev/null
722 if [ $ret -ne 0 ]; then
723 test_done "$testroot" "$ret"
727 echo "modified alpha" > $testroot/wt/alpha
728 (cd $testroot/wt && env GOT_AUTHOR=":flan_hacker:" \
729 got commit -m 'test no email' > $testroot/stdout \
732 printf "got: :flan_hacker:: %s\n" "$errmsg" > $testroot/stderr.expected
733 cmp -s $testroot/stderr.expected $testroot/stderr
735 if [ $ret -ne 0 ]; then
736 diff -u $testroot/stderr.expected $testroot/stderr
737 test_done "$testroot" "$ret"
741 echo -n > $testroot/stdout.expected
742 cmp -s $testroot/stdout.expected $testroot/stdout
744 if [ $ret -ne 0 ]; then
745 diff -u $testroot/stdout.expected $testroot/stdout
746 test_done "$testroot" $ret
750 # try again with a newline inside the email
752 && FS=' ' env GOT_AUTHOR="$(printf "Flan <hack\ner>")" \
753 got commit -m 'test invalid email' > $testroot/stdout \
756 printf "got: Flan <hack\ner>: %s\n" "$errmsg" \
757 > $testroot/stderr.expected
758 cmp -s $testroot/stderr.expected $testroot/stderr
760 if [ $ret -ne 0 ]; then
761 diff -u $testroot/stderr.expected $testroot/stderr
762 test_done "$testroot" $ret
766 echo -n > $testroot/stdout.expected
767 cmp -s $testroot/stdout.expected $testroot/stdout
769 if [ $ret -ne 0 ]; then
770 diff -u $testroot/stdout.expected $testroot/stdout
771 test_done "$testroot" $ret
775 # try again with a < inside the email
776 (cd $testroot/wt && env GOT_AUTHOR="$(printf "Flan <ha<ker>")" \
777 got commit -m 'test invalid email' > $testroot/stdout \
780 printf "got: Flan <ha<ker>: %s\n" "$errmsg" > $testroot/stderr.expected
781 cmp -s $testroot/stderr.expected $testroot/stderr
783 if [ $ret -ne 0 ]; then
784 diff -u $testroot/stderr.expected $testroot/stderr
785 test_done "$testroot" $ret
789 echo -n > $testroot/stdout.expected
790 cmp -s $testroot/stdout.expected $testroot/stdout
792 if [ $ret -ne 0 ]; then
793 diff -u $testroot/stdout.expected $testroot/stdout
795 test_done "$testroot" $ret
798 test_commit_tree_entry_sorting() {
799 local testroot=`test_init commit_tree_entry_sorting`
801 got checkout $testroot/repo $testroot/wt > /dev/null
803 if [ $ret -ne 0 ]; then
804 test_done "$testroot" "$ret"
808 # Git's index gets corrupted when tree entries are written in the
809 # order defined by got_path_cmp() rather than Git's own ordering.
810 # Create a new tree where a directory "got" and a file "got-version"
811 # would sort in the wrong order according to Git's opinion.
812 mkdir $testroot/wt/got
813 touch $testroot/wt/got/foo
814 echo foo > $testroot/wt/got-version
815 echo zzz > $testroot/wt/zzz
816 (cd $testroot/wt && got add got-version got/foo zzz > /dev/null)
818 (cd $testroot/wt && got commit -m 'test' > /dev/null)
820 # Let git-fsck verify the newly written tree to make sure Git is happy
821 (cd $testroot/repo && git fsck --strict \
822 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
824 test_done "$testroot" "$ret"
827 test_commit_cmdline_author() {
828 local testroot=`test_init commit_cmdline_author`
830 got checkout $testroot/repo $testroot/wt > /dev/null
832 if [ $ret -ne 0 ]; then
833 test_done "$testroot" $ret
837 echo "modified alpha" > $testroot/wt/alpha
839 local author="Foo <foo@example.com>"
840 (cd $testroot/wt && got commit -A "$author" -m 'edit alpha') \
843 if [ $ret -ne 0 ]; then
844 test_done "$testroot" $ret
848 (cd $testroot/repo && got log -l1 | egrep '^(from|via):') \
851 if [ $ret -ne 0 ]; then
852 test_done "$testroot" $ret
856 echo "from: $author" > $testroot/stdout.expected
857 echo "via: $GOT_AUTHOR" >> $testroot/stdout.expected
858 cmp -s $testroot/stdout.expected $testroot/stdout
860 if [ $ret -ne 0 ]; then
861 diff -u $testroot/stdout.expected $testroot/stdout
863 test_done "$testroot" $ret
866 test_commit_gotconfig_author() {
867 local testroot=`test_init commit_gotconfig_author`
869 got checkout $testroot/repo $testroot/wt > /dev/null
871 if [ $ret -ne 0 ]; then
872 test_done "$testroot" "$ret"
875 echo 'author "Flan Luck <flan_luck@openbsd.org>"' \
876 > $testroot/repo/.git/got.conf
878 echo "modified alpha" > $testroot/wt/alpha
879 (cd $testroot/wt && got commit -m 'test gotconfig author' > /dev/null)
881 if [ $ret -ne 0 ]; then
882 test_done "$testroot" "$ret"
886 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
888 if [ $ret -ne 0 ]; then
889 test_done "$testroot" "$ret"
893 echo "from: Flan Luck <flan_luck@openbsd.org>" \
894 > $testroot/stdout.expected
895 cmp -s $testroot/stdout.expected $testroot/stdout
897 if [ $ret -ne 0 ]; then
898 diff -u $testroot/stdout.expected $testroot/stdout
900 test_done "$testroot" "$ret"
903 test_commit_gotconfig_worktree_author() {
904 local testroot=`test_init commit_gotconfig_worktree_author`
906 got checkout $testroot/repo $testroot/wt > /dev/null
908 if [ $ret -ne 0 ]; then
909 test_done "$testroot" "$ret"
912 echo 'author "Flan Luck <flan_luck@openbsd.org>"' \
913 > $testroot/repo/.git/got.conf
914 echo 'author "Flan Squee <flan_squee@openbsd.org>"' \
915 > $testroot/wt/.got/got.conf
917 echo "modified alpha" > $testroot/wt/alpha
918 (cd $testroot/wt && got commit -m 'test gotconfig author' > /dev/null)
920 if [ $ret -ne 0 ]; then
921 test_done "$testroot" "$ret"
925 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
927 if [ $ret -ne 0 ]; then
928 test_done "$testroot" "$ret"
932 echo "from: Flan Squee <flan_squee@openbsd.org>" \
933 > $testroot/stdout.expected
934 cmp -s $testroot/stdout.expected $testroot/stdout
936 if [ $ret -ne 0 ]; then
937 diff -u $testroot/stdout.expected $testroot/stdout
939 test_done "$testroot" "$ret"
942 test_commit_gitconfig_author() {
943 local testroot=`test_init commit_gitconfig_author`
945 got checkout $testroot/repo $testroot/wt > /dev/null
947 if [ $ret -ne 0 ]; then
948 test_done "$testroot" "$ret"
952 (cd $testroot/repo && git config user.name 'Flan Luck')
953 (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
955 echo "modified alpha" > $testroot/wt/alpha
957 # unset in a subshell to avoid affecting our environment
958 (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
959 got commit -m 'test gitconfig author' > /dev/null)
961 if [ $ret -ne 0 ]; then
962 test_done "$testroot" "$ret"
966 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
968 if [ $ret -ne 0 ]; then
969 test_done "$testroot" "$ret"
973 echo "from: Flan Luck <flan_luck@openbsd.org>" \
974 > $testroot/stdout.expected
975 cmp -s $testroot/stdout.expected $testroot/stdout
977 if [ $ret -ne 0 ]; then
978 diff -u $testroot/stdout.expected $testroot/stdout
979 test_done "$testroot" "$ret"
983 # retry with spaces in the git config
984 ed -s "$testroot/repo/.git/config" <<EOF
988 echo "modified again" > $testroot/wt/alpha
990 # unset in a subshell to avoid affecting our environment
991 (unset GOT_IGNORE_GITCONFIG && cd "$testroot/wt" && \
992 got commit -m 'test gitconfig author again' >/dev/null)
994 if [ $ret -ne 0 ]; then
995 test_done "$testroot" "$ret"
999 (cd "$testroot/repo" && got log -l1 | grep ^from: > $testroot/stdout)
1001 if [ $ret -ne 0 ]; then
1002 test_done "$testroot" "$ret"
1006 echo "from: Flan Luck <flan_luck@openbsd.org>" \
1007 > $testroot/stdout.expected
1008 cmp -s $testroot/stdout.expected $testroot/stdout
1010 if [ $ret -ne 0 ]; then
1011 diff -u $testroot/stdout.expected $testroot/stdout
1013 test_done "$testroot" "$ret"
1016 test_commit_xbit_change() {
1017 local testroot=`test_init commit_xbit_change`
1019 got checkout $testroot/repo $testroot/wt > /dev/null
1021 if [ $ret -ne 0 ]; then
1022 test_done "$testroot" "$ret"
1026 chmod +x $testroot/wt/alpha
1028 echo 'm alpha' > $testroot/stdout.expected
1029 (cd $testroot/wt && got status > $testroot/stdout)
1031 cmp -s $testroot/stdout.expected $testroot/stdout
1033 if [ $ret -ne 0 ]; then
1034 diff -u $testroot/stdout.expected $testroot/stdout
1035 test_done "$testroot" "$ret"
1039 (cd $testroot/wt && got commit -mx > $testroot/stdout)
1041 if [ $ret -ne 0 ]; then
1042 echo "got commit failed unexpectedly"
1043 test_done "$testroot" "$ret"
1047 local commit_id=`git_show_head $testroot/repo`
1048 echo 'm alpha' > $testroot/stdout.expected
1049 echo "Created commit $commit_id" >> $testroot/stdout.expected
1050 cmp -s $testroot/stdout.expected $testroot/stdout
1052 if [ $ret -ne 0 ]; then
1053 diff -u $testroot/stdout.expected $testroot/stdout
1054 test_done "$testroot" "$ret"
1058 (cd $testroot/wt && got status > $testroot/stdout)
1060 echo -n > $testroot/stdout.expected
1061 cmp -s $testroot/stdout.expected $testroot/stdout
1063 if [ $ret -ne 0 ]; then
1064 diff -u $testroot/stdout.expected $testroot/stdout
1065 test_done "$testroot" "$ret"
1069 chmod -x $testroot/wt/alpha
1071 echo 'm alpha' > $testroot/stdout.expected
1072 (cd $testroot/wt && got status > $testroot/stdout)
1074 cmp -s $testroot/stdout.expected $testroot/stdout
1076 if [ $ret -ne 0 ]; then
1077 diff -u $testroot/stdout.expected $testroot/stdout
1078 test_done "$testroot" "$ret"
1082 (cd $testroot/wt && got commit -mx > $testroot/stdout)
1084 if [ $ret -ne 0 ]; then
1085 echo "got commit failed unexpectedly"
1086 test_done "$testroot" "$ret"
1090 local commit_id=`git_show_head $testroot/repo`
1091 echo 'm alpha' > $testroot/stdout.expected
1092 echo "Created commit $commit_id" >> $testroot/stdout.expected
1093 cmp -s $testroot/stdout.expected $testroot/stdout
1095 if [ $ret -ne 0 ]; then
1096 diff -u $testroot/stdout.expected $testroot/stdout
1097 test_done "$testroot" "$ret"
1101 chmod +x $testroot/wt/alpha
1103 echo 'm alpha' > $testroot/stdout.expected
1104 (cd $testroot/wt && got status > $testroot/stdout)
1106 cmp -s $testroot/stdout.expected $testroot/stdout
1108 if [ $ret -ne 0 ]; then
1109 diff -u $testroot/stdout.expected $testroot/stdout
1111 test_done "$testroot" "$ret"
1114 commit_check_mode() {
1116 local expected_mode="$2"
1118 chmod 644 $testroot/wt/alpha
1119 echo a >> $testroot/wt/alpha
1120 chmod $mode $testroot/wt/alpha
1122 (cd $testroot/wt && got commit -mm > $testroot/stdout)
1124 if [ $ret -ne 0 ]; then
1125 echo "got commit failed unexpectedly"
1126 test_done "$testroot" "$ret"
1130 local commit_id=`git_show_head $testroot/repo`
1131 echo 'M alpha' > $testroot/stdout.expected
1132 echo "Created commit $commit_id" >> $testroot/stdout.expected
1133 cmp -s $testroot/stdout.expected $testroot/stdout
1135 if [ $ret -ne 0 ]; then
1136 diff -u $testroot/stdout.expected $testroot/stdout
1137 test_done "$testroot" "$ret"
1141 local tree_id=$(got cat -r $testroot/repo $commit_id | \
1142 grep ^tree | cut -d' ' -f2)
1143 local alpha_id=$(got cat -r $testroot/repo $tree_id | \
1144 grep 'alpha$' | cut -d' ' -f1)
1145 echo "$alpha_id $expected_mode alpha" > $testroot/stdout.expected
1146 got cat -r $testroot/repo $tree_id | grep 'alpha$' > $testroot/stdout
1147 cmp -s $testroot/stdout.expected $testroot/stdout
1149 if [ $ret -ne 0 ]; then
1150 diff -u $testroot/stdout.expected $testroot/stdout
1155 test_commit_normalizes_filemodes() {
1156 local testroot=`test_init commit_normalizes_filemodes`
1158 got checkout $testroot/repo $testroot/wt > /dev/null
1160 if [ $ret -ne 0 ]; then
1161 test_done "$testroot" "$ret"
1165 modes="600 400 460 640 440 660 444 666"
1167 commit_check_mode "$m" "0100644"
1169 if [ $ret -ne 0 ]; then
1173 if [ $ret -ne 0 ]; then
1174 test_done "$testroot" "$ret"
1177 modes="700 500 570 750 550 770 555 777"
1179 commit_check_mode "$m" "0100755"
1181 if [ $ret -ne 0 ]; then
1185 if [ $ret -ne 0 ]; then
1186 test_done "$testroot" "$ret"
1189 test_done "$testroot" "$ret"
1192 test_commit_with_unrelated_submodule() {
1193 local testroot=`test_init commit_with_unrelated_submodule`
1195 make_single_file_repo $testroot/repo2 foo
1197 (cd $testroot/repo && git -c protocol.file.allow=always \
1198 submodule -q add ../repo2)
1199 (cd $testroot/repo && git commit -q -m 'adding submodule')
1201 got checkout $testroot/repo $testroot/wt > /dev/null
1203 if [ $ret -ne 0 ]; then
1204 echo "checkout failed unexpectedly" >&2
1205 test_done "$testroot" "$ret"
1209 echo "modified alpha" > $testroot/wt/alpha
1211 echo "" > $testroot/stdout.expected
1213 (cd $testroot/wt && got commit -m 'modify alpha' > $testroot/stdout)
1215 if [ $ret -ne 0 ]; then
1216 echo "commit failed unexpectedly" >&2
1217 test_done "$testroot" "$ret"
1221 local head_rev=`git_show_head $testroot/repo`
1222 echo "M alpha" > $testroot/stdout.expected
1223 echo "Created commit $head_rev" >> $testroot/stdout.expected
1225 cmp -s $testroot/stdout.expected $testroot/stdout
1227 if [ $ret -ne 0 ]; then
1228 diff -u $testroot/stdout.expected $testroot/stdout
1230 test_done "$testroot" "$ret"
1235 if ! [ -h $wtpath/alpha.link ]; then
1236 echo "alpha.link is not a symlink"
1240 readlink $wtpath/alpha.link > $testroot/stdout
1241 echo "alpha" > $testroot/stdout.expected
1242 cmp -s $testroot/stdout.expected $testroot/stdout
1244 if [ $ret -ne 0 ]; then
1245 diff -u $testroot/stdout.expected $testroot/stdout
1249 if ! [ -h $wtpath/epsilon.link ]; then
1250 echo "epsilon.link is not a symlink"
1254 readlink $wtpath/epsilon.link > $testroot/stdout
1255 echo "epsilon" > $testroot/stdout.expected
1256 cmp -s $testroot/stdout.expected $testroot/stdout
1258 if [ $ret -ne 0 ]; then
1259 diff -u $testroot/stdout.expected $testroot/stdout
1263 if [ -h $wtpath/passwd.link ]; then
1264 echo -n "passwd.link is a symlink and points outside of work tree: " >&2
1265 readlink $wtpath/passwd.link >&2
1269 echo -n "/etc/passwd" > $testroot/content.expected
1270 cp $wtpath/passwd.link $testroot/content
1272 if [ $ret -ne 0 ]; then
1273 echo "cp command failed unexpectedly" >&2
1277 cmp -s $testroot/content.expected $testroot/content
1279 if [ $ret -ne 0 ]; then
1280 diff -u $testroot/content.expected $testroot/content
1284 readlink $wtpath/epsilon/beta.link > $testroot/stdout
1285 echo "../beta" > $testroot/stdout.expected
1286 cmp -s $testroot/stdout.expected $testroot/stdout
1288 if [ $ret -ne 0 ]; then
1289 diff -u $testroot/stdout.expected $testroot/stdout
1293 readlink $wtpath/nonexistent.link > $testroot/stdout
1294 echo "nonexistent" > $testroot/stdout.expected
1295 cmp -s $testroot/stdout.expected $testroot/stdout
1297 if [ $ret -ne 0 ]; then
1298 diff -u $testroot/stdout.expected $testroot/stdout
1305 test_commit_symlink() {
1306 local testroot=`test_init commit_symlink`
1308 got checkout $testroot/repo $testroot/wt > /dev/null
1310 if [ $ret -ne 0 ]; then
1311 test_done "$testroot" "$ret"
1315 (cd $testroot/wt && ln -s alpha alpha.link)
1316 (cd $testroot/wt && ln -s epsilon epsilon.link)
1317 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1318 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
1319 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
1320 (cd $testroot/wt && got add alpha.link epsilon.link passwd.link \
1321 epsilon/beta.link nonexistent.link > /dev/null)
1323 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1324 > $testroot/stdout 2> $testroot/stderr)
1326 if [ $ret -eq 0 ]; then
1327 echo "got commit succeeded unexpectedly" >&2
1328 test_done "$testroot" "$ret"
1331 echo -n "got: $testroot/wt/passwd.link: " > $testroot/stderr.expected
1332 echo "symbolic link points outside of paths under version control" \
1333 >> $testroot/stderr.expected
1334 cmp -s $testroot/stderr.expected $testroot/stderr
1336 if [ $ret -ne 0 ]; then
1337 diff -u $testroot/stderr.expected $testroot/stderr
1338 test_done "$testroot" "$ret"
1342 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1345 local head_rev=`git_show_head $testroot/repo`
1346 echo "A alpha.link" > $testroot/stdout.expected
1347 echo "A epsilon.link" >> $testroot/stdout.expected
1348 echo "A nonexistent.link" >> $testroot/stdout.expected
1349 echo "A passwd.link" >> $testroot/stdout.expected
1350 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1351 echo "Created commit $head_rev" >> $testroot/stdout.expected
1353 cmp -s $testroot/stdout.expected $testroot/stdout
1355 if [ $ret -ne 0 ]; then
1356 diff -u $testroot/stdout.expected $testroot/stdout
1357 test_done "$testroot" "$ret"
1361 # verify created in-repository tree
1362 got checkout $testroot/repo $testroot/wt2 > /dev/null
1364 if [ $ret -ne 0 ]; then
1365 test_done "$testroot" "$ret"
1368 check_symlinks $testroot/wt2
1370 if [ $ret -ne 0 ]; then
1371 test_done "$testroot" "$ret"
1375 if ! [ -h $testroot/wt/passwd.link ]; then
1376 echo 'passwd.link is not a symlink' >&2
1377 test_done "$testroot" 1
1381 # 'got update' should reinstall passwd.link as a regular file
1382 (cd $testroot/wt && got update > /dev/null)
1383 check_symlinks $testroot/wt
1385 if [ $ret -ne 0 ]; then
1386 test_done "$testroot" "$ret"
1390 (cd $testroot/wt && ln -sf beta alpha.link)
1391 (cd $testroot/wt && ln -sfT gamma epsilon.link)
1392 rm $testroot/wt/epsilon/beta.link
1393 echo "this is a regular file" > $testroot/wt/epsilon/beta.link
1394 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
1395 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
1396 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
1397 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
1398 (cd $testroot/wt && ln -sf alpha new.link)
1399 (cd $testroot/wt && got add new.link > /dev/null)
1401 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1402 > $testroot/stdout 2> $testroot/stderr)
1404 if [ $ret -eq 0 ]; then
1405 echo "got commit succeeded unexpectedly" >&2
1406 test_done "$testroot" "$ret"
1409 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
1410 echo "symbolic link points outside of paths under version control" \
1411 >> $testroot/stderr.expected
1412 cmp -s $testroot/stderr.expected $testroot/stderr
1414 if [ $ret -ne 0 ]; then
1415 diff -u $testroot/stderr.expected $testroot/stderr
1416 test_done "$testroot" "$ret"
1420 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1423 local head_rev=`git_show_head $testroot/repo`
1424 echo "A dotgotbar.link" > $testroot/stdout.expected
1425 echo "A new.link" >> $testroot/stdout.expected
1426 echo "M alpha.link" >> $testroot/stdout.expected
1427 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1428 echo "M epsilon.link" >> $testroot/stdout.expected
1429 echo "D nonexistent.link" >> $testroot/stdout.expected
1430 echo "Created commit $head_rev" >> $testroot/stdout.expected
1432 cmp -s $testroot/stdout.expected $testroot/stdout
1434 if [ $ret -ne 0 ]; then
1435 diff -u $testroot/stdout.expected $testroot/stdout
1436 test_done "$testroot" "$ret"
1440 got tree -r $testroot/repo -c $head_rev -R > $testroot/stdout
1441 cat > $testroot/stdout.expected <<EOF
1445 dotgotbar.link@ -> .got/bar
1449 epsilon.link@ -> gamma
1453 passwd.link@ -> /etc/passwd
1455 cmp -s $testroot/stdout.expected $testroot/stdout
1457 if [ $ret -ne 0 ]; then
1458 diff -u $testroot/stdout.expected $testroot/stdout
1460 test_done "$testroot" "$ret"
1463 test_commit_fix_bad_symlink() {
1464 local testroot=`test_init commit_fix_bad_symlink`
1466 got checkout $testroot/repo $testroot/wt > /dev/null
1468 if [ $ret -ne 0 ]; then
1469 echo "got checkout failed unexpectedly" >&2
1470 test_done "$testroot" "$ret"
1474 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1475 (cd $testroot/wt && got add passwd.link > /dev/null)
1477 (cd $testroot/wt && got commit -S -m 'commit bad symlink' \
1480 if ! [ -h $testroot/wt/passwd.link ]; then
1481 echo 'passwd.link is not a symlink' >&2
1482 test_done "$testroot" 1
1485 (cd $testroot/wt && got update >/dev/null)
1486 if [ -h $testroot/wt/passwd.link ]; then
1487 echo "passwd.link is a symlink but should be a regular file" >&2
1488 test_done "$testroot" "1"
1492 # create another work tree which will contain the "bad" symlink
1493 got checkout $testroot/repo $testroot/wt2 > /dev/null
1495 if [ $ret -ne 0 ]; then
1496 echo "got checkout failed unexpectedly" >&2
1497 test_done "$testroot" "$ret"
1501 # change "bad" symlink back into a "good" symlink
1502 (cd $testroot/wt && ln -sfT alpha passwd.link)
1504 (cd $testroot/wt && got commit -m 'fix bad symlink' \
1507 local head_rev=`git_show_head $testroot/repo`
1508 echo "M passwd.link" > $testroot/stdout.expected
1509 echo "Created commit $head_rev" >> $testroot/stdout.expected
1511 cmp -s $testroot/stdout.expected $testroot/stdout
1513 if [ $ret -ne 0 ]; then
1514 diff -u $testroot/stdout.expected $testroot/stdout
1515 test_done "$testroot" "$ret"
1519 if ! [ -h $testroot/wt/passwd.link ]; then
1520 echo 'passwd.link is not a symlink' >&2
1521 test_done "$testroot" 1
1525 readlink $testroot/wt/passwd.link > $testroot/stdout
1526 echo "alpha" > $testroot/stdout.expected
1527 cmp -s $testroot/stdout.expected $testroot/stdout
1529 if [ $ret -ne 0 ]; then
1530 diff -u $testroot/stdout.expected $testroot/stdout
1534 # Update the other work tree; the bad symlink should be fixed
1535 (cd $testroot/wt2 && got update > /dev/null)
1537 if [ $ret -ne 0 ]; then
1538 echo "got checkout failed unexpectedly" >&2
1539 test_done "$testroot" "$ret"
1543 if ! [ -h $testroot/wt2/passwd.link ]; then
1544 echo 'passwd.link is not a symlink' >&2
1545 test_done "$testroot" 1
1549 readlink $testroot/wt2/passwd.link > $testroot/stdout
1550 echo "alpha" > $testroot/stdout.expected
1551 cmp -s $testroot/stdout.expected $testroot/stdout
1553 if [ $ret -ne 0 ]; then
1554 diff -u $testroot/stdout.expected $testroot/stdout
1558 test_done "$testroot" "0"
1561 test_commit_prepared_logmsg() {
1562 local testroot=`test_init commit_prepared_logmsg`
1564 got checkout $testroot/repo $testroot/wt > /dev/null
1566 if [ $ret -ne 0 ]; then
1567 test_done "$testroot" "$ret"
1571 echo "modified alpha" > $testroot/wt/alpha
1572 (cd $testroot/wt && got rm beta >/dev/null)
1573 echo "new file" > $testroot/wt/new
1574 (cd $testroot/wt && got add new >/dev/null)
1576 echo 'test commit_prepared_logmsg' > $testroot/logmsg
1578 cat > $testroot/editor.sh <<EOF
1581 [ "\$OSTYPE" = "linux-gnu" ] && SOPTS="-i"
1582 sed "\$SOPTS" -e 's/foo/bar/' "\$1"
1584 chmod +x $testroot/editor.sh
1586 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
1587 got commit -F "$testroot/logmsg" > $testroot/stdout)
1589 local head_rev=`git_show_head $testroot/repo`
1590 echo "A new" > $testroot/stdout.expected
1591 echo "M alpha" >> $testroot/stdout.expected
1592 echo "D beta" >> $testroot/stdout.expected
1593 echo "Created commit $head_rev" >> $testroot/stdout.expected
1595 cmp -s $testroot/stdout.expected $testroot/stdout
1597 if [ $ret -ne 0 ]; then
1598 diff -u $testroot/stdout.expected $testroot/stdout
1599 test_done "$testroot" "$ret"
1603 local author_time=`git_show_author_time $testroot/repo`
1604 local prev_LC_TIME="$LC_TIME"
1606 d=`date -u -d "@$author_time" +"%a %b %e %X %Y UTC"`
1607 LC_TIME="$prev_LC_TIME"
1608 echo "-----------------------------------------------" > $testroot/stdout.expected
1609 echo "commit $head_rev (master)" >> $testroot/stdout.expected
1610 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
1611 echo "date: $d" >> $testroot/stdout.expected
1612 echo " " >> $testroot/stdout.expected
1613 echo " test commit_prepared_logmsg" >> $testroot/stdout.expected
1614 echo " " >> $testroot/stdout.expected
1616 (cd $testroot/wt && got log -l 1 > $testroot/stdout)
1617 cmp -s $testroot/stdout.expected $testroot/stdout
1619 if [ $ret -ne 0 ]; then
1620 diff -u $testroot/stdout.expected $testroot/stdout
1621 test_done "$testroot" "$ret"
1625 echo "modified alpha again" > $testroot/wt/alpha
1627 echo 'test commit_prepared_logmsg non-interactive' \
1630 (cd $testroot/wt && got commit -N -F "$testroot/logmsg" \
1633 local head_rev=`git_show_head $testroot/repo`
1634 echo "M alpha" > $testroot/stdout.expected
1635 echo "Created commit $head_rev" >> $testroot/stdout.expected
1637 cmp -s $testroot/stdout.expected $testroot/stdout
1639 if [ $ret -ne 0 ]; then
1640 diff -u $testroot/stdout.expected $testroot/stdout
1641 test_done "$testroot" "$ret"
1645 local author_time=`git_show_author_time $testroot/repo`
1646 local prev_LC_TIME="$LC_TIME"
1648 d=`date -u -d "@$author_time" +"%a %b %e %X %Y UTC"`
1649 LC_TIME="$prev_LC_TIME"
1650 echo "-----------------------------------------------" \
1651 > $testroot/stdout.expected
1652 echo "commit $head_rev (master)" >> $testroot/stdout.expected
1653 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
1654 echo "date: $d" >> $testroot/stdout.expected
1655 echo " " >> $testroot/stdout.expected
1656 echo " test commit_prepared_logmsg non-interactive" \
1657 >> $testroot/stdout.expected
1658 echo " " >> $testroot/stdout.expected
1660 (cd $testroot/wt && got log -l 1 > $testroot/stdout)
1661 cmp -s $testroot/stdout.expected $testroot/stdout
1663 if [ $ret -ne 0 ]; then
1664 diff -u $testroot/stdout.expected $testroot/stdout
1666 test_done "$testroot" "$ret"
1669 test_commit_large_file() {
1670 local testroot=`test_init commit_large_file`
1672 got checkout $testroot/repo $testroot/wt > /dev/null
1674 if [ $ret -ne 0 ]; then
1675 test_done "$testroot" "$ret"
1679 dd status=none if=/dev/zero of=$testroot/wt/new bs=1M count=64
1680 (cd $testroot/wt && got add new >/dev/null)
1682 (cd $testroot/wt && got commit -m 'test commit_large_file' \
1685 local head_rev=`git_show_head $testroot/repo`
1686 echo "A new" > $testroot/stdout.expected
1687 echo "Created commit $head_rev" >> $testroot/stdout.expected
1689 cmp -s $testroot/stdout.expected $testroot/stdout
1691 if [ $ret -ne 0 ]; then
1692 diff -u $testroot/stdout.expected $testroot/stdout
1693 test_done "$testroot" "$ret"
1697 new_id=`get_blob_id $testroot/repo "" new`
1698 got cat -r $testroot/repo $new_id > $testroot/new
1700 if [ $ret -ne 0 ]; then
1701 echo "commit failed unexpectedly" >&2
1702 test_done "$testroot" "1"
1706 cmp -s $testroot/new $testroot/wt/new
1708 if [ $ret -ne 0 ]; then
1709 diff -u $testroot/new $testroot/wt/new
1711 test_done "$testroot" "$ret"
1716 test_commit_gitignore() {
1717 local testroot=`test_init commit_gitignores`
1719 got checkout $testroot/repo $testroot/wt > /dev/null
1721 if [ $ret -ne 0 ]; then
1722 test_done "$testroot" "$ret"
1726 mkdir -p $testroot/wt/tree1/foo
1727 mkdir -p $testroot/wt/tree2/foo
1728 echo "tree1/**" > $testroot/wt/.gitignore
1729 echo "tree2/**" >> $testroot/wt/.gitignore
1730 echo -n > $testroot/wt/tree1/bar
1731 echo -n > $testroot/wt/tree1/foo/baz
1732 echo -n > $testroot/wt/tree2/bar
1733 echo -n > $testroot/wt/tree2/foo/baz
1734 echo -n > $testroot/wt/epsilon/zeta1
1735 echo -n > $testroot/wt/epsilon/zeta2
1737 (cd $testroot/wt && got add -I -R tree1 > /dev/null)
1738 (cd $testroot/wt && got add -I tree2/foo/baz > /dev/null)
1739 (cd $testroot/wt && got commit -m "gitignore add" > /dev/null)
1740 (cd $testroot/wt && got log -P -l 1 | egrep '^ .' > $testroot/stdout)
1742 echo ' gitignore add' > $testroot/stdout.expected
1743 echo ' A tree1/bar' >> $testroot/stdout.expected
1744 echo ' A tree1/foo/baz' >> $testroot/stdout.expected
1745 echo ' A tree2/foo/baz' >> $testroot/stdout.expected
1747 cmp -s $testroot/stdout.expected $testroot/stdout
1749 if [ $ret -ne 0 ]; then
1750 diff -u $testroot/stdout.expected $testroot/stdout
1751 test_done "$testroot" "$ret"
1755 echo touch > $testroot/wt/tree1/bar
1756 echo touch > $testroot/wt/tree1/foo/baz
1757 echo touch > $testroot/wt/epsilon/zeta1
1759 (cd $testroot/wt && got commit -m "gitignore change" > /dev/null)
1760 (cd $testroot/wt && got log -P -l 1 | egrep '^ .' > $testroot/stdout)
1762 echo ' gitignore change' > $testroot/stdout.expected
1763 echo ' M tree1/bar' >> $testroot/stdout.expected
1764 echo ' M tree1/foo/baz' >> $testroot/stdout.expected
1766 cmp -s $testroot/stdout.expected $testroot/stdout
1768 if [ $ret -ne 0 ]; then
1769 diff -u $testroot/stdout.expected $testroot/stdout
1770 test_done "$testroot" "$ret"
1774 test_done "$testroot" "$ret"
1777 test_commit_bad_author() {
1778 local testroot=`test_init commit_bad_author`
1780 got checkout $testroot/repo $testroot/wt > /dev/null
1782 if [ $ret -ne 0 ]; then
1783 test_done "$testroot" $ret
1787 echo "modified alpha" > $testroot/wt/alpha
1789 (cd $testroot/wt && got commit \
1790 -A "${GIT_AUTHOR_NAME}<${GIT_AUTHOR_EMAIL}>" -m 'edit alpha') \
1791 > /dev/null 2> $testroot/stderr
1793 if [ $ret -eq 0 ]; then
1794 test_done "$testroot" 1
1798 echo -n "got: ${GIT_AUTHOR_NAME}<${GIT_AUTHOR_EMAIL}>: " \
1799 > $testroot/stderr.expected
1800 echo -n 'space between author name and email required: ' \
1801 >> $testroot/stderr.expected
1802 echo 'commit author formatting would make Git unhappy' \
1803 >> $testroot/stderr.expected
1804 cmp -s $testroot/stderr.expected $testroot/stderr
1806 if [ $ret -ne 0 ]; then
1807 diff -u $testroot/stderr.expected $testroot/stderr
1808 test_done "$testroot" $ret
1812 test_done "$testroot" 0
1815 test_commit_logmsg_ref() {
1816 local testroot=`test_init commit_logmsg_ref`
1818 got checkout $testroot/repo $testroot/wt > /dev/null
1820 if [ $ret -ne 0 ]; then
1821 test_done "$testroot" "$ret"
1825 (cd $testroot/repo && git checkout -q -b newbranch)
1827 local bo_logmsg_prefix="log message of backed-out commit"
1828 local cy_logmsg_prefix="log message of cherrypicked commit"
1829 local branch_rev_logmsg="changes on newbranch to cherrypick"
1830 local branch_rev2_logmsg="modified zeta on newbranch to cherrypick"
1832 echo "modified delta on branch" > $testroot/repo/gamma/delta
1833 echo "modified alpha on branch" > $testroot/repo/alpha
1834 (cd $testroot/repo && git rm -q beta)
1835 echo "new file on branch" > $testroot/repo/epsilon/new
1836 (cd $testroot/repo && git add epsilon/new)
1838 git_commit $testroot/repo -m "$branch_rev_logmsg"
1839 local branch_rev=`git_show_head $testroot/repo`
1841 echo "modified zeta on branch" > $testroot/repo/epsilon/zeta
1843 git_commit $testroot/repo -m "$branch_rev2_logmsg"
1844 local branch_rev2=`git_show_head $testroot/repo`
1846 (cd $testroot/wt && got cherrypick $branch_rev > /dev/null)
1847 (cd $testroot/wt && got cherrypick $branch_rev2 > /dev/null)
1849 cat > $testroot/editor.sh <<EOF
1851 sed -i 's/# l/l/' "\$1"
1853 chmod +x $testroot/editor.sh
1855 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
1856 got commit > /dev/null)
1858 if [ $ret -ne 0 ]; then
1859 echo "'got commit' failed unexpectedly" >&2
1860 test_done "$testroot" "1"
1864 # check that multiple cherrypicked log messages populate the editor
1865 local first=`printf '%s\n%s' $branch_rev $branch_rev2 | sort | head -1`
1866 local second=`printf '%s\n%s' $branch_rev $branch_rev2 | sort | tail -1`
1868 if [ $branch_rev == $first ]; then
1869 local first_msg=$branch_rev_logmsg
1870 local second_msg=$branch_rev2_logmsg
1872 local first_msg=$branch_rev2_logmsg
1873 local second_msg=$branch_rev_logmsg
1876 echo " $cy_logmsg_prefix $first:" > $testroot/stdout.expected
1877 echo " $first_msg" >> $testroot/stdout.expected
1878 echo " " >> $testroot/stdout.expected
1879 echo " $cy_logmsg_prefix $second:" >> $testroot/stdout.expected
1880 echo " $second_msg" >> $testroot/stdout.expected
1881 echo " " >> $testroot/stdout.expected
1883 (cd $testroot/wt && got log -l2 | \
1884 grep -A2 'log message' | sed '/^--/d' > $testroot/stdout)
1886 cmp -s $testroot/stdout.expected $testroot/stdout
1888 if [ $ret -ne 0 ]; then
1889 diff -u $testroot/stdout.expected $testroot/stdout
1890 test_done "$testroot" "$ret"
1894 # check that only the relevant log message populates the editor
1895 # when the changes from one of two backout commits are reverted
1896 got checkout $testroot/repo $testroot/wt2 > /dev/null
1898 if [ $ret -ne 0 ]; then
1899 test_done "$testroot" "$ret"
1903 (cd $testroot/wt2 && got backout $branch_rev > /dev/null)
1904 (cd $testroot/wt2 && got backout $branch_rev2 > /dev/null)
1905 (cd $testroot/wt2 && got revert epsilon/zeta > /dev/null)
1907 (cd $testroot/wt2 && env VISUAL="$testroot/editor.sh" \
1908 got commit > /dev/null)
1910 if [ $ret -ne 0 ]; then
1911 echo "'got commit' failed unexpectedly" >&2
1912 test_done "$testroot" "1"
1916 echo " $bo_logmsg_prefix $branch_rev:" > $testroot/stdout.expected
1917 echo " $branch_rev_logmsg" >> $testroot/stdout.expected
1918 echo " " >> $testroot/stdout.expected
1920 (cd $testroot/wt2 && got log -l1 | \
1921 grep -A2 'log message' > $testroot/stdout)
1923 cmp -s $testroot/stdout.expected $testroot/stdout
1925 if [ $ret -ne 0 ]; then
1926 diff -u $testroot/stdout.expected $testroot/stdout
1927 test_done "$testroot" "$ret"
1931 # check that a cherrypicked log message is still
1932 # used when its changes are only partially reverted
1933 branch_rev_logmsg="changes to cherrypick and partially revert"
1935 echo "newline in alpha" >> $testroot/repo/alpha
1936 echo "modified epsilon/zeta on branch" > $testroot/repo/epsilon/zeta
1938 git_commit $testroot/repo -m "$branch_rev_logmsg"
1939 branch_rev=`git_show_head $testroot/repo`
1941 (cd $testroot/wt && got cherrypick $branch_rev > /dev/null)
1942 (cd $testroot/wt && got revert alpha > /dev/null)
1944 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
1945 got commit > /dev/null)
1947 if [ $ret -ne 0 ]; then
1948 echo "'got commit' failed unexpectedly" >&2
1949 test_done "$testroot" "1"
1953 echo " $cy_logmsg_prefix $branch_rev:" > $testroot/stdout.expected
1954 echo " $branch_rev_logmsg" >> $testroot/stdout.expected
1955 echo " " >> $testroot/stdout.expected
1957 (cd $testroot/wt && got log -l1 | \
1958 grep -A2 'log message' > $testroot/stdout)
1960 cmp -s $testroot/stdout.expected $testroot/stdout
1962 if [ $ret -ne 0 ]; then
1963 diff -u $testroot/stdout.expected $testroot/stdout
1964 test_done "$testroot" "$ret"
1968 # check we don't use and consequently delete the logmsg ref of a
1969 # cherrypicked commit when omitting its changed path from the commit
1970 branch_rev_logmsg="changes to cherrypick but omit from the commit"
1972 echo "changed delta" >> $testroot/repo/gamma/delta
1974 git_commit $testroot/repo -m "$branch_rev_logmsg"
1975 local author_time=`git_show_author_time $testroot/repo`
1976 local d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
1977 branch_rev=`git_show_head $testroot/repo`
1979 (cd $testroot/wt && got update > /dev/null)
1981 if [ $ret -ne 0 ]; then
1982 echo "got update failed unexpectedly" >&2
1983 test_done "$testroot" "$ret"
1987 (cd $testroot/wt && got cherrypick $branch_rev > /dev/null)
1989 echo "changed alpha" >> $testroot/wt/alpha
1991 (cd $testroot/wt && got commit -m \
1992 "don't commit cy change to gamma/delta" alpha > /dev/null)
1994 if [ $ret -ne 0 ]; then
1995 echo "'got commit' failed unexpectedly" >&2
1996 test_done "$testroot" "1"
2000 # confirm logmsg ref was not deleted with got cherrypick -l
2001 echo "-----------------------------------------------" \
2002 > $testroot/stdout.expected
2003 echo "cherrypick $branch_rev (newbranch)" >> $testroot/stdout.expected
2004 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
2005 echo "date: $d" >> $testroot/stdout.expected
2006 echo " " >> $testroot/stdout.expected
2007 echo " $branch_rev_logmsg" >> $testroot/stdout.expected
2008 echo " " >> $testroot/stdout.expected
2009 echo " M gamma/delta" >> $testroot/stdout.expected
2010 echo >> $testroot/stdout.expected
2012 (cd $testroot/wt && got cherrypick -l > $testroot/stdout)
2014 cmp -s $testroot/stdout.expected $testroot/stdout
2016 if [ $ret -ne 0 ]; then
2017 diff -u $testroot/stdout.expected $testroot/stdout
2018 test_done "$testroot" "$ret"
2022 # confirm a previously unused logmsg ref is picked up
2023 # when an affected path is actually committed
2024 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
2025 got commit > /dev/null)
2027 if [ $ret -ne 0 ]; then
2028 echo "'got commit' failed unexpectedly" >&2
2029 test_done "$testroot" "1"
2033 echo " $cy_logmsg_prefix $branch_rev:" > $testroot/stdout.expected
2034 echo " $branch_rev_logmsg" >> $testroot/stdout.expected
2035 echo " " >> $testroot/stdout.expected
2037 (cd $testroot/wt && got log -l1 | \
2038 grep -A2 'log message' > $testroot/stdout)
2040 cmp -s $testroot/stdout.expected $testroot/stdout
2042 if [ $ret -ne 0 ]; then
2043 diff -u $testroot/stdout.expected $testroot/stdout
2044 test_done "$testroot" "$ret"
2048 # make sure we are not littering work trees
2049 # by leaving temp got-logmsg-* files behind
2050 echo -n > $testroot/stdout.expected
2051 (cd $testroot/wt && got status > $testroot/stdout)
2053 cmp -s $testroot/stdout.expected $testroot/stdout
2055 if [ $ret -ne 0 ]; then
2056 echo "$testroot/wt is not clean"
2057 diff -u $testroot/stdout.expected $testroot/stdout
2058 test_done "$testroot" "$ret"
2062 (cd $testroot/wt2 && got status > $testroot/stdout)
2064 cmp -s $testroot/stdout.expected $testroot/stdout
2066 if [ $ret -ne 0 ]; then
2067 echo "$testroot/repo is not clean"
2068 diff -u $testroot/stdout.expected $testroot/stdout
2070 test_done "$testroot" "$ret"
2074 run_test test_commit_basic
2075 run_test test_commit_new_subdir
2076 run_test test_commit_subdir
2077 run_test test_commit_single_file
2078 run_test test_commit_out_of_date
2079 run_test test_commit_added_subdirs
2080 run_test test_commit_deleted_subdirs
2081 run_test test_commit_rejects_conflicted_file
2082 run_test test_commit_single_file_multiple
2083 run_test test_commit_added_and_modified_in_same_dir
2084 run_test test_commit_path_prefix
2085 run_test test_commit_dir_path
2086 run_test test_commit_selected_paths
2087 run_test test_commit_outside_refs_heads
2088 run_test test_commit_no_email
2089 run_test test_commit_tree_entry_sorting
2090 run_test test_commit_cmdline_author
2091 run_test test_commit_gotconfig_author
2092 run_test test_commit_gotconfig_worktree_author
2093 run_test test_commit_gitconfig_author
2094 run_test test_commit_xbit_change
2095 run_test test_commit_normalizes_filemodes
2096 run_test test_commit_with_unrelated_submodule
2097 run_test test_commit_symlink
2098 run_test test_commit_fix_bad_symlink
2099 run_test test_commit_prepared_logmsg
2100 run_test test_commit_large_file
2101 run_test test_commit_gitignore
2102 run_test test_commit_bad_author
2103 run_test test_commit_logmsg_ref