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)
298 (cd $testroot/wt && got update -c $initial_rev > /dev/null)
300 echo "modified alpha, too" > $testroot/wt/alpha
302 echo "C alpha" > $testroot/stdout.expected
303 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
304 git_show_head $testroot/repo >> $testroot/stdout.expected
305 echo >> $testroot/stdout.expected
306 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
308 (cd $testroot/wt && got update > $testroot/stdout)
310 cmp -s $testroot/stdout.expected $testroot/stdout
312 if [ $ret -ne 0 ]; then
313 diff -u $testroot/stdout.expected $testroot/stdout
314 test_done "$testroot" "$ret"
318 (cd $testroot/wt && got commit -m 'commit it' > $testroot/stdout \
321 echo -n > $testroot/stdout.expected
322 echo "got: cannot commit file in conflicted status" \
323 > $testroot/stderr.expected
325 cmp -s $testroot/stdout.expected $testroot/stdout
327 if [ $ret -ne 0 ]; then
328 diff -u $testroot/stdout.expected $testroot/stdout
329 test_done "$testroot" "$ret"
332 cmp -s $testroot/stderr.expected $testroot/stderr
334 if [ $ret -ne 0 ]; then
335 diff -u $testroot/stderr.expected $testroot/stderr
337 test_done "$testroot" "$ret"
340 test_commit_single_file_multiple() {
341 local testroot=`test_init commit_single_file_multiple`
343 got checkout $testroot/repo $testroot/wt > /dev/null
345 if [ $ret -ne 0 ]; then
346 test_done "$testroot" "$ret"
351 echo "modified alpha" >> $testroot/wt/alpha
353 (cd $testroot/wt && \
354 got commit -m "changed alpha" > $testroot/stdout)
356 local head_rev=`git_show_head $testroot/repo`
357 echo "M alpha" > $testroot/stdout.expected
358 echo "Created commit $head_rev" >> $testroot/stdout.expected
360 cmp -s $testroot/stdout.expected $testroot/stdout
362 if [ $ret -ne 0 ]; then
363 diff -u $testroot/stdout.expected $testroot/stdout
364 test_done "$testroot" "$ret"
369 test_done "$testroot" "0"
372 test_commit_added_and_modified_in_same_dir() {
373 local testroot=`test_init commit_added_and_modified_in_same_dir`
375 got checkout $testroot/repo $testroot/wt > /dev/null
377 if [ $ret -ne 0 ]; then
378 test_done "$testroot" "$ret"
382 echo "modified zeta" > $testroot/wt/epsilon/zeta
383 echo "new file" > $testroot/wt/epsilon/new
384 (cd $testroot/wt && got add epsilon/new >/dev/null)
386 (cd $testroot/wt && got commit \
387 -m 'added and modified in same dir' > $testroot/stdout \
390 local head_rev=`git_show_head $testroot/repo`
391 echo "A epsilon/new" > $testroot/stdout.expected
392 echo "M epsilon/zeta" >> $testroot/stdout.expected
393 echo "Created commit $head_rev" >> $testroot/stdout.expected
395 cmp -s $testroot/stdout.expected $testroot/stdout
397 if [ $ret -ne 0 ]; then
398 diff -u $testroot/stdout.expected $testroot/stdout
400 test_done "$testroot" "$ret"
403 test_commit_path_prefix() {
404 local testroot=`test_init commit_path_prefix`
405 local commit1=`git_show_head $testroot/repo`
407 got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
409 if [ $ret -ne 0 ]; then
410 test_done "$testroot" "$ret"
414 echo "modified delta" > $testroot/wt/delta
416 (cd $testroot/wt && got commit -m 'changed gamma/delta' > $testroot/stdout)
418 local commit2=`git_show_head $testroot/repo`
419 echo "M delta" > $testroot/stdout.expected
420 echo "Created commit $commit2" >> $testroot/stdout.expected
422 cmp -s $testroot/stdout.expected $testroot/stdout
424 if [ $ret -ne 0 ]; then
425 diff -u $testroot/stdout.expected $testroot/stdout
426 test_done "$testroot" "$ret"
430 echo "diff $commit1 $commit2" > $testroot/stdout.expected
431 echo "commit - $commit1" >> $testroot/stdout.expected
432 echo "commit + $commit2" >> $testroot/stdout.expected
433 echo -n 'blob - ' >> $testroot/stdout.expected
434 got tree -r $testroot/repo -c $commit1 -i gamma | grep 'delta$' \
435 | cut -d' ' -f 1 >> $testroot/stdout.expected
436 echo -n 'blob + ' >> $testroot/stdout.expected
437 got tree -r $testroot/repo -c $commit2 -i gamma | grep 'delta$' | \
438 cut -d' ' -f 1 >> $testroot/stdout.expected
439 echo '--- gamma/delta' >> $testroot/stdout.expected
440 echo '+++ gamma/delta' >> $testroot/stdout.expected
441 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
442 echo '-delta' >> $testroot/stdout.expected
443 echo '+modified delta' >> $testroot/stdout.expected
445 got diff -r $testroot/repo $commit1 $commit2 > $testroot/stdout
446 cmp -s $testroot/stdout.expected $testroot/stdout
448 if [ $ret -ne 0 ]; then
449 diff -u $testroot/stdout.expected $testroot/stdout
450 test_done "$testroot" "$ret"
454 (cd $testroot/wt && got rm delta > /dev/null)
455 echo new > $testroot/wt/new
456 (cd $testroot/wt && got add new > /dev/null)
458 (cd $testroot/wt && got commit -m 'remove gamma/delta; add gamma/new' \
461 local commit3=`git_show_head $testroot/repo`
462 echo "A new" > $testroot/stdout.expected
463 echo "D delta" >> $testroot/stdout.expected
464 echo "Created commit $commit3" >> $testroot/stdout.expected
466 cmp -s $testroot/stdout.expected $testroot/stdout
468 if [ $ret -ne 0 ]; then
469 diff -u $testroot/stdout.expected $testroot/stdout
470 test_done "$testroot" "$ret"
474 echo "diff $commit2 $commit3" > $testroot/stdout.expected
475 echo "commit - $commit2" >> $testroot/stdout.expected
476 echo "commit + $commit3" >> $testroot/stdout.expected
477 echo -n 'blob - ' >> $testroot/stdout.expected
478 got tree -r $testroot/repo -c $commit2 -i gamma | grep 'delta$' \
479 | cut -d' ' -f 1 | sed -e 's/$/ (mode 644)/' \
480 >> $testroot/stdout.expected
481 echo 'blob + /dev/null' >> $testroot/stdout.expected
482 echo '--- gamma/delta' >> $testroot/stdout.expected
483 echo '+++ /dev/null' >> $testroot/stdout.expected
484 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
485 echo '-modified delta' >> $testroot/stdout.expected
486 echo 'blob - /dev/null' >> $testroot/stdout.expected
487 echo -n 'blob + ' >> $testroot/stdout.expected
488 got tree -r $testroot/repo -c $commit3 -i gamma | grep 'new$' | \
489 cut -d' ' -f 1 | sed -e 's/$/ (mode 644)/' \
490 >> $testroot/stdout.expected
491 echo '--- /dev/null' >> $testroot/stdout.expected
492 echo '+++ gamma/new' >> $testroot/stdout.expected
493 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
494 echo '+new' >> $testroot/stdout.expected
496 got diff -r $testroot/repo $commit2 $commit3 > $testroot/stdout
497 cmp -s $testroot/stdout.expected $testroot/stdout
499 if [ $ret -ne 0 ]; then
500 diff -u $testroot/stdout.expected $testroot/stdout
502 test_done "$testroot" "$ret"
506 test_commit_dir_path() {
507 local testroot=`test_init commit_dir_path`
509 got checkout $testroot/repo $testroot/wt > /dev/null
511 if [ $ret -ne 0 ]; then
512 test_done "$testroot" "$ret"
516 echo "modified alpha" > $testroot/wt/alpha
517 echo "modified zeta" > $testroot/wt/epsilon/zeta
519 (cd $testroot/wt && got commit -m 'changed zeta' epsilon \
522 local head_rev=`git_show_head $testroot/repo`
523 echo "M epsilon/zeta" >> $testroot/stdout.expected
524 echo "Created commit $head_rev" >> $testroot/stdout.expected
526 cmp -s $testroot/stdout.expected $testroot/stdout
528 if [ $ret -ne 0 ]; then
529 diff -u $testroot/stdout.expected $testroot/stdout
530 test_done "$testroot" "$ret"
534 echo "M alpha" > $testroot/stdout.expected
535 (cd $testroot/wt && got status > $testroot/stdout)
536 cmp -s $testroot/stdout.expected $testroot/stdout
538 if [ $ret -ne 0 ]; then
539 diff -u $testroot/stdout.expected $testroot/stdout
541 test_done "$testroot" "$ret"
544 test_commit_selected_paths() {
545 local testroot=`test_init commit_selected_paths`
547 got checkout $testroot/repo $testroot/wt > /dev/null
549 if [ $ret -ne 0 ]; then
550 test_done "$testroot" "$ret"
554 echo "modified alpha" > $testroot/wt/alpha
555 echo "modified delta" > $testroot/wt/gamma/delta
556 echo "modified zeta" > $testroot/wt/epsilon/zeta
557 (cd $testroot/wt && got rm beta >/dev/null)
558 echo "new file" > $testroot/wt/new
559 (cd $testroot/wt && got add new >/dev/null)
561 (cd $testroot/wt && got commit -m 'many paths' nonexistent alpha \
562 > $testroot/stdout 2> $testroot/stderr)
564 if [ $ret -eq 0 ]; then
565 echo "commit succeeded unexpectedly" >&2
566 test_done "$testroot" "1"
569 echo "got: nonexistent: bad path" > $testroot/stderr.expected
571 cmp -s $testroot/stderr.expected $testroot/stderr
573 if [ $ret -ne 0 ]; then
574 diff -u $testroot/stderr.expected $testroot/stderr
575 test_done "$testroot" "$ret"
579 (cd $testroot/wt && got commit -m 'many paths' \
580 beta new gamma > $testroot/stdout)
582 local head_rev=`git_show_head $testroot/repo`
583 echo "A new" > $testroot/stdout.expected
584 echo "D beta" >> $testroot/stdout.expected
585 echo "M gamma/delta" >> $testroot/stdout.expected
586 echo "Created commit $head_rev" >> $testroot/stdout.expected
588 cmp -s $testroot/stdout.expected $testroot/stdout
590 if [ $ret -ne 0 ]; then
591 diff -u $testroot/stdout.expected $testroot/stdout
593 test_done "$testroot" "$ret"
596 test_commit_outside_refs_heads() {
597 local testroot=`test_init commit_outside_refs_heads`
599 got ref -r $testroot/repo -c master refs/remotes/origin/master
601 got checkout -b refs/remotes/origin/master \
602 $testroot/repo $testroot/wt > /dev/null
604 if [ $ret -ne 0 ]; then
605 test_done "$testroot" "$ret"
609 echo "modified alpha" > $testroot/wt/alpha
611 (cd $testroot/wt && got commit -m 'change alpha' \
612 > $testroot/stdout 2> $testroot/stderr)
614 if [ $ret -eq 0 ]; then
615 echo "commit succeeded unexpectedly" >&2
616 test_done "$testroot" "1"
620 echo -n > $testroot/stdout.expected
621 cmp -s $testroot/stdout.expected $testroot/stdout
623 if [ $ret -ne 0 ]; then
624 diff -u $testroot/stdout.expected $testroot/stdout
625 test_done "$testroot" "$ret"
629 echo -n "got: will not commit to a branch outside the " \
630 > $testroot/stderr.expected
631 echo '"refs/heads/" reference namespace' \
632 >> $testroot/stderr.expected
633 cmp -s $testroot/stderr.expected $testroot/stderr
635 if [ $ret -ne 0 ]; then
636 diff -u $testroot/stderr.expected $testroot/stderr
638 test_done "$testroot" "$ret"
641 test_commit_no_email() {
642 local testroot=`test_init commit_no_email`
645 errmsg="commit author's email address is required for"
646 errmsg="$errmsg compatibility with Git"
648 got checkout $testroot/repo $testroot/wt > /dev/null
650 if [ $ret -ne 0 ]; then
651 test_done "$testroot" "$ret"
655 echo "modified alpha" > $testroot/wt/alpha
656 (cd $testroot/wt && env GOT_AUTHOR=":flan_hacker:" \
657 got commit -m 'test no email' > $testroot/stdout \
660 printf "got: :flan_hacker:: %s\n" "$errmsg" > $testroot/stderr.expected
661 cmp -s $testroot/stderr.expected $testroot/stderr
663 if [ $ret -ne 0 ]; then
664 diff -u $testroot/stderr.expected $testroot/stderr
665 test_done "$testroot" "$ret"
669 echo -n > $testroot/stdout.expected
670 cmp -s $testroot/stdout.expected $testroot/stdout
672 if [ $ret -ne 0 ]; then
673 diff -u $testroot/stdout.expected $testroot/stdout
674 test_done "$testroot" $ret
678 # try again with a newline inside the email
680 && FS=' ' env GOT_AUTHOR="$(printf "Flan <hack\ner>")" \
681 got commit -m 'test invalid email' > $testroot/stdout \
684 printf "got: Flan <hack\ner>: %s\n" "$errmsg" \
685 > $testroot/stderr.expected
686 cmp -s $testroot/stderr.expected $testroot/stderr
688 if [ $ret -ne 0 ]; then
689 diff -u $testroot/stderr.expected $testroot/stderr
690 test_done "$testroot" $ret
694 echo -n > $testroot/stdout.expected
695 cmp -s $testroot/stdout.expected $testroot/stdout
697 if [ $ret -ne 0 ]; then
698 diff -u $testroot/stdout.expected $testroot/stdout
699 test_done "$testroot" $ret
703 # try again with a < inside the email
704 (cd $testroot/wt && env GOT_AUTHOR="$(printf "Flan <ha<ker>")" \
705 got commit -m 'test invalid email' > $testroot/stdout \
708 printf "got: Flan <ha<ker>: %s\n" "$errmsg" > $testroot/stderr.expected
709 cmp -s $testroot/stderr.expected $testroot/stderr
711 if [ $ret -ne 0 ]; then
712 diff -u $testroot/stderr.expected $testroot/stderr
713 test_done "$testroot" $ret
717 echo -n > $testroot/stdout.expected
718 cmp -s $testroot/stdout.expected $testroot/stdout
720 if [ $ret -ne 0 ]; then
721 diff -u $testroot/stdout.expected $testroot/stdout
723 test_done "$testroot" $ret
726 test_commit_tree_entry_sorting() {
727 local testroot=`test_init commit_tree_entry_sorting`
729 got checkout $testroot/repo $testroot/wt > /dev/null
731 if [ $ret -ne 0 ]; then
732 test_done "$testroot" "$ret"
736 # Git's index gets corrupted when tree entries are written in the
737 # order defined by got_path_cmp() rather than Git's own ordering.
738 # Create a new tree where a directory "got" and a file "got-version"
739 # would sort in the wrong order according to Git's opinion.
740 mkdir $testroot/wt/got
741 touch $testroot/wt/got/foo
742 echo foo > $testroot/wt/got-version
743 echo zzz > $testroot/wt/zzz
744 (cd $testroot/wt && got add got-version got/foo zzz > /dev/null)
746 (cd $testroot/wt && got commit -m 'test' > /dev/null)
748 # Let git-fsck verify the newly written tree to make sure Git is happy
749 (cd $testroot/repo && git fsck --strict \
750 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
752 test_done "$testroot" "$ret"
755 test_commit_cmdline_author() {
756 local testroot=`test_init commit_cmdline_author`
758 got checkout $testroot/repo $testroot/wt > /dev/null
760 if [ $ret -ne 0 ]; then
761 test_done "$testroot" $ret
765 echo "modified alpha" > $testroot/wt/alpha
767 # first try with a -A equals to $GOT_AUTHOR
768 (cd $testroot/wt && got commit -A "$GOT_AUTHOR" -m 'edit alpha') \
769 > /dev/null 2> $testroot/stderr
771 if [ $ret -eq 0 ]; then
772 test_done "$testroot" 1
776 echo 'got: specified author is equal to the default one' \
777 > $testroot/stderr.expected
778 cmp -s $testroot/stderr.expected $testroot/stderr
780 if [ $ret -ne 0 ]; then
781 diff -u $testroot/stderr.expected $testroot/stderr
782 test_done "$testroot" $ret
786 # try again with a different author
787 local author="Foo <foo@example.com>"
788 (cd $testroot/wt && got commit -A "$author" -m 'edit alpha') \
791 if [ $ret -ne 0 ]; then
792 test_done "$testroot" $ret
796 (cd $testroot/repo && got log -l1 | egrep '^(from|via):') \
799 if [ $ret -ne 0 ]; then
800 test_done "$testroot" $ret
804 echo "from: $author" > $testroot/stdout.expected
805 echo "via: $GOT_AUTHOR" >> $testroot/stdout.expected
806 cmp -s $testroot/stdout.expected $testroot/stdout
808 if [ $ret -ne 0 ]; then
809 diff -u $testroot/stdout.expected $testroot/stdout
811 test_done "$testroot" $ret
814 test_commit_gotconfig_author() {
815 local testroot=`test_init commit_gotconfig_author`
817 got checkout $testroot/repo $testroot/wt > /dev/null
819 if [ $ret -ne 0 ]; then
820 test_done "$testroot" "$ret"
823 echo 'author "Flan Luck <flan_luck@openbsd.org>"' \
824 > $testroot/repo/.git/got.conf
826 echo "modified alpha" > $testroot/wt/alpha
827 (cd $testroot/wt && got commit -m 'test gotconfig author' > /dev/null)
829 if [ $ret -ne 0 ]; then
830 test_done "$testroot" "$ret"
834 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
836 if [ $ret -ne 0 ]; then
837 test_done "$testroot" "$ret"
841 echo "from: Flan Luck <flan_luck@openbsd.org>" \
842 > $testroot/stdout.expected
843 cmp -s $testroot/stdout.expected $testroot/stdout
845 if [ $ret -ne 0 ]; then
846 diff -u $testroot/stdout.expected $testroot/stdout
848 test_done "$testroot" "$ret"
851 test_commit_gotconfig_worktree_author() {
852 local testroot=`test_init commit_gotconfig_worktree_author`
854 got checkout $testroot/repo $testroot/wt > /dev/null
856 if [ $ret -ne 0 ]; then
857 test_done "$testroot" "$ret"
860 echo 'author "Flan Luck <flan_luck@openbsd.org>"' \
861 > $testroot/repo/.git/got.conf
862 echo 'author "Flan Squee <flan_squee@openbsd.org>"' \
863 > $testroot/wt/.got/got.conf
865 echo "modified alpha" > $testroot/wt/alpha
866 (cd $testroot/wt && got commit -m 'test gotconfig author' > /dev/null)
868 if [ $ret -ne 0 ]; then
869 test_done "$testroot" "$ret"
873 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
875 if [ $ret -ne 0 ]; then
876 test_done "$testroot" "$ret"
880 echo "from: Flan Squee <flan_squee@openbsd.org>" \
881 > $testroot/stdout.expected
882 cmp -s $testroot/stdout.expected $testroot/stdout
884 if [ $ret -ne 0 ]; then
885 diff -u $testroot/stdout.expected $testroot/stdout
887 test_done "$testroot" "$ret"
890 test_commit_gitconfig_author() {
891 local testroot=`test_init commit_gitconfig_author`
893 got checkout $testroot/repo $testroot/wt > /dev/null
895 if [ $ret -ne 0 ]; then
896 test_done "$testroot" "$ret"
900 (cd $testroot/repo && git config user.name 'Flan Luck')
901 (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
903 echo "modified alpha" > $testroot/wt/alpha
905 # unset in a subshell to avoid affecting our environment
906 (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
907 got commit -m 'test gitconfig author' > /dev/null)
909 if [ $ret -ne 0 ]; then
910 test_done "$testroot" "$ret"
914 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
916 if [ $ret -ne 0 ]; then
917 test_done "$testroot" "$ret"
921 echo "from: Flan Luck <flan_luck@openbsd.org>" \
922 > $testroot/stdout.expected
923 cmp -s $testroot/stdout.expected $testroot/stdout
925 if [ $ret -ne 0 ]; then
926 diff -u $testroot/stdout.expected $testroot/stdout
928 test_done "$testroot" "$ret"
931 test_commit_xbit_change() {
932 local testroot=`test_init commit_xbit_change`
934 got checkout $testroot/repo $testroot/wt > /dev/null
936 if [ $ret -ne 0 ]; then
937 test_done "$testroot" "$ret"
941 chmod +x $testroot/wt/alpha
943 echo 'm alpha' > $testroot/stdout.expected
944 (cd $testroot/wt && got status > $testroot/stdout)
946 cmp -s $testroot/stdout.expected $testroot/stdout
948 if [ $ret -ne 0 ]; then
949 diff -u $testroot/stdout.expected $testroot/stdout
950 test_done "$testroot" "$ret"
954 (cd $testroot/wt && got commit -mx > $testroot/stdout)
956 if [ $ret -ne 0 ]; then
957 echo "got commit failed unexpectedly"
958 test_done "$testroot" "$ret"
962 local commit_id=`git_show_head $testroot/repo`
963 echo 'm alpha' > $testroot/stdout.expected
964 echo "Created commit $commit_id" >> $testroot/stdout.expected
965 cmp -s $testroot/stdout.expected $testroot/stdout
967 if [ $ret -ne 0 ]; then
968 diff -u $testroot/stdout.expected $testroot/stdout
969 test_done "$testroot" "$ret"
973 (cd $testroot/wt && got status > $testroot/stdout)
975 echo -n > $testroot/stdout.expected
976 cmp -s $testroot/stdout.expected $testroot/stdout
978 if [ $ret -ne 0 ]; then
979 diff -u $testroot/stdout.expected $testroot/stdout
980 test_done "$testroot" "$ret"
984 chmod -x $testroot/wt/alpha
986 echo 'm alpha' > $testroot/stdout.expected
987 (cd $testroot/wt && got status > $testroot/stdout)
989 cmp -s $testroot/stdout.expected $testroot/stdout
991 if [ $ret -ne 0 ]; then
992 diff -u $testroot/stdout.expected $testroot/stdout
993 test_done "$testroot" "$ret"
997 (cd $testroot/wt && got commit -mx > $testroot/stdout)
999 if [ $ret -ne 0 ]; then
1000 echo "got commit failed unexpectedly"
1001 test_done "$testroot" "$ret"
1005 local commit_id=`git_show_head $testroot/repo`
1006 echo 'm alpha' > $testroot/stdout.expected
1007 echo "Created commit $commit_id" >> $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
1012 test_done "$testroot" "$ret"
1016 chmod +x $testroot/wt/alpha
1018 echo 'm alpha' > $testroot/stdout.expected
1019 (cd $testroot/wt && got status > $testroot/stdout)
1021 cmp -s $testroot/stdout.expected $testroot/stdout
1023 if [ $ret -ne 0 ]; then
1024 diff -u $testroot/stdout.expected $testroot/stdout
1026 test_done "$testroot" "$ret"
1029 commit_check_mode() {
1031 local expected_mode="$2"
1033 chmod 644 $testroot/wt/alpha
1034 echo a >> $testroot/wt/alpha
1035 chmod $mode $testroot/wt/alpha
1037 (cd $testroot/wt && got commit -mm > $testroot/stdout)
1039 if [ $ret -ne 0 ]; then
1040 echo "got commit failed unexpectedly"
1041 test_done "$testroot" "$ret"
1045 local commit_id=`git_show_head $testroot/repo`
1046 echo 'M alpha' > $testroot/stdout.expected
1047 echo "Created commit $commit_id" >> $testroot/stdout.expected
1048 cmp -s $testroot/stdout.expected $testroot/stdout
1050 if [ $ret -ne 0 ]; then
1051 diff -u $testroot/stdout.expected $testroot/stdout
1052 test_done "$testroot" "$ret"
1056 local tree_id=$(got cat -r $testroot/repo $commit_id | \
1057 grep ^tree | cut -d' ' -f2)
1058 local alpha_id=$(got cat -r $testroot/repo $tree_id | \
1059 grep 'alpha$' | cut -d' ' -f1)
1060 echo "$alpha_id $expected_mode alpha" > $testroot/stdout.expected
1061 got cat -r $testroot/repo $tree_id | grep 'alpha$' > $testroot/stdout
1062 cmp -s $testroot/stdout.expected $testroot/stdout
1064 if [ $ret -ne 0 ]; then
1065 diff -u $testroot/stdout.expected $testroot/stdout
1070 test_commit_normalizes_filemodes() {
1071 local testroot=`test_init commit_normalizes_filemodes`
1073 got checkout $testroot/repo $testroot/wt > /dev/null
1075 if [ $ret -ne 0 ]; then
1076 test_done "$testroot" "$ret"
1080 modes="600 400 460 640 440 660 444 666"
1082 commit_check_mode "$m" "0100644"
1084 if [ $ret -ne 0 ]; then
1088 if [ $ret -ne 0 ]; then
1089 test_done "$testroot" "$ret"
1092 modes="700 500 570 750 550 770 555 777"
1094 commit_check_mode "$m" "0100755"
1096 if [ $ret -ne 0 ]; then
1100 if [ $ret -ne 0 ]; then
1101 test_done "$testroot" "$ret"
1104 test_done "$testroot" "$ret"
1107 test_commit_with_unrelated_submodule() {
1108 local testroot=`test_init commit_with_unrelated_submodule`
1110 make_single_file_repo $testroot/repo2 foo
1112 (cd $testroot/repo && git -c protocol.file.allow=always \
1113 submodule -q add ../repo2)
1114 (cd $testroot/repo && git commit -q -m 'adding submodule')
1116 got checkout $testroot/repo $testroot/wt > /dev/null
1118 if [ $ret -ne 0 ]; then
1119 echo "checkout failed unexpectedly" >&2
1120 test_done "$testroot" "$ret"
1124 echo "modified alpha" > $testroot/wt/alpha
1126 echo "" > $testroot/stdout.expected
1128 (cd $testroot/wt && got commit -m 'modify alpha' > $testroot/stdout)
1130 if [ $ret -ne 0 ]; then
1131 echo "commit failed unexpectedly" >&2
1132 test_done "$testroot" "$ret"
1136 local head_rev=`git_show_head $testroot/repo`
1137 echo "M alpha" > $testroot/stdout.expected
1138 echo "Created commit $head_rev" >> $testroot/stdout.expected
1140 cmp -s $testroot/stdout.expected $testroot/stdout
1142 if [ $ret -ne 0 ]; then
1143 diff -u $testroot/stdout.expected $testroot/stdout
1145 test_done "$testroot" "$ret"
1150 if ! [ -h $wtpath/alpha.link ]; then
1151 echo "alpha.link is not a symlink"
1155 readlink $wtpath/alpha.link > $testroot/stdout
1156 echo "alpha" > $testroot/stdout.expected
1157 cmp -s $testroot/stdout.expected $testroot/stdout
1159 if [ $ret -ne 0 ]; then
1160 diff -u $testroot/stdout.expected $testroot/stdout
1164 if ! [ -h $wtpath/epsilon.link ]; then
1165 echo "epsilon.link is not a symlink"
1169 readlink $wtpath/epsilon.link > $testroot/stdout
1170 echo "epsilon" > $testroot/stdout.expected
1171 cmp -s $testroot/stdout.expected $testroot/stdout
1173 if [ $ret -ne 0 ]; then
1174 diff -u $testroot/stdout.expected $testroot/stdout
1178 if [ -h $wtpath/passwd.link ]; then
1179 echo -n "passwd.link is a symlink and points outside of work tree: " >&2
1180 readlink $wtpath/passwd.link >&2
1184 echo -n "/etc/passwd" > $testroot/content.expected
1185 cp $wtpath/passwd.link $testroot/content
1187 if [ $ret -ne 0 ]; then
1188 echo "cp command failed unexpectedly" >&2
1192 cmp -s $testroot/content.expected $testroot/content
1194 if [ $ret -ne 0 ]; then
1195 diff -u $testroot/content.expected $testroot/content
1199 readlink $wtpath/epsilon/beta.link > $testroot/stdout
1200 echo "../beta" > $testroot/stdout.expected
1201 cmp -s $testroot/stdout.expected $testroot/stdout
1203 if [ $ret -ne 0 ]; then
1204 diff -u $testroot/stdout.expected $testroot/stdout
1208 readlink $wtpath/nonexistent.link > $testroot/stdout
1209 echo "nonexistent" > $testroot/stdout.expected
1210 cmp -s $testroot/stdout.expected $testroot/stdout
1212 if [ $ret -ne 0 ]; then
1213 diff -u $testroot/stdout.expected $testroot/stdout
1220 test_commit_symlink() {
1221 local testroot=`test_init commit_symlink`
1223 got checkout $testroot/repo $testroot/wt > /dev/null
1225 if [ $ret -ne 0 ]; then
1226 test_done "$testroot" "$ret"
1230 (cd $testroot/wt && ln -s alpha alpha.link)
1231 (cd $testroot/wt && ln -s epsilon epsilon.link)
1232 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1233 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
1234 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
1235 (cd $testroot/wt && got add alpha.link epsilon.link passwd.link \
1236 epsilon/beta.link nonexistent.link > /dev/null)
1238 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1239 > $testroot/stdout 2> $testroot/stderr)
1241 if [ $ret -eq 0 ]; then
1242 echo "got commit succeeded unexpectedly" >&2
1243 test_done "$testroot" "$ret"
1246 echo -n "got: $testroot/wt/passwd.link: " > $testroot/stderr.expected
1247 echo "symbolic link points outside of paths under version control" \
1248 >> $testroot/stderr.expected
1249 cmp -s $testroot/stderr.expected $testroot/stderr
1251 if [ $ret -ne 0 ]; then
1252 diff -u $testroot/stderr.expected $testroot/stderr
1253 test_done "$testroot" "$ret"
1257 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1260 local head_rev=`git_show_head $testroot/repo`
1261 echo "A alpha.link" > $testroot/stdout.expected
1262 echo "A epsilon.link" >> $testroot/stdout.expected
1263 echo "A nonexistent.link" >> $testroot/stdout.expected
1264 echo "A passwd.link" >> $testroot/stdout.expected
1265 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1266 echo "Created commit $head_rev" >> $testroot/stdout.expected
1268 cmp -s $testroot/stdout.expected $testroot/stdout
1270 if [ $ret -ne 0 ]; then
1271 diff -u $testroot/stdout.expected $testroot/stdout
1272 test_done "$testroot" "$ret"
1276 # verify created in-repository tree
1277 got checkout $testroot/repo $testroot/wt2 > /dev/null
1279 if [ $ret -ne 0 ]; then
1280 test_done "$testroot" "$ret"
1283 check_symlinks $testroot/wt2
1285 if [ $ret -ne 0 ]; then
1286 test_done "$testroot" "$ret"
1290 if ! [ -h $testroot/wt/passwd.link ]; then
1291 echo 'passwd.link is not a symlink' >&2
1292 test_done "$testroot" 1
1296 # 'got update' should reinstall passwd.link as a regular file
1297 (cd $testroot/wt && got update > /dev/null)
1298 check_symlinks $testroot/wt
1300 if [ $ret -ne 0 ]; then
1301 test_done "$testroot" "$ret"
1305 (cd $testroot/wt && ln -sf beta alpha.link)
1306 (cd $testroot/wt && ln -sfT gamma epsilon.link)
1307 rm $testroot/wt/epsilon/beta.link
1308 echo "this is a regular file" > $testroot/wt/epsilon/beta.link
1309 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
1310 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
1311 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
1312 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
1313 (cd $testroot/wt && ln -sf alpha new.link)
1314 (cd $testroot/wt && got add new.link > /dev/null)
1316 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1317 > $testroot/stdout 2> $testroot/stderr)
1319 if [ $ret -eq 0 ]; then
1320 echo "got commit succeeded unexpectedly" >&2
1321 test_done "$testroot" "$ret"
1324 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
1325 echo "symbolic link points outside of paths under version control" \
1326 >> $testroot/stderr.expected
1327 cmp -s $testroot/stderr.expected $testroot/stderr
1329 if [ $ret -ne 0 ]; then
1330 diff -u $testroot/stderr.expected $testroot/stderr
1331 test_done "$testroot" "$ret"
1335 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1338 local head_rev=`git_show_head $testroot/repo`
1339 echo "A dotgotbar.link" > $testroot/stdout.expected
1340 echo "A new.link" >> $testroot/stdout.expected
1341 echo "M alpha.link" >> $testroot/stdout.expected
1342 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1343 echo "M epsilon.link" >> $testroot/stdout.expected
1344 echo "D nonexistent.link" >> $testroot/stdout.expected
1345 echo "Created commit $head_rev" >> $testroot/stdout.expected
1347 cmp -s $testroot/stdout.expected $testroot/stdout
1349 if [ $ret -ne 0 ]; then
1350 diff -u $testroot/stdout.expected $testroot/stdout
1351 test_done "$testroot" "$ret"
1355 got tree -r $testroot/repo -c $head_rev -R > $testroot/stdout
1356 cat > $testroot/stdout.expected <<EOF
1360 dotgotbar.link@ -> .got/bar
1364 epsilon.link@ -> gamma
1368 passwd.link@ -> /etc/passwd
1370 cmp -s $testroot/stdout.expected $testroot/stdout
1372 if [ $ret -ne 0 ]; then
1373 diff -u $testroot/stdout.expected $testroot/stdout
1375 test_done "$testroot" "$ret"
1378 test_commit_fix_bad_symlink() {
1379 local testroot=`test_init commit_fix_bad_symlink`
1381 got checkout $testroot/repo $testroot/wt > /dev/null
1383 if [ $ret -ne 0 ]; then
1384 echo "got checkout failed unexpectedly" >&2
1385 test_done "$testroot" "$ret"
1389 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1390 (cd $testroot/wt && got add passwd.link > /dev/null)
1392 (cd $testroot/wt && got commit -S -m 'commit bad symlink' \
1395 if ! [ -h $testroot/wt/passwd.link ]; then
1396 echo 'passwd.link is not a symlink' >&2
1397 test_done "$testroot" 1
1400 (cd $testroot/wt && got update >/dev/null)
1401 if [ -h $testroot/wt/passwd.link ]; then
1402 echo "passwd.link is a symlink but should be a regular file" >&2
1403 test_done "$testroot" "1"
1407 # create another work tree which will contain the "bad" symlink
1408 got checkout $testroot/repo $testroot/wt2 > /dev/null
1410 if [ $ret -ne 0 ]; then
1411 echo "got checkout failed unexpectedly" >&2
1412 test_done "$testroot" "$ret"
1416 # change "bad" symlink back into a "good" symlink
1417 (cd $testroot/wt && ln -sfT alpha passwd.link)
1419 (cd $testroot/wt && got commit -m 'fix bad symlink' \
1422 local head_rev=`git_show_head $testroot/repo`
1423 echo "M passwd.link" > $testroot/stdout.expected
1424 echo "Created commit $head_rev" >> $testroot/stdout.expected
1426 cmp -s $testroot/stdout.expected $testroot/stdout
1428 if [ $ret -ne 0 ]; then
1429 diff -u $testroot/stdout.expected $testroot/stdout
1430 test_done "$testroot" "$ret"
1434 if ! [ -h $testroot/wt/passwd.link ]; then
1435 echo 'passwd.link is not a symlink' >&2
1436 test_done "$testroot" 1
1440 readlink $testroot/wt/passwd.link > $testroot/stdout
1441 echo "alpha" > $testroot/stdout.expected
1442 cmp -s $testroot/stdout.expected $testroot/stdout
1444 if [ $ret -ne 0 ]; then
1445 diff -u $testroot/stdout.expected $testroot/stdout
1449 # Update the other work tree; the bad symlink should be fixed
1450 (cd $testroot/wt2 && got update > /dev/null)
1452 if [ $ret -ne 0 ]; then
1453 echo "got checkout failed unexpectedly" >&2
1454 test_done "$testroot" "$ret"
1458 if ! [ -h $testroot/wt2/passwd.link ]; then
1459 echo 'passwd.link is not a symlink' >&2
1460 test_done "$testroot" 1
1464 readlink $testroot/wt2/passwd.link > $testroot/stdout
1465 echo "alpha" > $testroot/stdout.expected
1466 cmp -s $testroot/stdout.expected $testroot/stdout
1468 if [ $ret -ne 0 ]; then
1469 diff -u $testroot/stdout.expected $testroot/stdout
1473 test_done "$testroot" "0"
1476 test_commit_prepared_logmsg() {
1477 local testroot=`test_init commit_prepared_logmsg`
1479 got checkout $testroot/repo $testroot/wt > /dev/null
1481 if [ $ret -ne 0 ]; then
1482 test_done "$testroot" "$ret"
1486 echo "modified alpha" > $testroot/wt/alpha
1487 (cd $testroot/wt && got rm beta >/dev/null)
1488 echo "new file" > $testroot/wt/new
1489 (cd $testroot/wt && got add new >/dev/null)
1491 echo 'test commit_prepared_logmsg' > $testroot/logmsg
1493 cat > $testroot/editor.sh <<EOF
1496 [ "\$OSTYPE" = "linux-gnu" ] && SOPTS="-i"
1497 sed "\$SOPTS" -e 's/foo/bar/' "\$1"
1499 chmod +x $testroot/editor.sh
1501 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
1502 got commit -F "$testroot/logmsg" > $testroot/stdout)
1504 local head_rev=`git_show_head $testroot/repo`
1505 echo "A new" > $testroot/stdout.expected
1506 echo "M alpha" >> $testroot/stdout.expected
1507 echo "D beta" >> $testroot/stdout.expected
1508 echo "Created commit $head_rev" >> $testroot/stdout.expected
1510 cmp -s $testroot/stdout.expected $testroot/stdout
1512 if [ $ret -ne 0 ]; then
1513 diff -u $testroot/stdout.expected $testroot/stdout
1514 test_done "$testroot" "$ret"
1518 local author_time=`git_show_author_time $testroot/repo`
1519 local prev_LC_TIME="$LC_TIME"
1521 d=`date -u -d "@$author_time" +"%a %b %e %X %Y UTC"`
1522 LC_TIME="$prev_LC_TIME"
1523 echo "-----------------------------------------------" > $testroot/stdout.expected
1524 echo "commit $head_rev (master)" >> $testroot/stdout.expected
1525 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
1526 echo "date: $d" >> $testroot/stdout.expected
1527 echo " " >> $testroot/stdout.expected
1528 echo " test commit_prepared_logmsg" >> $testroot/stdout.expected
1529 echo " " >> $testroot/stdout.expected
1531 (cd $testroot/wt && got log -l 1 > $testroot/stdout)
1532 cmp -s $testroot/stdout.expected $testroot/stdout
1534 if [ $ret -ne 0 ]; then
1535 diff -u $testroot/stdout.expected $testroot/stdout
1536 test_done "$testroot" "$ret"
1540 echo "modified alpha again" > $testroot/wt/alpha
1542 echo 'test commit_prepared_logmsg non-interactive' \
1545 (cd $testroot/wt && got commit -N -F "$testroot/logmsg" \
1548 local head_rev=`git_show_head $testroot/repo`
1549 echo "M alpha" > $testroot/stdout.expected
1550 echo "Created commit $head_rev" >> $testroot/stdout.expected
1552 cmp -s $testroot/stdout.expected $testroot/stdout
1554 if [ $ret -ne 0 ]; then
1555 diff -u $testroot/stdout.expected $testroot/stdout
1556 test_done "$testroot" "$ret"
1560 local author_time=`git_show_author_time $testroot/repo`
1561 local prev_LC_TIME="$LC_TIME"
1563 d=`date -u -d "@$author_time" +"%a %b %e %X %Y UTC"`
1564 LC_TIME="$prev_LC_TIME"
1565 echo "-----------------------------------------------" \
1566 > $testroot/stdout.expected
1567 echo "commit $head_rev (master)" >> $testroot/stdout.expected
1568 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
1569 echo "date: $d" >> $testroot/stdout.expected
1570 echo " " >> $testroot/stdout.expected
1571 echo " test commit_prepared_logmsg non-interactive" \
1572 >> $testroot/stdout.expected
1573 echo " " >> $testroot/stdout.expected
1575 (cd $testroot/wt && got log -l 1 > $testroot/stdout)
1576 cmp -s $testroot/stdout.expected $testroot/stdout
1578 if [ $ret -ne 0 ]; then
1579 diff -u $testroot/stdout.expected $testroot/stdout
1581 test_done "$testroot" "$ret"
1584 test_commit_large_file() {
1585 local testroot=`test_init commit_large_file`
1587 got checkout $testroot/repo $testroot/wt > /dev/null
1589 if [ $ret -ne 0 ]; then
1590 test_done "$testroot" "$ret"
1594 dd status=none if=/dev/zero of=$testroot/wt/new bs=1M count=64
1595 (cd $testroot/wt && got add new >/dev/null)
1597 (cd $testroot/wt && got commit -m 'test commit_large_file' \
1600 local head_rev=`git_show_head $testroot/repo`
1601 echo "A new" > $testroot/stdout.expected
1602 echo "Created commit $head_rev" >> $testroot/stdout.expected
1604 cmp -s $testroot/stdout.expected $testroot/stdout
1606 if [ $ret -ne 0 ]; then
1607 diff -u $testroot/stdout.expected $testroot/stdout
1608 test_done "$testroot" "$ret"
1612 new_id=`get_blob_id $testroot/repo "" new`
1613 got cat -r $testroot/repo $new_id > $testroot/new
1615 if [ $ret -ne 0 ]; then
1616 echo "commit failed unexpectedly" >&2
1617 test_done "$testroot" "1"
1621 cmp -s $testroot/new $testroot/wt/new
1623 if [ $ret -ne 0 ]; then
1624 diff -u $testroot/new $testroot/wt/new
1626 test_done "$testroot" "$ret"
1631 test_commit_gitignore() {
1632 local testroot=`test_init commit_gitignores`
1634 got checkout $testroot/repo $testroot/wt > /dev/null
1636 if [ $ret -ne 0 ]; then
1637 test_done "$testroot" "$ret"
1641 mkdir -p $testroot/wt/tree1/foo
1642 mkdir -p $testroot/wt/tree2/foo
1643 echo "tree1/**" > $testroot/wt/.gitignore
1644 echo "tree2/**" >> $testroot/wt/.gitignore
1645 echo -n > $testroot/wt/tree1/bar
1646 echo -n > $testroot/wt/tree1/foo/baz
1647 echo -n > $testroot/wt/tree2/bar
1648 echo -n > $testroot/wt/tree2/foo/baz
1649 echo -n > $testroot/wt/epsilon/zeta1
1650 echo -n > $testroot/wt/epsilon/zeta2
1652 (cd $testroot/wt && got add -I -R tree1 > /dev/null)
1653 (cd $testroot/wt && got add -I tree2/foo/baz > /dev/null)
1654 (cd $testroot/wt && got commit -m "gitignore add" > /dev/null)
1655 (cd $testroot/wt && got log -P -l 1 | egrep '^ .' > $testroot/stdout)
1657 echo ' gitignore add' > $testroot/stdout.expected
1658 echo ' A tree1/bar' >> $testroot/stdout.expected
1659 echo ' A tree1/foo/baz' >> $testroot/stdout.expected
1660 echo ' A tree2/foo/baz' >> $testroot/stdout.expected
1662 cmp -s $testroot/stdout.expected $testroot/stdout
1664 if [ $ret -ne 0 ]; then
1665 diff -u $testroot/stdout.expected $testroot/stdout
1666 test_done "$testroot" "$ret"
1670 echo touch > $testroot/wt/tree1/bar
1671 echo touch > $testroot/wt/tree1/foo/baz
1672 echo touch > $testroot/wt/epsilon/zeta1
1674 (cd $testroot/wt && got commit -m "gitignore change" > /dev/null)
1675 (cd $testroot/wt && got log -P -l 1 | egrep '^ .' > $testroot/stdout)
1677 echo ' gitignore change' > $testroot/stdout.expected
1678 echo ' M tree1/bar' >> $testroot/stdout.expected
1679 echo ' M tree1/foo/baz' >> $testroot/stdout.expected
1681 cmp -s $testroot/stdout.expected $testroot/stdout
1683 if [ $ret -ne 0 ]; then
1684 diff -u $testroot/stdout.expected $testroot/stdout
1685 test_done "$testroot" "$ret"
1689 test_done "$testroot" "$ret"
1692 test_commit_bad_author() {
1693 local testroot=`test_init commit_bad_author`
1695 got checkout $testroot/repo $testroot/wt > /dev/null
1697 if [ $ret -ne 0 ]; then
1698 test_done "$testroot" $ret
1702 echo "modified alpha" > $testroot/wt/alpha
1704 (cd $testroot/wt && got commit \
1705 -A "${GIT_AUTHOR_NAME}<${GIT_AUTHOR_EMAIL}>" -m 'edit alpha') \
1706 > /dev/null 2> $testroot/stderr
1708 if [ $ret -eq 0 ]; then
1709 test_done "$testroot" 1
1713 echo -n "got: ${GIT_AUTHOR_NAME}<${GIT_AUTHOR_EMAIL}>: " \
1714 > $testroot/stderr.expected
1715 echo -n 'space between author name and email required: ' \
1716 >> $testroot/stderr.expected
1717 echo 'commit author formatting would make Git unhappy' \
1718 >> $testroot/stderr.expected
1719 cmp -s $testroot/stderr.expected $testroot/stderr
1721 if [ $ret -ne 0 ]; then
1722 diff -u $testroot/stderr.expected $testroot/stderr
1723 test_done "$testroot" $ret
1727 test_done "$testroot" 0
1731 run_test test_commit_basic
1732 run_test test_commit_new_subdir
1733 run_test test_commit_subdir
1734 run_test test_commit_single_file
1735 run_test test_commit_out_of_date
1736 run_test test_commit_added_subdirs
1737 run_test test_commit_deleted_subdirs
1738 run_test test_commit_rejects_conflicted_file
1739 run_test test_commit_single_file_multiple
1740 run_test test_commit_added_and_modified_in_same_dir
1741 run_test test_commit_path_prefix
1742 run_test test_commit_dir_path
1743 run_test test_commit_selected_paths
1744 run_test test_commit_outside_refs_heads
1745 run_test test_commit_no_email
1746 run_test test_commit_tree_entry_sorting
1747 run_test test_commit_cmdline_author
1748 run_test test_commit_gotconfig_author
1749 run_test test_commit_gotconfig_worktree_author
1750 run_test test_commit_gitconfig_author
1751 run_test test_commit_xbit_change
1752 run_test test_commit_normalizes_filemodes
1753 run_test test_commit_with_unrelated_submodule
1754 run_test test_commit_symlink
1755 run_test test_commit_fix_bad_symlink
1756 run_test test_commit_prepared_logmsg
1757 run_test test_commit_large_file
1758 run_test test_commit_gitignore
1759 run_test test_commit_bad_author