make got-read-gotconfig clear its imsgbuf before exit in an error case
[got-portable.git] / regress / cmdline / commit.sh
blobc8651ab26909a5ce8ff104fcc69b1029cc18605e
1 #!/bin/sh
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.
17 . ./common.sh
19 test_commit_basic() {
20 local testroot=`test_init commit_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret=$?
24 if [ $ret -ne 0 ]; then
25 test_done "$testroot" "$ret"
26 return 1
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
43 ret=$?
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
54 ret=$?
55 if [ $ret -ne 0 ]; then
56 test_done "$testroot" "$ret"
57 return 1
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)
66 (cd $testroot/wt && \
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
75 ret=$?
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
86 ret=$?
87 if [ $ret -ne 0 ]; then
88 test_done "$testroot" "$ret"
89 return 1
92 echo "modified alpha" > $testroot/wt/alpha
93 echo "modified zeta" > $testroot/wt/epsilon/zeta
95 (cd $testroot/wt && \
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
103 ret=$?
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
114 ret=$?
115 if [ $ret -ne 0 ]; then
116 test_done "$testroot" "$ret"
117 return 1
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 \
124 > $testroot/stdout)
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
131 ret=$?
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
143 ret=$?
144 if [ $ret -ne 0 ]; then
145 test_done "$testroot" "$ret"
146 return 1
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
162 ret=$?
163 if [ $ret -ne 0 ]; then
164 diff -u $testroot/stdout.expected $testroot/stdout
165 test_done "$testroot" "$ret"
166 return 1
169 cmp -s $testroot/stderr.expected $testroot/stderr
170 ret=$?
171 if [ $ret -ne 0 ]; then
172 diff -u $testroot/stderr.expected $testroot/stderr
173 test_done "$testroot" "$ret"
174 return 1
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)
184 ret=$?
185 if [ $ret -ne 0 ]; then
186 echo "commit failed unexpectedly" >&2
187 test_done "$testroot" "1"
188 return 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
195 ret=$?
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
206 ret=$?
207 if [ $ret -ne 0 ]; then
208 test_done "$testroot" "$ret"
209 return 1
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
234 ret=$?
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
245 ret=$?
246 if [ $ret -ne 0 ]; then
247 test_done "$testroot" "$ret"
248 return 1
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
263 ret=$?
264 if [ $ret -ne 0 ]; then
265 diff -u $testroot/stdout.expected $testroot/stdout
266 test_done "$testroot" "$ret"
267 return 1
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
276 ret=$?
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
289 ret=$?
290 if [ $ret -ne 0 ]; then
291 test_done "$testroot" "$ret"
292 return 1
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
312 ret=$?
313 if [ $ret -ne 0 ]; then
314 diff -u $testroot/stdout.expected $testroot/stdout
315 test_done "$testroot" "$ret"
316 return 1
319 (cd $testroot/wt && got commit -m 'commit it' > $testroot/stdout \
320 2> $testroot/stderr)
321 ret=$?
322 if [ $ret -eq 0 ]; then
323 echo "got commit succeeded unexpectedly"
324 test_done "$testroot" "1"
325 return 1
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
333 ret=$?
334 if [ $ret -ne 0 ]; then
335 diff -u $testroot/stdout.expected $testroot/stdout
336 test_done "$testroot" "$ret"
337 return 1
339 cmp -s $testroot/stderr.expected $testroot/stderr
340 ret=$?
341 if [ $ret -ne 0 ]; then
342 diff -u $testroot/stderr.expected $testroot/stderr
343 test_done "$testroot" "$ret"
344 return 1
347 (cd $testroot/wt && got commit -C -m 'commit it' > $testroot/stdout \
348 2> $testroot/stderr)
349 ret=$?
350 if [ $ret -ne 0 ]; then
351 echo "got commit failed unexpectedly"
352 test_done "$testroot" "$ret"
353 return 1
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
365 ret=$?
366 if [ $ret -ne 0 ]; then
367 diff -u $testroot/stderr.expected $testroot/stderr
368 test_done "$testroot" "$ret"
369 return 1
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
377 commit - $commit_id1
378 commit + $conflict_commit
379 blob - $blob_minus
380 blob + $blob_plus
381 --- alpha
382 +++ alpha
383 @@ -1 +1,7 @@
384 +<<<<<<< merged change: commit $commit_id1
385 modified alpha
386 +||||||| 3-way merge base: commit $initial_rev
387 +alpha
388 +=======
389 +modified alpha, too
390 +>>>>>>>
393 cmp -s $testroot/stdout.expected $testroot/stdout
394 ret=$?
395 if [ $ret -ne 0 ]; then
396 diff -u $testroot/stdout.expected $testroot/stdout
397 test_done "$testroot" "$ret"
398 return 1
401 (cd $testroot/wt && got status > $testroot/stdout)
403 echo -n > $testroot/stdout.expected
404 cmp -s $testroot/stdout.expected $testroot/stdout
405 ret=$?
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
416 ret=$?
417 if [ $ret -ne 0 ]; then
418 test_done "$testroot" "$ret"
419 return 1
422 for i in 1 2 3 4; do
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
433 ret=$?
434 if [ $ret -ne 0 ]; then
435 diff -u $testroot/stdout.expected $testroot/stdout
436 test_done "$testroot" "$ret"
437 return 1
439 done
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
448 ret=$?
449 if [ $ret -ne 0 ]; then
450 test_done "$testroot" "$ret"
451 return 1
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 \
460 2> $testroot/stderr)
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
468 ret=$?
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
480 ret=$?
481 if [ $ret -ne 0 ]; then
482 test_done "$testroot" "$ret"
483 return 1
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
495 ret=$?
496 if [ $ret -ne 0 ]; then
497 diff -u $testroot/stdout.expected $testroot/stdout
498 test_done "$testroot" "$ret"
499 return 1
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
519 ret=$?
520 if [ $ret -ne 0 ]; then
521 diff -u $testroot/stdout.expected $testroot/stdout
522 test_done "$testroot" "$ret"
523 return 1
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' \
531 > $testroot/stdout)
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
539 ret=$?
540 if [ $ret -ne 0 ]; then
541 diff -u $testroot/stdout.expected $testroot/stdout
542 test_done "$testroot" "$ret"
543 return 1
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
570 ret=$?
571 if [ $ret -ne 0 ]; then
572 diff -u $testroot/stdout.expected $testroot/stdout
574 test_done "$testroot" "$ret"
575 return "$ret"
578 test_commit_dir_path() {
579 local testroot=`test_init commit_dir_path`
581 got checkout $testroot/repo $testroot/wt > /dev/null
582 ret=$?
583 if [ $ret -ne 0 ]; then
584 test_done "$testroot" "$ret"
585 return 1
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 \
592 > $testroot/stdout)
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
599 ret=$?
600 if [ $ret -ne 0 ]; then
601 diff -u $testroot/stdout.expected $testroot/stdout
602 test_done "$testroot" "$ret"
603 return 1
606 echo "M alpha" > $testroot/stdout.expected
607 (cd $testroot/wt && got status > $testroot/stdout)
608 cmp -s $testroot/stdout.expected $testroot/stdout
609 ret=$?
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
620 ret=$?
621 if [ $ret -ne 0 ]; then
622 test_done "$testroot" "$ret"
623 return 1
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)
635 ret=$?
636 if [ $ret -eq 0 ]; then
637 echo "commit succeeded unexpectedly" >&2
638 test_done "$testroot" "1"
639 return 1
641 echo "got: nonexistent: no changes to commit" \
642 > $testroot/stderr.expected
644 cmp -s $testroot/stderr.expected $testroot/stderr
645 ret=$?
646 if [ $ret -ne 0 ]; then
647 diff -u $testroot/stderr.expected $testroot/stderr
648 test_done "$testroot" "$ret"
649 return 1
652 (cd $testroot/wt && got commit -m 'many paths' \
653 beta new gamma > $testroot/stdout)
655 local head_rev=`git_show_head $testroot/repo`
656 echo "A new" > $testroot/stdout.expected
657 echo "D beta" >> $testroot/stdout.expected
658 echo "M gamma/delta" >> $testroot/stdout.expected
659 echo "Created commit $head_rev" >> $testroot/stdout.expected
661 cmp -s $testroot/stdout.expected $testroot/stdout
662 ret=$?
663 if [ $ret -ne 0 ]; then
664 diff -u $testroot/stdout.expected $testroot/stdout
666 test_done "$testroot" "$ret"
669 test_commit_outside_refs_heads() {
670 local testroot=`test_init commit_outside_refs_heads`
672 got ref -r $testroot/repo -c master refs/remotes/origin/master
674 got checkout -b refs/remotes/origin/master \
675 $testroot/repo $testroot/wt > /dev/null
676 ret=$?
677 if [ $ret -ne 0 ]; then
678 test_done "$testroot" "$ret"
679 return 1
682 echo "modified alpha" > $testroot/wt/alpha
684 (cd $testroot/wt && got commit -m 'change alpha' \
685 > $testroot/stdout 2> $testroot/stderr)
686 ret=$?
687 if [ $ret -eq 0 ]; then
688 echo "commit succeeded unexpectedly" >&2
689 test_done "$testroot" "1"
690 return 1
693 echo -n > $testroot/stdout.expected
694 cmp -s $testroot/stdout.expected $testroot/stdout
695 ret=$?
696 if [ $ret -ne 0 ]; then
697 diff -u $testroot/stdout.expected $testroot/stdout
698 test_done "$testroot" "$ret"
699 return 1
702 echo -n "got: will not commit to a branch outside the " \
703 > $testroot/stderr.expected
704 echo '"refs/heads/" reference namespace' \
705 >> $testroot/stderr.expected
706 cmp -s $testroot/stderr.expected $testroot/stderr
707 ret=$?
708 if [ $ret -ne 0 ]; then
709 diff -u $testroot/stderr.expected $testroot/stderr
711 test_done "$testroot" "$ret"
714 test_commit_no_email() {
715 local testroot=`test_init commit_no_email`
716 local errmsg=""
718 errmsg="commit author's email address is required for"
719 errmsg="$errmsg compatibility with Git"
721 got checkout $testroot/repo $testroot/wt > /dev/null
722 ret=$?
723 if [ $ret -ne 0 ]; then
724 test_done "$testroot" "$ret"
725 return 1
728 echo "modified alpha" > $testroot/wt/alpha
729 (cd $testroot/wt && env GOT_AUTHOR=":flan_hacker:" \
730 got commit -m 'test no email' > $testroot/stdout \
731 2> $testroot/stderr)
733 printf "got: :flan_hacker:: %s\n" "$errmsg" > $testroot/stderr.expected
734 cmp -s $testroot/stderr.expected $testroot/stderr
735 ret=$?
736 if [ $ret -ne 0 ]; then
737 diff -u $testroot/stderr.expected $testroot/stderr
738 test_done "$testroot" "$ret"
739 return 1
742 echo -n > $testroot/stdout.expected
743 cmp -s $testroot/stdout.expected $testroot/stdout
744 ret=$?
745 if [ $ret -ne 0 ]; then
746 diff -u $testroot/stdout.expected $testroot/stdout
747 test_done "$testroot" $ret
748 return 1
751 # try again with a newline inside the email
752 (cd $testroot/wt \
753 && FS=' ' env GOT_AUTHOR="$(printf "Flan <hack\ner>")" \
754 got commit -m 'test invalid email' > $testroot/stdout \
755 2> $testroot/stderr)
757 printf "got: Flan <hack\ner>: %s\n" "$errmsg" \
758 > $testroot/stderr.expected
759 cmp -s $testroot/stderr.expected $testroot/stderr
760 ret=$?
761 if [ $ret -ne 0 ]; then
762 diff -u $testroot/stderr.expected $testroot/stderr
763 test_done "$testroot" $ret
764 return 1
767 echo -n > $testroot/stdout.expected
768 cmp -s $testroot/stdout.expected $testroot/stdout
769 ret=$?
770 if [ $ret -ne 0 ]; then
771 diff -u $testroot/stdout.expected $testroot/stdout
772 test_done "$testroot" $ret
773 return 1
776 # try again with a < inside the email
777 (cd $testroot/wt && env GOT_AUTHOR="$(printf "Flan <ha<ker>")" \
778 got commit -m 'test invalid email' > $testroot/stdout \
779 2> $testroot/stderr)
781 printf "got: Flan <ha<ker>: %s\n" "$errmsg" > $testroot/stderr.expected
782 cmp -s $testroot/stderr.expected $testroot/stderr
783 ret=$?
784 if [ $ret -ne 0 ]; then
785 diff -u $testroot/stderr.expected $testroot/stderr
786 test_done "$testroot" $ret
787 return 1
790 echo -n > $testroot/stdout.expected
791 cmp -s $testroot/stdout.expected $testroot/stdout
792 ret=$?
793 if [ $ret -ne 0 ]; then
794 diff -u $testroot/stdout.expected $testroot/stdout
796 test_done "$testroot" $ret
799 test_commit_tree_entry_sorting() {
800 local testroot=`test_init commit_tree_entry_sorting`
802 got checkout $testroot/repo $testroot/wt > /dev/null
803 ret=$?
804 if [ $ret -ne 0 ]; then
805 test_done "$testroot" "$ret"
806 return 1
809 # Git's index gets corrupted when tree entries are written in the
810 # order defined by got_path_cmp() rather than Git's own ordering.
811 # Create a new tree where a directory "got" and a file "got-version"
812 # would sort in the wrong order according to Git's opinion.
813 mkdir $testroot/wt/got
814 touch $testroot/wt/got/foo
815 echo foo > $testroot/wt/got-version
816 echo zzz > $testroot/wt/zzz
817 (cd $testroot/wt && got add got-version got/foo zzz > /dev/null)
819 (cd $testroot/wt && got commit -m 'test' > /dev/null)
821 # Let git-fsck verify the newly written tree to make sure Git is happy
822 git -C $testroot/repo fsck --strict \
823 > $testroot/fsck.stdout 2> $testroot/fsck.stderr
824 ret=$?
825 test_done "$testroot" "$ret"
828 test_commit_cmdline_author() {
829 local testroot=`test_init commit_cmdline_author`
831 got checkout $testroot/repo $testroot/wt > /dev/null
832 ret=$?
833 if [ $ret -ne 0 ]; then
834 test_done "$testroot" $ret
835 return 1
838 echo "modified alpha" > $testroot/wt/alpha
840 local author="Foo <foo@example.com>"
841 (cd $testroot/wt && got commit -A "$author" -m 'edit alpha') \
842 > /dev/null
843 ret=$?
844 if [ $ret -ne 0 ]; then
845 test_done "$testroot" $ret
846 return 1
849 (cd $testroot/repo && got log -l1 | egrep '^(from|via):') \
850 > $testroot/stdout
851 ret=$?
852 if [ $ret -ne 0 ]; then
853 test_done "$testroot" $ret
854 return 1
857 echo "from: $author" > $testroot/stdout.expected
858 echo "via: $GOT_AUTHOR" >> $testroot/stdout.expected
859 cmp -s $testroot/stdout.expected $testroot/stdout
860 ret=$?
861 if [ $ret -ne 0 ]; then
862 diff -u $testroot/stdout.expected $testroot/stdout
864 test_done "$testroot" $ret
867 test_commit_gotconfig_author() {
868 local testroot=`test_init commit_gotconfig_author`
870 got checkout $testroot/repo $testroot/wt > /dev/null
871 ret=$?
872 if [ $ret -ne 0 ]; then
873 test_done "$testroot" "$ret"
874 return 1
876 echo 'author "Flan Luck <flan_luck@openbsd.org>"' \
877 > $testroot/repo/.git/got.conf
879 echo "modified alpha" > $testroot/wt/alpha
880 (cd $testroot/wt && got commit -m 'test gotconfig author' > /dev/null)
881 ret=$?
882 if [ $ret -ne 0 ]; then
883 test_done "$testroot" "$ret"
884 return 1
887 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
888 ret=$?
889 if [ $ret -ne 0 ]; then
890 test_done "$testroot" "$ret"
891 return 1
894 echo "from: Flan Luck <flan_luck@openbsd.org>" \
895 > $testroot/stdout.expected
896 cmp -s $testroot/stdout.expected $testroot/stdout
897 ret=$?
898 if [ $ret -ne 0 ]; then
899 diff -u $testroot/stdout.expected $testroot/stdout
901 test_done "$testroot" "$ret"
904 test_commit_gotconfig_worktree_author() {
905 local testroot=`test_init commit_gotconfig_worktree_author`
907 got checkout $testroot/repo $testroot/wt > /dev/null
908 ret=$?
909 if [ $ret -ne 0 ]; then
910 test_done "$testroot" "$ret"
911 return 1
913 echo 'author "Flan Luck <flan_luck@openbsd.org>"' \
914 > $testroot/repo/.git/got.conf
915 echo 'author "Flan Squee <flan_squee@openbsd.org>"' \
916 > $testroot/wt/.got/got.conf
918 echo "modified alpha" > $testroot/wt/alpha
919 (cd $testroot/wt && got commit -m 'test gotconfig author' > /dev/null)
920 ret=$?
921 if [ $ret -ne 0 ]; then
922 test_done "$testroot" "$ret"
923 return 1
926 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
927 ret=$?
928 if [ $ret -ne 0 ]; then
929 test_done "$testroot" "$ret"
930 return 1
933 echo "from: Flan Squee <flan_squee@openbsd.org>" \
934 > $testroot/stdout.expected
935 cmp -s $testroot/stdout.expected $testroot/stdout
936 ret=$?
937 if [ $ret -ne 0 ]; then
938 diff -u $testroot/stdout.expected $testroot/stdout
940 test_done "$testroot" "$ret"
943 test_commit_gitconfig_author() {
944 local testroot=`test_init commit_gitconfig_author`
946 got checkout $testroot/repo $testroot/wt > /dev/null
947 ret=$?
948 if [ $ret -ne 0 ]; then
949 test_done "$testroot" "$ret"
950 return 1
953 git -C $testroot/repo config user.name 'Flan Luck'
954 git -C $testroot/repo config user.email 'flan_luck@openbsd.org'
956 echo "modified alpha" > $testroot/wt/alpha
958 # unset in a subshell to avoid affecting our environment
959 (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
960 got commit -m 'test gitconfig author' > /dev/null)
961 ret=$?
962 if [ $ret -ne 0 ]; then
963 test_done "$testroot" "$ret"
964 return 1
967 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
968 ret=$?
969 if [ $ret -ne 0 ]; then
970 test_done "$testroot" "$ret"
971 return 1
974 echo "from: Flan Luck <flan_luck@openbsd.org>" \
975 > $testroot/stdout.expected
976 cmp -s $testroot/stdout.expected $testroot/stdout
977 ret=$?
978 if [ $ret -ne 0 ]; then
979 diff -u $testroot/stdout.expected $testroot/stdout
980 test_done "$testroot" "$ret"
981 return 1
984 # retry with spaces in the git config
985 ed -s "$testroot/repo/.git/config" <<EOF
986 /^\[user/ a
987 # it's me!
989 ,s/ / /g
992 echo "modified again" > $testroot/wt/alpha
994 # unset in a subshell to avoid affecting our environment
995 (unset GOT_IGNORE_GITCONFIG && cd "$testroot/wt" && \
996 got commit -m 'test gitconfig author again' \
997 >/dev/null 2>$testroot/stderr)
998 ret=$?
999 if [ $ret -ne 0 ]; then
1000 test_done "$testroot" "$ret"
1001 return 1
1004 # shouldn't have triggered any parsing error
1005 echo -n > $testroot/stderr.expected
1006 cmp -s $testroot/stderr.expected $testroot/stderr
1007 ret=$?
1008 if [ $ret -ne 0 ]; then
1009 diff -u $testroot/stderr.expected $testroot/stderr
1010 test_done "$testroot" "$ret"
1011 return 1
1014 (cd "$testroot/repo" && got log -l1 | grep ^from: > $testroot/stdout)
1015 ret=$?
1016 if [ $ret -ne 0 ]; then
1017 test_done "$testroot" "$ret"
1018 return 1
1021 echo "from: Flan Luck <flan_luck@openbsd.org>" \
1022 > $testroot/stdout.expected
1023 cmp -s $testroot/stdout.expected $testroot/stdout
1024 ret=$?
1025 if [ $ret -ne 0 ]; then
1026 diff -u $testroot/stdout.expected $testroot/stdout
1028 test_done "$testroot" "$ret"
1031 test_commit_xbit_change() {
1032 local testroot=`test_init commit_xbit_change`
1034 got checkout $testroot/repo $testroot/wt > /dev/null
1035 ret=$?
1036 if [ $ret -ne 0 ]; then
1037 test_done "$testroot" "$ret"
1038 return 1
1041 chmod +x $testroot/wt/alpha
1043 echo 'm alpha' > $testroot/stdout.expected
1044 (cd $testroot/wt && got status > $testroot/stdout)
1046 cmp -s $testroot/stdout.expected $testroot/stdout
1047 ret=$?
1048 if [ $ret -ne 0 ]; then
1049 diff -u $testroot/stdout.expected $testroot/stdout
1050 test_done "$testroot" "$ret"
1051 return 1
1054 (cd $testroot/wt && got commit -mx > $testroot/stdout)
1055 ret=$?
1056 if [ $ret -ne 0 ]; then
1057 echo "got commit failed unexpectedly"
1058 test_done "$testroot" "$ret"
1059 return 1
1062 local commit_id=`git_show_head $testroot/repo`
1063 echo 'm alpha' > $testroot/stdout.expected
1064 echo "Created commit $commit_id" >> $testroot/stdout.expected
1065 cmp -s $testroot/stdout.expected $testroot/stdout
1066 ret=$?
1067 if [ $ret -ne 0 ]; then
1068 diff -u $testroot/stdout.expected $testroot/stdout
1069 test_done "$testroot" "$ret"
1070 return 1
1073 (cd $testroot/wt && got status > $testroot/stdout)
1075 echo -n > $testroot/stdout.expected
1076 cmp -s $testroot/stdout.expected $testroot/stdout
1077 ret=$?
1078 if [ $ret -ne 0 ]; then
1079 diff -u $testroot/stdout.expected $testroot/stdout
1080 test_done "$testroot" "$ret"
1081 return 1
1084 chmod -x $testroot/wt/alpha
1086 echo 'm alpha' > $testroot/stdout.expected
1087 (cd $testroot/wt && got status > $testroot/stdout)
1089 cmp -s $testroot/stdout.expected $testroot/stdout
1090 ret=$?
1091 if [ $ret -ne 0 ]; then
1092 diff -u $testroot/stdout.expected $testroot/stdout
1093 test_done "$testroot" "$ret"
1094 return 1
1097 (cd $testroot/wt && got commit -mx > $testroot/stdout)
1098 ret=$?
1099 if [ $ret -ne 0 ]; then
1100 echo "got commit failed unexpectedly"
1101 test_done "$testroot" "$ret"
1102 return 1
1105 local commit_id=`git_show_head $testroot/repo`
1106 echo 'm alpha' > $testroot/stdout.expected
1107 echo "Created commit $commit_id" >> $testroot/stdout.expected
1108 cmp -s $testroot/stdout.expected $testroot/stdout
1109 ret=$?
1110 if [ $ret -ne 0 ]; then
1111 diff -u $testroot/stdout.expected $testroot/stdout
1112 test_done "$testroot" "$ret"
1113 return 1
1116 chmod +x $testroot/wt/alpha
1118 echo 'm alpha' > $testroot/stdout.expected
1119 (cd $testroot/wt && got status > $testroot/stdout)
1121 cmp -s $testroot/stdout.expected $testroot/stdout
1122 ret=$?
1123 if [ $ret -ne 0 ]; then
1124 diff -u $testroot/stdout.expected $testroot/stdout
1126 test_done "$testroot" "$ret"
1129 commit_check_mode() {
1130 local mode="$1"
1131 local expected_mode="$2"
1133 chmod 644 $testroot/wt/alpha
1134 echo a >> $testroot/wt/alpha
1135 chmod $mode $testroot/wt/alpha
1137 (cd $testroot/wt && got commit -mm > $testroot/stdout)
1138 ret=$?
1139 if [ $ret -ne 0 ]; then
1140 echo "got commit failed unexpectedly"
1141 test_done "$testroot" "$ret"
1142 return 1
1145 local commit_id=`git_show_head $testroot/repo`
1146 echo 'M alpha' > $testroot/stdout.expected
1147 echo "Created commit $commit_id" >> $testroot/stdout.expected
1148 cmp -s $testroot/stdout.expected $testroot/stdout
1149 ret=$?
1150 if [ $ret -ne 0 ]; then
1151 diff -u $testroot/stdout.expected $testroot/stdout
1152 test_done "$testroot" "$ret"
1153 return 1
1156 local tree_id=$(got cat -r $testroot/repo $commit_id | \
1157 grep ^tree | cut -d' ' -f2)
1158 local alpha_id=$(got cat -r $testroot/repo $tree_id | \
1159 grep 'alpha$' | cut -d' ' -f1)
1160 echo "$alpha_id $expected_mode alpha" > $testroot/stdout.expected
1161 got cat -r $testroot/repo $tree_id | grep 'alpha$' > $testroot/stdout
1162 cmp -s $testroot/stdout.expected $testroot/stdout
1163 ret=$?
1164 if [ $ret -ne 0 ]; then
1165 diff -u $testroot/stdout.expected $testroot/stdout
1167 return $ret
1170 test_commit_normalizes_filemodes() {
1171 local testroot=`test_init commit_normalizes_filemodes`
1173 got checkout $testroot/repo $testroot/wt > /dev/null
1174 ret=$?
1175 if [ $ret -ne 0 ]; then
1176 test_done "$testroot" "$ret"
1177 return 1
1180 modes="600 400 460 640 440 660 444 666"
1181 for m in $modes; do
1182 commit_check_mode "$m" "0100644"
1183 ret=$?
1184 if [ $ret -ne 0 ]; then
1185 break
1187 done
1188 if [ $ret -ne 0 ]; then
1189 test_done "$testroot" "$ret"
1190 return 1
1192 modes="700 500 570 750 550 770 555 777"
1193 for m in $modes; do
1194 commit_check_mode "$m" "0100755"
1195 ret=$?
1196 if [ $ret -ne 0 ]; then
1197 break
1199 done
1200 if [ $ret -ne 0 ]; then
1201 test_done "$testroot" "$ret"
1202 return 1
1204 test_done "$testroot" "$ret"
1207 test_commit_with_unrelated_submodule() {
1208 local testroot=`test_init commit_with_unrelated_submodule`
1210 make_single_file_repo $testroot/repo2 foo
1212 git -C $testroot/repo -c protocol.file.allow=always \
1213 submodule -q add ../repo2
1214 git -C $testroot/repo commit -q -m 'adding submodule'
1216 got checkout $testroot/repo $testroot/wt > /dev/null
1217 ret=$?
1218 if [ $ret -ne 0 ]; then
1219 echo "checkout failed unexpectedly" >&2
1220 test_done "$testroot" "$ret"
1221 return 1
1224 echo "modified alpha" > $testroot/wt/alpha
1226 echo "" > $testroot/stdout.expected
1228 (cd $testroot/wt && got commit -m 'modify alpha' > $testroot/stdout)
1229 ret=$?
1230 if [ $ret -ne 0 ]; then
1231 echo "commit failed unexpectedly" >&2
1232 test_done "$testroot" "$ret"
1233 return 1
1236 local head_rev=`git_show_head $testroot/repo`
1237 echo "M alpha" > $testroot/stdout.expected
1238 echo "Created commit $head_rev" >> $testroot/stdout.expected
1240 cmp -s $testroot/stdout.expected $testroot/stdout
1241 ret=$?
1242 if [ $ret -ne 0 ]; then
1243 diff -u $testroot/stdout.expected $testroot/stdout
1245 test_done "$testroot" "$ret"
1248 check_symlinks() {
1249 local wtpath="$1"
1250 if ! [ -h $wtpath/alpha.link ]; then
1251 echo "alpha.link is not a symlink"
1252 return 1
1255 readlink $wtpath/alpha.link > $testroot/stdout
1256 echo "alpha" > $testroot/stdout.expected
1257 cmp -s $testroot/stdout.expected $testroot/stdout
1258 ret=$?
1259 if [ $ret -ne 0 ]; then
1260 diff -u $testroot/stdout.expected $testroot/stdout
1261 return 1
1264 if ! [ -h $wtpath/epsilon.link ]; then
1265 echo "epsilon.link is not a symlink"
1266 return 1
1269 readlink $wtpath/epsilon.link > $testroot/stdout
1270 echo "epsilon" > $testroot/stdout.expected
1271 cmp -s $testroot/stdout.expected $testroot/stdout
1272 ret=$?
1273 if [ $ret -ne 0 ]; then
1274 diff -u $testroot/stdout.expected $testroot/stdout
1275 return 1
1278 if [ -h $wtpath/passwd.link ]; then
1279 echo -n "passwd.link is a symlink and points outside of work tree: " >&2
1280 readlink $wtpath/passwd.link >&2
1281 return 1
1284 echo -n "/etc/passwd" > $testroot/content.expected
1285 cp $wtpath/passwd.link $testroot/content
1286 ret=$?
1287 if [ $ret -ne 0 ]; then
1288 echo "cp command failed unexpectedly" >&2
1289 return 1
1292 cmp -s $testroot/content.expected $testroot/content
1293 ret=$?
1294 if [ $ret -ne 0 ]; then
1295 diff -u $testroot/content.expected $testroot/content
1296 return 1
1299 readlink $wtpath/epsilon/beta.link > $testroot/stdout
1300 echo "../beta" > $testroot/stdout.expected
1301 cmp -s $testroot/stdout.expected $testroot/stdout
1302 ret=$?
1303 if [ $ret -ne 0 ]; then
1304 diff -u $testroot/stdout.expected $testroot/stdout
1305 return 1
1308 readlink $wtpath/nonexistent.link > $testroot/stdout
1309 echo "nonexistent" > $testroot/stdout.expected
1310 cmp -s $testroot/stdout.expected $testroot/stdout
1311 ret=$?
1312 if [ $ret -ne 0 ]; then
1313 diff -u $testroot/stdout.expected $testroot/stdout
1314 return 1
1317 return 0
1320 test_commit_symlink() {
1321 local testroot=`test_init commit_symlink`
1323 got checkout $testroot/repo $testroot/wt > /dev/null
1324 ret=$?
1325 if [ $ret -ne 0 ]; then
1326 test_done "$testroot" "$ret"
1327 return 1
1330 (cd $testroot/wt && ln -s alpha alpha.link)
1331 (cd $testroot/wt && ln -s epsilon epsilon.link)
1332 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1333 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
1334 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
1335 (cd $testroot/wt && got add alpha.link epsilon.link passwd.link \
1336 epsilon/beta.link nonexistent.link > /dev/null)
1338 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1339 > $testroot/stdout 2> $testroot/stderr)
1340 ret=$?
1341 if [ $ret -eq 0 ]; then
1342 echo "got commit succeeded unexpectedly" >&2
1343 test_done "$testroot" "1"
1344 return 1
1346 echo -n "got: $testroot/wt/passwd.link: " > $testroot/stderr.expected
1347 echo "symbolic link points outside of paths under version control" \
1348 >> $testroot/stderr.expected
1349 cmp -s $testroot/stderr.expected $testroot/stderr
1350 ret=$?
1351 if [ $ret -ne 0 ]; then
1352 diff -u $testroot/stderr.expected $testroot/stderr
1353 test_done "$testroot" "$ret"
1354 return 1
1357 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1358 > $testroot/stdout)
1360 local head_rev=`git_show_head $testroot/repo`
1361 echo "A alpha.link" > $testroot/stdout.expected
1362 echo "A epsilon.link" >> $testroot/stdout.expected
1363 echo "A nonexistent.link" >> $testroot/stdout.expected
1364 echo "A passwd.link" >> $testroot/stdout.expected
1365 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1366 echo "Created commit $head_rev" >> $testroot/stdout.expected
1368 cmp -s $testroot/stdout.expected $testroot/stdout
1369 ret=$?
1370 if [ $ret -ne 0 ]; then
1371 diff -u $testroot/stdout.expected $testroot/stdout
1372 test_done "$testroot" "$ret"
1373 return 1
1376 # verify created in-repository tree
1377 got checkout $testroot/repo $testroot/wt2 > /dev/null
1378 ret=$?
1379 if [ $ret -ne 0 ]; then
1380 test_done "$testroot" "$ret"
1381 return 1
1383 check_symlinks $testroot/wt2
1384 ret=$?
1385 if [ $ret -ne 0 ]; then
1386 test_done "$testroot" "$ret"
1387 return 1
1390 if ! [ -h $testroot/wt/passwd.link ]; then
1391 echo 'passwd.link is not a symlink' >&2
1392 test_done "$testroot" 1
1393 return 1
1396 # 'got update' should reinstall passwd.link as a regular file
1397 (cd $testroot/wt && got update > /dev/null)
1398 check_symlinks $testroot/wt
1399 ret=$?
1400 if [ $ret -ne 0 ]; then
1401 test_done "$testroot" "$ret"
1402 return 1
1405 (cd $testroot/wt && ln -sf beta alpha.link)
1406 (cd $testroot/wt && rm epsilon.link && ln -s gamma epsilon.link)
1407 rm $testroot/wt/epsilon/beta.link
1408 echo "this is a regular file" > $testroot/wt/epsilon/beta.link
1409 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
1410 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
1411 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
1412 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
1413 (cd $testroot/wt && ln -sf alpha new.link)
1414 (cd $testroot/wt && got add new.link > /dev/null)
1416 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1417 > $testroot/stdout 2> $testroot/stderr)
1418 ret=$?
1419 if [ $ret -eq 0 ]; then
1420 echo "got commit succeeded unexpectedly" >&2
1421 test_done "$testroot" "1"
1422 return 1
1424 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
1425 echo "symbolic link points outside of paths under version control" \
1426 >> $testroot/stderr.expected
1427 cmp -s $testroot/stderr.expected $testroot/stderr
1428 ret=$?
1429 if [ $ret -ne 0 ]; then
1430 diff -u $testroot/stderr.expected $testroot/stderr
1431 test_done "$testroot" "$ret"
1432 return 1
1435 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1436 > $testroot/stdout)
1438 local head_rev=`git_show_head $testroot/repo`
1439 echo "A dotgotbar.link" > $testroot/stdout.expected
1440 echo "A new.link" >> $testroot/stdout.expected
1441 echo "M alpha.link" >> $testroot/stdout.expected
1442 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1443 echo "M epsilon.link" >> $testroot/stdout.expected
1444 echo "D nonexistent.link" >> $testroot/stdout.expected
1445 echo "Created commit $head_rev" >> $testroot/stdout.expected
1447 cmp -s $testroot/stdout.expected $testroot/stdout
1448 ret=$?
1449 if [ $ret -ne 0 ]; then
1450 diff -u $testroot/stdout.expected $testroot/stdout
1451 test_done "$testroot" "$ret"
1452 return 1
1455 got tree -r $testroot/repo -c $head_rev -R > $testroot/stdout
1456 cat > $testroot/stdout.expected <<EOF
1457 alpha
1458 alpha.link@ -> beta
1459 beta
1460 dotgotbar.link@ -> .got/bar
1461 epsilon/
1462 epsilon/beta.link
1463 epsilon/zeta
1464 epsilon.link@ -> gamma
1465 gamma/
1466 gamma/delta
1467 new.link@ -> alpha
1468 passwd.link@ -> /etc/passwd
1470 cmp -s $testroot/stdout.expected $testroot/stdout
1471 ret=$?
1472 if [ $ret -ne 0 ]; then
1473 diff -u $testroot/stdout.expected $testroot/stdout
1475 test_done "$testroot" "$ret"
1478 test_commit_fix_bad_symlink() {
1479 local testroot=`test_init commit_fix_bad_symlink`
1481 got checkout $testroot/repo $testroot/wt > /dev/null
1482 ret=$?
1483 if [ $ret -ne 0 ]; then
1484 echo "got checkout failed unexpectedly" >&2
1485 test_done "$testroot" "$ret"
1486 return 1
1489 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1490 (cd $testroot/wt && got add passwd.link > /dev/null)
1492 (cd $testroot/wt && got commit -S -m 'commit bad symlink' \
1493 > $testroot/stdout)
1495 if ! [ -h $testroot/wt/passwd.link ]; then
1496 echo 'passwd.link is not a symlink' >&2
1497 test_done "$testroot" 1
1498 return 1
1500 (cd $testroot/wt && got update >/dev/null)
1501 if [ -h $testroot/wt/passwd.link ]; then
1502 echo "passwd.link is a symlink but should be a regular file" >&2
1503 test_done "$testroot" "1"
1504 return 1
1507 # create another work tree which will contain the "bad" symlink
1508 got checkout $testroot/repo $testroot/wt2 > /dev/null
1509 ret=$?
1510 if [ $ret -ne 0 ]; then
1511 echo "got checkout failed unexpectedly" >&2
1512 test_done "$testroot" "$ret"
1513 return 1
1516 # change "bad" symlink back into a "good" symlink
1517 (cd $testroot/wt && rm passwd.link && ln -s alpha passwd.link)
1519 (cd $testroot/wt && got commit -m 'fix bad symlink' \
1520 > $testroot/stdout)
1522 local head_rev=`git_show_head $testroot/repo`
1523 echo "M passwd.link" > $testroot/stdout.expected
1524 echo "Created commit $head_rev" >> $testroot/stdout.expected
1526 cmp -s $testroot/stdout.expected $testroot/stdout
1527 ret=$?
1528 if [ $ret -ne 0 ]; then
1529 diff -u $testroot/stdout.expected $testroot/stdout
1530 test_done "$testroot" "$ret"
1531 return 1
1534 if ! [ -h $testroot/wt/passwd.link ]; then
1535 echo 'passwd.link is not a symlink' >&2
1536 test_done "$testroot" 1
1537 return 1
1540 readlink $testroot/wt/passwd.link > $testroot/stdout
1541 echo "alpha" > $testroot/stdout.expected
1542 cmp -s $testroot/stdout.expected $testroot/stdout
1543 ret=$?
1544 if [ $ret -ne 0 ]; then
1545 diff -u $testroot/stdout.expected $testroot/stdout
1546 return 1
1549 # Update the other work tree; the bad symlink should be fixed
1550 (cd $testroot/wt2 && got update > /dev/null)
1551 ret=$?
1552 if [ $ret -ne 0 ]; then
1553 echo "got checkout failed unexpectedly" >&2
1554 test_done "$testroot" "$ret"
1555 return 1
1558 if ! [ -h $testroot/wt2/passwd.link ]; then
1559 echo 'passwd.link is not a symlink' >&2
1560 test_done "$testroot" 1
1561 return 1
1564 readlink $testroot/wt2/passwd.link > $testroot/stdout
1565 echo "alpha" > $testroot/stdout.expected
1566 cmp -s $testroot/stdout.expected $testroot/stdout
1567 ret=$?
1568 if [ $ret -ne 0 ]; then
1569 diff -u $testroot/stdout.expected $testroot/stdout
1570 return 1
1573 test_done "$testroot" "0"
1576 test_commit_prepared_logmsg() {
1577 local testroot=`test_init commit_prepared_logmsg`
1579 got checkout $testroot/repo $testroot/wt > /dev/null
1580 ret=$?
1581 if [ $ret -ne 0 ]; then
1582 test_done "$testroot" "$ret"
1583 return 1
1586 echo "modified alpha" > $testroot/wt/alpha
1587 (cd $testroot/wt && got rm beta >/dev/null)
1588 echo "new file" > $testroot/wt/new
1589 (cd $testroot/wt && got add new >/dev/null)
1591 echo 'test commit_prepared_logmsg' > $testroot/logmsg
1593 # a no-op editor script
1594 > $testroot/editor.sh
1595 chmod +x $testroot/editor.sh
1597 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
1598 got commit -F "$testroot/logmsg" > $testroot/stdout)
1600 local head_rev=`git_show_head $testroot/repo`
1601 echo "A new" > $testroot/stdout.expected
1602 echo "M alpha" >> $testroot/stdout.expected
1603 echo "D beta" >> $testroot/stdout.expected
1604 echo "Created commit $head_rev" >> $testroot/stdout.expected
1606 cmp -s $testroot/stdout.expected $testroot/stdout
1607 ret=$?
1608 if [ $ret -ne 0 ]; then
1609 diff -u $testroot/stdout.expected $testroot/stdout
1610 test_done "$testroot" "$ret"
1611 return 1
1614 local author_time=`git_show_author_time $testroot/repo`
1615 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
1616 echo "-----------------------------------------------" > $testroot/stdout.expected
1617 echo "commit $head_rev (master)" >> $testroot/stdout.expected
1618 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
1619 echo "date: $d" >> $testroot/stdout.expected
1620 echo " " >> $testroot/stdout.expected
1621 echo " test commit_prepared_logmsg" >> $testroot/stdout.expected
1622 echo " " >> $testroot/stdout.expected
1624 (cd $testroot/wt && got log -l 1 > $testroot/stdout)
1625 cmp -s $testroot/stdout.expected $testroot/stdout
1626 ret=$?
1627 if [ $ret -ne 0 ]; then
1628 diff -u $testroot/stdout.expected $testroot/stdout
1629 test_done "$testroot" "$ret"
1630 return 1
1633 echo "modified alpha again" > $testroot/wt/alpha
1635 echo 'test commit_prepared_logmsg non-interactive' \
1636 > $testroot/logmsg
1638 (cd $testroot/wt && got commit -N -F "$testroot/logmsg" \
1639 > $testroot/stdout)
1641 local head_rev=`git_show_head $testroot/repo`
1642 echo "M alpha" > $testroot/stdout.expected
1643 echo "Created commit $head_rev" >> $testroot/stdout.expected
1645 cmp -s $testroot/stdout.expected $testroot/stdout
1646 ret=$?
1647 if [ $ret -ne 0 ]; then
1648 diff -u $testroot/stdout.expected $testroot/stdout
1649 test_done "$testroot" "$ret"
1650 return 1
1653 local author_time=`git_show_author_time $testroot/repo`
1654 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
1655 echo "-----------------------------------------------" \
1656 > $testroot/stdout.expected
1657 echo "commit $head_rev (master)" >> $testroot/stdout.expected
1658 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
1659 echo "date: $d" >> $testroot/stdout.expected
1660 echo " " >> $testroot/stdout.expected
1661 echo " test commit_prepared_logmsg non-interactive" \
1662 >> $testroot/stdout.expected
1663 echo " " >> $testroot/stdout.expected
1665 (cd $testroot/wt && got log -l 1 > $testroot/stdout)
1666 cmp -s $testroot/stdout.expected $testroot/stdout
1667 ret=$?
1668 if [ $ret -ne 0 ]; then
1669 diff -u $testroot/stdout.expected $testroot/stdout
1671 test_done "$testroot" "$ret"
1674 test_commit_large_file() {
1675 local testroot=`test_init commit_large_file`
1677 got checkout $testroot/repo $testroot/wt > /dev/null
1678 ret=$?
1679 if [ $ret -ne 0 ]; then
1680 test_done "$testroot" "$ret"
1681 return 1
1684 dd status=none if=/dev/zero of=$testroot/wt/new bs=1M count=64
1685 (cd $testroot/wt && got add new >/dev/null)
1687 (cd $testroot/wt && got commit -m 'test commit_large_file' \
1688 > $testroot/stdout)
1690 local head_rev=`git_show_head $testroot/repo`
1691 echo "A new" > $testroot/stdout.expected
1692 echo "Created commit $head_rev" >> $testroot/stdout.expected
1694 cmp -s $testroot/stdout.expected $testroot/stdout
1695 ret=$?
1696 if [ $ret -ne 0 ]; then
1697 diff -u $testroot/stdout.expected $testroot/stdout
1698 test_done "$testroot" "$ret"
1699 return 1
1702 new_id=`get_blob_id $testroot/repo "" new`
1703 got cat -r $testroot/repo $new_id > $testroot/new
1704 ret=$?
1705 if [ $ret -ne 0 ]; then
1706 echo "commit failed unexpectedly" >&2
1707 test_done "$testroot" "1"
1708 return 1
1711 cmp -s $testroot/new $testroot/wt/new
1712 ret=$?
1713 if [ $ret -ne 0 ]; then
1714 diff -u $testroot/new $testroot/wt/new
1716 test_done "$testroot" "$ret"
1721 test_commit_gitignore() {
1722 local testroot=`test_init commit_gitignores`
1724 got checkout $testroot/repo $testroot/wt > /dev/null
1725 ret=$?
1726 if [ $ret -ne 0 ]; then
1727 test_done "$testroot" "$ret"
1728 return 1
1731 mkdir -p $testroot/wt/tree1/foo
1732 mkdir -p $testroot/wt/tree2/foo
1733 echo "tree1/**" > $testroot/wt/.gitignore
1734 echo "tree2/**" >> $testroot/wt/.gitignore
1735 echo -n > $testroot/wt/tree1/bar
1736 echo -n > $testroot/wt/tree1/foo/baz
1737 echo -n > $testroot/wt/tree2/bar
1738 echo -n > $testroot/wt/tree2/foo/baz
1739 echo -n > $testroot/wt/epsilon/zeta1
1740 echo -n > $testroot/wt/epsilon/zeta2
1742 (cd $testroot/wt && got add -I -R tree1 > /dev/null)
1743 (cd $testroot/wt && got add -I tree2/foo/baz > /dev/null)
1744 (cd $testroot/wt && got commit -m "gitignore add" > /dev/null)
1745 (cd $testroot/wt && got log -P -l 1 | egrep '^ .' > $testroot/stdout)
1747 echo ' gitignore add' > $testroot/stdout.expected
1748 echo ' A tree1/bar' >> $testroot/stdout.expected
1749 echo ' A tree1/foo/baz' >> $testroot/stdout.expected
1750 echo ' A tree2/foo/baz' >> $testroot/stdout.expected
1752 cmp -s $testroot/stdout.expected $testroot/stdout
1753 ret=$?
1754 if [ $ret -ne 0 ]; then
1755 diff -u $testroot/stdout.expected $testroot/stdout
1756 test_done "$testroot" "$ret"
1757 return 1
1760 echo touch > $testroot/wt/tree1/bar
1761 echo touch > $testroot/wt/tree1/foo/baz
1762 echo touch > $testroot/wt/epsilon/zeta1
1764 (cd $testroot/wt && got commit -m "gitignore change" > /dev/null)
1765 (cd $testroot/wt && got log -P -l 1 | egrep '^ .' > $testroot/stdout)
1767 echo ' gitignore change' > $testroot/stdout.expected
1768 echo ' M tree1/bar' >> $testroot/stdout.expected
1769 echo ' M tree1/foo/baz' >> $testroot/stdout.expected
1771 cmp -s $testroot/stdout.expected $testroot/stdout
1772 ret=$?
1773 if [ $ret -ne 0 ]; then
1774 diff -u $testroot/stdout.expected $testroot/stdout
1775 test_done "$testroot" "$ret"
1776 return 1
1779 test_done "$testroot" "$ret"
1782 test_commit_bad_author() {
1783 local testroot=`test_init commit_bad_author`
1785 got checkout $testroot/repo $testroot/wt > /dev/null
1786 ret=$?
1787 if [ $ret -ne 0 ]; then
1788 test_done "$testroot" $ret
1789 return 1
1792 echo "modified alpha" > $testroot/wt/alpha
1794 (cd $testroot/wt && got commit \
1795 -A "${GIT_AUTHOR_NAME}<${GIT_AUTHOR_EMAIL}>" -m 'edit alpha') \
1796 > /dev/null 2> $testroot/stderr
1797 ret=$?
1798 if [ $ret -eq 0 ]; then
1799 test_done "$testroot" 1
1800 return 1
1803 echo -n "got: ${GIT_AUTHOR_NAME}<${GIT_AUTHOR_EMAIL}>: " \
1804 > $testroot/stderr.expected
1805 echo -n 'space between author name and email required: ' \
1806 >> $testroot/stderr.expected
1807 echo 'commit author formatting would make Git unhappy' \
1808 >> $testroot/stderr.expected
1809 cmp -s $testroot/stderr.expected $testroot/stderr
1810 ret=$?
1811 if [ $ret -ne 0 ]; then
1812 diff -u $testroot/stderr.expected $testroot/stderr
1813 test_done "$testroot" $ret
1814 return 1
1817 test_done "$testroot" 0
1820 test_commit_logmsg_ref() {
1821 local testroot=`test_init commit_logmsg_ref`
1823 got checkout $testroot/repo $testroot/wt > /dev/null
1824 ret=$?
1825 if [ $ret -ne 0 ]; then
1826 test_done "$testroot" "$ret"
1827 return 1
1830 git -C $testroot/repo checkout -q -b newbranch
1832 local bo_logmsg_prefix="log message of backed-out commit"
1833 local cy_logmsg_prefix="log message of cherrypicked commit"
1834 local branch_rev_logmsg="changes on newbranch to cherrypick"
1835 local branch_rev2_logmsg="modified zeta on newbranch to cherrypick"
1837 echo "modified delta on branch" > $testroot/repo/gamma/delta
1838 echo "modified alpha on branch" > $testroot/repo/alpha
1839 git -C $testroot/repo rm -q beta
1840 echo "new file on branch" > $testroot/repo/epsilon/new
1841 git -C $testroot/repo add epsilon/new
1843 git_commit $testroot/repo -m "$branch_rev_logmsg"
1844 local branch_rev=`git_show_head $testroot/repo`
1846 echo "modified zeta on branch" > $testroot/repo/epsilon/zeta
1848 git_commit $testroot/repo -m "$branch_rev2_logmsg"
1849 local branch_rev2=`git_show_head $testroot/repo`
1851 (cd $testroot/wt && got cherrypick $branch_rev > /dev/null)
1852 (cd $testroot/wt && got cherrypick $branch_rev2 > /dev/null)
1854 cat > $testroot/editor.sh <<EOF
1855 #!/bin/sh
1856 ed -s "\$1" <<-EOF
1857 ,s/# l/l/
1861 chmod +x $testroot/editor.sh
1863 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
1864 got commit > /dev/null)
1865 ret=$?
1866 if [ $ret -ne 0 ]; then
1867 echo "'got commit' failed unexpectedly" >&2
1868 test_done "$testroot" "1"
1869 return 1
1872 # check that multiple cherrypicked log messages populate the editor
1873 local first=`printf '%s\n%s' $branch_rev $branch_rev2 | sort | head -1`
1874 local second=`printf '%s\n%s' $branch_rev $branch_rev2 | sort | tail -1`
1876 if [ $branch_rev = $first ]; then
1877 local first_msg=$branch_rev_logmsg
1878 local second_msg=$branch_rev2_logmsg
1879 else
1880 local first_msg=$branch_rev2_logmsg
1881 local second_msg=$branch_rev_logmsg
1884 echo " $cy_logmsg_prefix $first:" > $testroot/stdout.expected
1885 echo " $first_msg" >> $testroot/stdout.expected
1886 echo " " >> $testroot/stdout.expected
1887 echo " $cy_logmsg_prefix $second:" >> $testroot/stdout.expected
1888 echo " $second_msg" >> $testroot/stdout.expected
1889 echo " " >> $testroot/stdout.expected
1891 (cd $testroot/wt && got log -l2 | \
1892 grep -A2 'log message' | sed '/^--/d' > $testroot/stdout)
1894 cmp -s $testroot/stdout.expected $testroot/stdout
1895 ret=$?
1896 if [ $ret -ne 0 ]; then
1897 diff -u $testroot/stdout.expected $testroot/stdout
1898 test_done "$testroot" "$ret"
1899 return 1
1902 # check that only the relevant log message populates the editor
1903 # when the changes from one of two backout commits are reverted
1904 got checkout $testroot/repo $testroot/wt2 > /dev/null
1905 ret=$?
1906 if [ $ret -ne 0 ]; then
1907 test_done "$testroot" "$ret"
1908 return 1
1911 (cd $testroot/wt2 && got backout $branch_rev > /dev/null)
1912 (cd $testroot/wt2 && got backout $branch_rev2 > /dev/null)
1913 (cd $testroot/wt2 && got revert epsilon/zeta > /dev/null)
1915 (cd $testroot/wt2 && env VISUAL="$testroot/editor.sh" \
1916 got commit > /dev/null)
1917 ret=$?
1918 if [ $ret -ne 0 ]; then
1919 echo "'got commit' failed unexpectedly" >&2
1920 test_done "$testroot" "1"
1921 return 1
1924 echo " $bo_logmsg_prefix $branch_rev:" > $testroot/stdout.expected
1925 echo " $branch_rev_logmsg" >> $testroot/stdout.expected
1926 echo " " >> $testroot/stdout.expected
1928 (cd $testroot/wt2 && got log -l1 | \
1929 grep -A2 'log message' > $testroot/stdout)
1931 cmp -s $testroot/stdout.expected $testroot/stdout
1932 ret=$?
1933 if [ $ret -ne 0 ]; then
1934 diff -u $testroot/stdout.expected $testroot/stdout
1935 test_done "$testroot" "$ret"
1936 return 1
1939 # check that a cherrypicked log message is still
1940 # used when its changes are only partially reverted
1941 branch_rev_logmsg="changes to cherrypick and partially revert"
1943 echo "newline in alpha" >> $testroot/repo/alpha
1944 echo "modified epsilon/zeta on branch" > $testroot/repo/epsilon/zeta
1946 git_commit $testroot/repo -m "$branch_rev_logmsg"
1947 branch_rev=`git_show_head $testroot/repo`
1949 (cd $testroot/wt && got cherrypick $branch_rev > /dev/null)
1950 (cd $testroot/wt && got revert alpha > /dev/null)
1952 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
1953 got commit > /dev/null)
1954 ret=$?
1955 if [ $ret -ne 0 ]; then
1956 echo "'got commit' failed unexpectedly" >&2
1957 test_done "$testroot" "1"
1958 return 1
1961 echo " $cy_logmsg_prefix $branch_rev:" > $testroot/stdout.expected
1962 echo " $branch_rev_logmsg" >> $testroot/stdout.expected
1963 echo " " >> $testroot/stdout.expected
1965 (cd $testroot/wt && got log -l1 | \
1966 grep -A2 'log message' > $testroot/stdout)
1968 cmp -s $testroot/stdout.expected $testroot/stdout
1969 ret=$?
1970 if [ $ret -ne 0 ]; then
1971 diff -u $testroot/stdout.expected $testroot/stdout
1972 test_done "$testroot" "$ret"
1973 return 1
1976 # check we don't use and consequently delete the logmsg ref of a
1977 # cherrypicked commit when omitting its changed path from the commit
1978 branch_rev_logmsg="changes to cherrypick but omit from the commit"
1980 echo "changed delta" >> $testroot/repo/gamma/delta
1982 git_commit $testroot/repo -m "$branch_rev_logmsg"
1983 local author_time=`git_show_author_time $testroot/repo`
1984 local d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
1985 branch_rev=`git_show_head $testroot/repo`
1987 (cd $testroot/wt && got update > /dev/null)
1988 ret=$?
1989 if [ $ret -ne 0 ]; then
1990 echo "got update failed unexpectedly" >&2
1991 test_done "$testroot" "$ret"
1992 return 1
1995 (cd $testroot/wt && got cherrypick $branch_rev > /dev/null)
1997 echo "changed alpha" >> $testroot/wt/alpha
1999 (cd $testroot/wt && got commit -m \
2000 "don't commit cy change to gamma/delta" alpha > /dev/null)
2001 ret=$?
2002 if [ $ret -ne 0 ]; then
2003 echo "'got commit' failed unexpectedly" >&2
2004 test_done "$testroot" "1"
2005 return 1
2008 # confirm logmsg ref was not deleted with got cherrypick -l
2009 echo "-----------------------------------------------" \
2010 > $testroot/stdout.expected
2011 echo "cherrypick $branch_rev (newbranch)" >> $testroot/stdout.expected
2012 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
2013 echo "date: $d" >> $testroot/stdout.expected
2014 echo " " >> $testroot/stdout.expected
2015 echo " $branch_rev_logmsg" >> $testroot/stdout.expected
2016 echo " " >> $testroot/stdout.expected
2017 echo " M gamma/delta" >> $testroot/stdout.expected
2018 echo >> $testroot/stdout.expected
2020 (cd $testroot/wt && got cherrypick -l > $testroot/stdout)
2022 cmp -s $testroot/stdout.expected $testroot/stdout
2023 ret=$?
2024 if [ $ret -ne 0 ]; then
2025 diff -u $testroot/stdout.expected $testroot/stdout
2026 test_done "$testroot" "$ret"
2027 return 1
2030 # confirm a previously unused logmsg ref is picked up
2031 # when an affected path is actually committed
2032 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
2033 got commit > /dev/null)
2034 ret=$?
2035 if [ $ret -ne 0 ]; then
2036 echo "'got commit' failed unexpectedly" >&2
2037 test_done "$testroot" "1"
2038 return 1
2041 echo " $cy_logmsg_prefix $branch_rev:" > $testroot/stdout.expected
2042 echo " $branch_rev_logmsg" >> $testroot/stdout.expected
2043 echo " " >> $testroot/stdout.expected
2045 (cd $testroot/wt && got log -l1 | \
2046 grep -A2 'log message' > $testroot/stdout)
2048 cmp -s $testroot/stdout.expected $testroot/stdout
2049 ret=$?
2050 if [ $ret -ne 0 ]; then
2051 diff -u $testroot/stdout.expected $testroot/stdout
2052 test_done "$testroot" "$ret"
2053 return 1
2056 # make sure we are not littering work trees
2057 # by leaving temp got-logmsg-* files behind
2058 echo -n > $testroot/stdout.expected
2059 (cd $testroot/wt && got status > $testroot/stdout)
2061 cmp -s $testroot/stdout.expected $testroot/stdout
2062 ret=$?
2063 if [ $ret -ne 0 ]; then
2064 echo "$testroot/wt is not clean"
2065 diff -u $testroot/stdout.expected $testroot/stdout
2066 test_done "$testroot" "$ret"
2067 return 1
2070 (cd $testroot/wt2 && got status > $testroot/stdout)
2072 cmp -s $testroot/stdout.expected $testroot/stdout
2073 ret=$?
2074 if [ $ret -ne 0 ]; then
2075 echo "$testroot/repo is not clean"
2076 diff -u $testroot/stdout.expected $testroot/stdout
2078 test_done "$testroot" "$ret"
2081 test_commit_from_different_worktrees() {
2082 local testroot=$(test_init commit_from_different_worktrees)
2084 got checkout $testroot/repo $testroot/wt > /dev/null
2085 ret=$?
2086 if [ $ret -ne 0 ]; then
2087 test_done "$testroot" "$ret"
2088 return 1
2091 got checkout $testroot/repo $testroot/wt2 > /dev/null
2092 ret=$?
2093 if [ $ret -ne 0 ]; then
2094 test_done "$testroot" "$ret"
2095 return 1
2098 echo "new file" > $testroot/wt2/new
2099 (cd $testroot/wt2 && got add new >/dev/null)
2100 (cd $testroot/wt2 && got commit -m 'add new file from wt2' > \
2101 $testroot/stdout)
2102 local wt2_head_id=$(git_show_head $testroot/repo)
2104 echo "modified alpha" > $testroot/wt/alpha
2105 (cd $testroot/wt && got commit -m 'mod alpha in wt' > $testroot/stdout)
2106 local wt1_parent_id=$(git_show_parent_commit $testroot/repo)
2108 if [ $wt2_head_id != $wt1_parent_id ]; then
2109 echo "commit lost from different work tree" >&2
2110 test_done "$testroot" "1"
2113 test_done "$testroot" "0"
2116 test_parseargs "$@"
2117 run_test test_commit_basic
2118 run_test test_commit_new_subdir
2119 run_test test_commit_subdir
2120 run_test test_commit_single_file
2121 run_test test_commit_out_of_date
2122 run_test test_commit_added_subdirs
2123 run_test test_commit_deleted_subdirs
2124 run_test test_commit_rejects_conflicted_file
2125 run_test test_commit_single_file_multiple
2126 run_test test_commit_added_and_modified_in_same_dir
2127 run_test test_commit_path_prefix
2128 run_test test_commit_dir_path
2129 run_test test_commit_selected_paths
2130 run_test test_commit_outside_refs_heads
2131 run_test test_commit_no_email
2132 run_test test_commit_tree_entry_sorting
2133 run_test test_commit_cmdline_author
2134 run_test test_commit_gotconfig_author
2135 run_test test_commit_gotconfig_worktree_author
2136 run_test test_commit_gitconfig_author
2137 run_test test_commit_xbit_change
2138 run_test test_commit_normalizes_filemodes
2139 run_test test_commit_with_unrelated_submodule
2140 run_test test_commit_symlink
2141 run_test test_commit_fix_bad_symlink
2142 run_test test_commit_prepared_logmsg
2143 run_test test_commit_large_file
2144 run_test test_commit_gitignore
2145 run_test test_commit_bad_author
2146 run_test test_commit_logmsg_ref
2147 run_test test_commit_from_different_worktrees