Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
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.
8 #
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" != "0" ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
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" != "0" ]; then
45 diff -u $testroot/stdout.expected $testroot/stdout
46 fi
47 test_done "$testroot" "$ret"
48 }
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" != "0" ]; then
56 test_done "$testroot" "$ret"
57 return 1
58 fi
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" != "0" ]; then
77 diff -u $testroot/stdout.expected $testroot/stdout
78 fi
79 test_done "$testroot" "$ret"
80 }
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" != "0" ]; then
88 test_done "$testroot" "$ret"
89 return 1
90 fi
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" != "0" ]; then
105 diff -u $testroot/stdout.expected $testroot/stdout
106 fi
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" != "0" ]; then
116 test_done "$testroot" "$ret"
117 return 1
118 fi
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" != "0" ]; then
133 diff -u $testroot/stdout.expected $testroot/stdout
134 fi
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" != "0" ]; then
145 test_done "$testroot" "$ret"
146 return 1
147 fi
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" != "0" ]; then
164 diff -u $testroot/stdout.expected $testroot/stdout
165 test_done "$testroot" "$ret"
166 return 1
167 fi
169 cmp -s $testroot/stderr.expected $testroot/stderr
170 ret="$?"
171 if [ "$ret" != "0" ]; then
172 diff -u $testroot/stderr.expected $testroot/stderr
173 test_done "$testroot" "$ret"
174 return 1
175 fi
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" != "0" ]; then
186 echo "commit failed unexpectedly" >&2
187 test_done "$testroot" "1"
188 return 1
189 fi
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" != "0" ]; then
197 diff -u $testroot/stdout.expected $testroot/stdout
198 fi
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" != "0" ]; then
208 test_done "$testroot" "$ret"
209 return 1
210 fi
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" != "0" ]; then
236 diff -u $testroot/stdout.expected $testroot/stdout
237 fi
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" != "0" ]; then
247 test_done "$testroot" "$ret"
248 return 1
249 fi
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" != "0" ]; then
265 diff -u $testroot/stdout.expected $testroot/stdout
266 test_done "$testroot" "$ret"
267 return 1
268 fi
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" != "0" ]; then
278 diff -u $testroot/stdout.expected $testroot/stdout
279 fi
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" != "0" ]; then
291 test_done "$testroot" "$ret"
292 return 1
293 fi
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
311 ret="$?"
312 if [ "$ret" != "0" ]; then
313 diff -u $testroot/stdout.expected $testroot/stdout
314 test_done "$testroot" "$ret"
315 return 1
316 fi
318 (cd $testroot/wt && got commit -m 'commit it' > $testroot/stdout \
319 2> $testroot/stderr)
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
326 ret="$?"
327 if [ "$ret" != "0" ]; then
328 diff -u $testroot/stdout.expected $testroot/stdout
329 test_done "$testroot" "$ret"
330 return 1
331 fi
332 cmp -s $testroot/stderr.expected $testroot/stderr
333 ret="$?"
334 if [ "$ret" != "0" ]; then
335 diff -u $testroot/stderr.expected $testroot/stderr
336 fi
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
344 ret="$?"
345 if [ "$ret" != "0" ]; then
346 test_done "$testroot" "$ret"
347 return 1
348 fi
350 for i in 1 2 3 4; do
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
361 ret="$?"
362 if [ "$ret" != "0" ]; then
363 diff -u $testroot/stdout.expected $testroot/stdout
364 test_done "$testroot" "$ret"
365 return 1
366 fi
367 done
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
376 ret="$?"
377 if [ "$ret" != "0" ]; then
378 test_done "$testroot" "$ret"
379 return 1
380 fi
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 \
388 2> $testroot/stderr)
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
396 ret="$?"
397 if [ "$ret" != "0" ]; then
398 diff -u $testroot/stdout.expected $testroot/stdout
399 fi
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
408 ret="$?"
409 if [ "$ret" != "0" ]; then
410 test_done "$testroot" "$ret"
411 return 1
412 fi
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
423 ret="$?"
424 if [ "$ret" != "0" ]; then
425 diff -u $testroot/stdout.expected $testroot/stdout
426 test_done "$testroot" "$ret"
427 return 1
428 fi
430 echo "diff $commit1 $commit2" > $testroot/stdout.expected
431 echo -n 'blob - ' >> $testroot/stdout.expected
432 got tree -r $testroot/repo -c $commit1 -i gamma | grep 'delta$' \
433 | cut -d' ' -f 1 >> $testroot/stdout.expected
434 echo -n 'blob + ' >> $testroot/stdout.expected
435 got tree -r $testroot/repo -c $commit2 -i gamma | grep 'delta$' | \
436 cut -d' ' -f 1 >> $testroot/stdout.expected
437 echo '--- gamma/delta' >> $testroot/stdout.expected
438 echo '+++ gamma/delta' >> $testroot/stdout.expected
439 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
440 echo '-delta' >> $testroot/stdout.expected
441 echo '+modified delta' >> $testroot/stdout.expected
443 got diff -r $testroot/repo $commit1 $commit2 > $testroot/stdout
444 cmp -s $testroot/stdout.expected $testroot/stdout
445 ret="$?"
446 if [ "$ret" != "0" ]; then
447 diff -u $testroot/stdout.expected $testroot/stdout
448 test_done "$testroot" "$ret"
449 return 1
450 fi
452 (cd $testroot/wt && got rm delta > /dev/null)
453 echo new > $testroot/wt/new
454 (cd $testroot/wt && got add new > /dev/null)
456 (cd $testroot/wt && got commit -m 'remove gamma/delta; add gamma/new' \
457 > $testroot/stdout)
459 local commit3=`git_show_head $testroot/repo`
460 echo "A new" > $testroot/stdout.expected
461 echo "D delta" >> $testroot/stdout.expected
462 echo "Created commit $commit3" >> $testroot/stdout.expected
464 cmp -s $testroot/stdout.expected $testroot/stdout
465 ret="$?"
466 if [ "$ret" != "0" ]; then
467 diff -u $testroot/stdout.expected $testroot/stdout
468 test_done "$testroot" "$ret"
469 return 1
470 fi
472 echo "diff $commit2 $commit3" > $testroot/stdout.expected
473 echo -n 'blob - ' >> $testroot/stdout.expected
474 got tree -r $testroot/repo -c $commit2 -i gamma | grep 'delta$' \
475 | cut -d' ' -f 1 | sed -e 's/$/ (mode 644)/' \
476 >> $testroot/stdout.expected
477 echo 'blob + /dev/null' >> $testroot/stdout.expected
478 echo '--- gamma/delta' >> $testroot/stdout.expected
479 echo '+++ /dev/null' >> $testroot/stdout.expected
480 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
481 echo '-modified delta' >> $testroot/stdout.expected
482 echo 'blob - /dev/null' >> $testroot/stdout.expected
483 echo -n 'blob + ' >> $testroot/stdout.expected
484 got tree -r $testroot/repo -c $commit3 -i gamma | grep 'new$' | \
485 cut -d' ' -f 1 | sed -e 's/$/ (mode 644)/' \
486 >> $testroot/stdout.expected
487 echo '--- /dev/null' >> $testroot/stdout.expected
488 echo '+++ gamma/new' >> $testroot/stdout.expected
489 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
490 echo '+new' >> $testroot/stdout.expected
492 got diff -r $testroot/repo $commit2 $commit3 > $testroot/stdout
493 cmp -s $testroot/stdout.expected $testroot/stdout
494 ret="$?"
495 if [ "$ret" != "0" ]; then
496 diff -u $testroot/stdout.expected $testroot/stdout
497 fi
498 test_done "$testroot" "$ret"
499 return "$ret"
502 test_commit_dir_path() {
503 local testroot=`test_init commit_dir_path`
505 got checkout $testroot/repo $testroot/wt > /dev/null
506 ret="$?"
507 if [ "$ret" != "0" ]; then
508 test_done "$testroot" "$ret"
509 return 1
510 fi
512 echo "modified alpha" > $testroot/wt/alpha
513 echo "modified zeta" > $testroot/wt/epsilon/zeta
515 (cd $testroot/wt && got commit -m 'changed zeta' epsilon \
516 > $testroot/stdout)
518 local head_rev=`git_show_head $testroot/repo`
519 echo "M epsilon/zeta" >> $testroot/stdout.expected
520 echo "Created commit $head_rev" >> $testroot/stdout.expected
522 cmp -s $testroot/stdout.expected $testroot/stdout
523 ret="$?"
524 if [ "$ret" != "0" ]; then
525 diff -u $testroot/stdout.expected $testroot/stdout
526 test_done "$testroot" "$ret"
527 return 1
528 fi
530 echo "M alpha" > $testroot/stdout.expected
531 (cd $testroot/wt && got status > $testroot/stdout)
532 cmp -s $testroot/stdout.expected $testroot/stdout
533 ret="$?"
534 if [ "$ret" != "0" ]; then
535 diff -u $testroot/stdout.expected $testroot/stdout
536 fi
537 test_done "$testroot" "$ret"
540 test_commit_selected_paths() {
541 local testroot=`test_init commit_selected_paths`
543 got checkout $testroot/repo $testroot/wt > /dev/null
544 ret="$?"
545 if [ "$ret" != "0" ]; then
546 test_done "$testroot" "$ret"
547 return 1
548 fi
550 echo "modified alpha" > $testroot/wt/alpha
551 echo "modified delta" > $testroot/wt/gamma/delta
552 echo "modified zeta" > $testroot/wt/epsilon/zeta
553 (cd $testroot/wt && got rm beta >/dev/null)
554 echo "new file" > $testroot/wt/new
555 (cd $testroot/wt && got add new >/dev/null)
557 (cd $testroot/wt && got commit -m 'many paths' nonexistent alpha \
558 > $testroot/stdout 2> $testroot/stderr)
559 ret="$?"
560 if [ "$ret" = "0" ]; then
561 echo "commit succeeded unexpectedly" >&2
562 test_done "$testroot" "1"
563 return 1
564 fi
565 echo "got: nonexistent: bad path" > $testroot/stderr.expected
567 cmp -s $testroot/stderr.expected $testroot/stderr
568 ret="$?"
569 if [ "$ret" != "0" ]; then
570 diff -u $testroot/stderr.expected $testroot/stderr
571 test_done "$testroot" "$ret"
572 return 1
573 fi
575 (cd $testroot/wt && got commit -m 'many paths' \
576 beta new gamma > $testroot/stdout)
578 local head_rev=`git_show_head $testroot/repo`
579 echo "A new" > $testroot/stdout.expected
580 echo "D beta" >> $testroot/stdout.expected
581 echo "M gamma/delta" >> $testroot/stdout.expected
582 echo "Created commit $head_rev" >> $testroot/stdout.expected
584 cmp -s $testroot/stdout.expected $testroot/stdout
585 ret="$?"
586 if [ "$ret" != "0" ]; then
587 diff -u $testroot/stdout.expected $testroot/stdout
588 fi
589 test_done "$testroot" "$ret"
592 test_commit_outside_refs_heads() {
593 local testroot=`test_init commit_outside_refs_heads`
595 got ref -r $testroot/repo -c master refs/remotes/origin/master
597 got checkout -b refs/remotes/origin/master \
598 $testroot/repo $testroot/wt > /dev/null
599 ret="$?"
600 if [ "$ret" != "0" ]; then
601 test_done "$testroot" "$ret"
602 return 1
603 fi
605 echo "modified alpha" > $testroot/wt/alpha
607 (cd $testroot/wt && got commit -m 'change alpha' \
608 > $testroot/stdout 2> $testroot/stderr)
609 ret="$?"
610 if [ "$ret" = "0" ]; then
611 echo "commit succeeded unexpectedly" >&2
612 test_done "$testroot" "1"
613 return 1
614 fi
616 echo -n > $testroot/stdout.expected
617 cmp -s $testroot/stdout.expected $testroot/stdout
618 ret="$?"
619 if [ "$ret" != "0" ]; then
620 diff -u $testroot/stdout.expected $testroot/stdout
621 test_done "$testroot" "$ret"
622 return 1
623 fi
625 echo -n "got: will not commit to a branch outside the " \
626 > $testroot/stderr.expected
627 echo '"refs/heads/" reference namespace' \
628 >> $testroot/stderr.expected
629 cmp -s $testroot/stderr.expected $testroot/stderr
630 ret="$?"
631 if [ "$ret" != "0" ]; then
632 diff -u $testroot/stderr.expected $testroot/stderr
633 fi
634 test_done "$testroot" "$ret"
637 test_commit_no_email() {
638 local testroot=`test_init commit_no_email`
640 got checkout $testroot/repo $testroot/wt > /dev/null
641 ret="$?"
642 if [ "$ret" != "0" ]; then
643 test_done "$testroot" "$ret"
644 return 1
645 fi
647 echo "modified alpha" > $testroot/wt/alpha
648 (cd $testroot/wt && env GOT_AUTHOR=":flan_hacker:" \
649 got commit -m 'test no email' > $testroot/stdout \
650 2> $testroot/stderr)
652 echo -n "got: GOT_AUTHOR environment variable contains no email " \
653 > $testroot/stderr.expected
654 echo -n "address; an email address is required for compatibility "\
655 >> $testroot/stderr.expected
656 echo "with Git" >> $testroot/stderr.expected
657 cmp -s $testroot/stderr.expected $testroot/stderr
658 ret="$?"
659 if [ "$ret" != "0" ]; then
660 diff -u $testroot/stderr.expected $testroot/stderr
661 test_done "$testroot" "$ret"
662 return 1
663 fi
665 echo -n > $testroot/stdout.expected
666 cmp -s $testroot/stdout.expected $testroot/stdout
667 ret="$?"
668 if [ "$ret" != "0" ]; then
669 diff -u $testroot/stdout.expected $testroot/stdout
670 fi
671 test_done "$testroot" "$ret"
674 test_commit_tree_entry_sorting() {
675 local testroot=`test_init commit_tree_entry_sorting`
677 got checkout $testroot/repo $testroot/wt > /dev/null
678 ret="$?"
679 if [ "$ret" != "0" ]; then
680 test_done "$testroot" "$ret"
681 return 1
682 fi
684 # Git's index gets corrupted when tree entries are written in the
685 # order defined by got_path_cmp() rather than Git's own ordering.
686 # Create a new tree where a directory "got" and a file "got-version"
687 # would sort in the wrong order according to Git's opinion.
688 mkdir $testroot/wt/got
689 touch $testroot/wt/got/foo
690 echo foo > $testroot/wt/got-version
691 echo zzz > $testroot/wt/zzz
692 (cd $testroot/wt && got add got-version got/foo zzz > /dev/null)
694 (cd $testroot/wt && got commit -m 'test' > /dev/null)
696 # Let git-fsck verify the newly written tree to make sure Git is happy
697 (cd $testroot/repo && git fsck --strict \
698 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
699 ret="$?"
700 test_done "$testroot" "$ret"
703 test_commit_gotconfig_author() {
704 local testroot=`test_init commit_gotconfig_author`
706 got checkout $testroot/repo $testroot/wt > /dev/null
707 ret="$?"
708 if [ "$ret" != "0" ]; then
709 test_done "$testroot" "$ret"
710 return 1
711 fi
712 echo 'author "Flan Luck <flan_luck@openbsd.org>"' \
713 > $testroot/repo/.git/got.conf
715 echo "modified alpha" > $testroot/wt/alpha
716 (cd $testroot/wt && got commit -m 'test gotconfig author' > /dev/null)
717 ret="$?"
718 if [ "$ret" != "0" ]; then
719 test_done "$testroot" "$ret"
720 return 1
721 fi
723 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
724 ret="$?"
725 if [ "$ret" != "0" ]; then
726 test_done "$testroot" "$ret"
727 return 1
728 fi
730 echo "from: Flan Luck <flan_luck@openbsd.org>" \
731 > $testroot/stdout.expected
732 cmp -s $testroot/stdout.expected $testroot/stdout
733 ret="$?"
734 if [ "$ret" != "0" ]; then
735 diff -u $testroot/stdout.expected $testroot/stdout
736 fi
737 test_done "$testroot" "$ret"
740 test_commit_gotconfig_worktree_author() {
741 local testroot=`test_init commit_gotconfig_worktree_author`
743 got checkout $testroot/repo $testroot/wt > /dev/null
744 ret="$?"
745 if [ "$ret" != "0" ]; then
746 test_done "$testroot" "$ret"
747 return 1
748 fi
749 echo 'author "Flan Luck <flan_luck@openbsd.org>"' \
750 > $testroot/repo/.git/got.conf
751 echo 'author "Flan Squee <flan_squee@openbsd.org>"' \
752 > $testroot/wt/.got/got.conf
754 echo "modified alpha" > $testroot/wt/alpha
755 (cd $testroot/wt && got commit -m 'test gotconfig author' > /dev/null)
756 ret="$?"
757 if [ "$ret" != "0" ]; then
758 test_done "$testroot" "$ret"
759 return 1
760 fi
762 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
763 ret="$?"
764 if [ "$ret" != "0" ]; then
765 test_done "$testroot" "$ret"
766 return 1
767 fi
769 echo "from: Flan Squee <flan_squee@openbsd.org>" \
770 > $testroot/stdout.expected
771 cmp -s $testroot/stdout.expected $testroot/stdout
772 ret="$?"
773 if [ "$ret" != "0" ]; then
774 diff -u $testroot/stdout.expected $testroot/stdout
775 fi
776 test_done "$testroot" "$ret"
779 test_commit_gitconfig_author() {
780 local testroot=`test_init commit_gitconfig_author`
782 got checkout $testroot/repo $testroot/wt > /dev/null
783 ret="$?"
784 if [ "$ret" != "0" ]; then
785 test_done "$testroot" "$ret"
786 return 1
787 fi
789 (cd $testroot/repo && git config user.name 'Flan Luck')
790 (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
792 echo "modified alpha" > $testroot/wt/alpha
793 (cd $testroot/wt && got commit -m 'test gitconfig author' > /dev/null)
794 ret="$?"
795 if [ "$ret" != "0" ]; then
796 test_done "$testroot" "$ret"
797 return 1
798 fi
800 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
801 ret="$?"
802 if [ "$ret" != "0" ]; then
803 test_done "$testroot" "$ret"
804 return 1
805 fi
807 echo "from: Flan Luck <flan_luck@openbsd.org>" \
808 > $testroot/stdout.expected
809 cmp -s $testroot/stdout.expected $testroot/stdout
810 ret="$?"
811 if [ "$ret" != "0" ]; then
812 diff -u $testroot/stdout.expected $testroot/stdout
813 fi
814 test_done "$testroot" "$ret"
817 test_commit_xbit_change() {
818 local testroot=`test_init commit_xbit_change`
820 got checkout $testroot/repo $testroot/wt > /dev/null
821 ret="$?"
822 if [ "$ret" != "0" ]; then
823 test_done "$testroot" "$ret"
824 return 1
825 fi
827 chmod +x $testroot/wt/alpha
829 echo 'm alpha' > $testroot/stdout.expected
830 (cd $testroot/wt && got status > $testroot/stdout)
832 cmp -s $testroot/stdout.expected $testroot/stdout
833 ret="$?"
834 if [ "$ret" != "0" ]; then
835 diff -u $testroot/stdout.expected $testroot/stdout
836 test_done "$testroot" "$ret"
837 return 1
838 fi
840 (cd $testroot/wt && got commit -mx > $testroot/stdout)
841 ret="$?"
842 if [ "$ret" != "0" ]; then
843 echo "got commit failed unexpectedly"
844 test_done "$testroot" "$ret"
845 return 1
846 fi
848 local commit_id=`git_show_head $testroot/repo`
849 echo 'm alpha' > $testroot/stdout.expected
850 echo "Created commit $commit_id" >> $testroot/stdout.expected
851 cmp -s $testroot/stdout.expected $testroot/stdout
852 ret="$?"
853 if [ "$ret" != "0" ]; then
854 diff -u $testroot/stdout.expected $testroot/stdout
855 test_done "$testroot" "$ret"
856 return 1
857 fi
859 (cd $testroot/wt && got status > $testroot/stdout)
861 echo -n > $testroot/stdout.expected
862 cmp -s $testroot/stdout.expected $testroot/stdout
863 ret="$?"
864 if [ "$ret" != "0" ]; then
865 diff -u $testroot/stdout.expected $testroot/stdout
866 test_done "$testroot" "$ret"
867 return 1
868 fi
870 chmod -x $testroot/wt/alpha
872 echo 'm alpha' > $testroot/stdout.expected
873 (cd $testroot/wt && got status > $testroot/stdout)
875 cmp -s $testroot/stdout.expected $testroot/stdout
876 ret="$?"
877 if [ "$ret" != "0" ]; then
878 diff -u $testroot/stdout.expected $testroot/stdout
879 test_done "$testroot" "$ret"
880 return 1
881 fi
883 (cd $testroot/wt && got commit -mx > $testroot/stdout)
884 ret="$?"
885 if [ "$ret" != "0" ]; then
886 echo "got commit failed unexpectedly"
887 test_done "$testroot" "$ret"
888 return 1
889 fi
891 local commit_id=`git_show_head $testroot/repo`
892 echo 'm alpha' > $testroot/stdout.expected
893 echo "Created commit $commit_id" >> $testroot/stdout.expected
894 cmp -s $testroot/stdout.expected $testroot/stdout
895 ret="$?"
896 if [ "$ret" != "0" ]; then
897 diff -u $testroot/stdout.expected $testroot/stdout
898 test_done "$testroot" "$ret"
899 return 1
900 fi
902 chmod +x $testroot/wt/alpha
904 echo 'm alpha' > $testroot/stdout.expected
905 (cd $testroot/wt && got status > $testroot/stdout)
907 cmp -s $testroot/stdout.expected $testroot/stdout
908 ret="$?"
909 if [ "$ret" != "0" ]; then
910 diff -u $testroot/stdout.expected $testroot/stdout
911 fi
912 test_done "$testroot" "$ret"
915 commit_check_mode() {
916 local mode="$1"
917 local expected_mode="$2"
919 chmod 644 $testroot/wt/alpha
920 echo a >> $testroot/wt/alpha
921 chmod $mode $testroot/wt/alpha
923 (cd $testroot/wt && got commit -mm > $testroot/stdout)
924 ret="$?"
925 if [ "$ret" != "0" ]; then
926 echo "got commit failed unexpectedly"
927 test_done "$testroot" "$ret"
928 return 1
929 fi
931 local commit_id=`git_show_head $testroot/repo`
932 echo 'M alpha' > $testroot/stdout.expected
933 echo "Created commit $commit_id" >> $testroot/stdout.expected
934 cmp -s $testroot/stdout.expected $testroot/stdout
935 ret="$?"
936 if [ "$ret" != "0" ]; then
937 diff -u $testroot/stdout.expected $testroot/stdout
938 test_done "$testroot" "$ret"
939 return 1
940 fi
942 local tree_id=$(got cat -r $testroot/repo $commit_id | \
943 grep ^tree | cut -d' ' -f2)
944 local alpha_id=$(got cat -r $testroot/repo $tree_id | \
945 grep 'alpha$' | cut -d' ' -f1)
946 echo "$alpha_id $expected_mode alpha" > $testroot/stdout.expected
947 got cat -r $testroot/repo $tree_id | grep 'alpha$' > $testroot/stdout
948 cmp -s $testroot/stdout.expected $testroot/stdout
949 ret="$?"
950 if [ "$ret" != "0" ]; then
951 diff -u $testroot/stdout.expected $testroot/stdout
952 fi
953 return $ret
956 test_commit_normalizes_filemodes() {
957 local testroot=`test_init commit_normalizes_filemodes`
959 got checkout $testroot/repo $testroot/wt > /dev/null
960 ret="$?"
961 if [ "$ret" != "0" ]; then
962 test_done "$testroot" "$ret"
963 return 1
964 fi
966 modes="600 400 460 640 440 660 444 666"
967 for m in $modes; do
968 commit_check_mode "$m" "0100644"
969 ret="$?"
970 if [ "$ret" != "0" ]; then
971 break
972 fi
973 done
974 if [ "$ret" != "0" ]; then
975 test_done "$testroot" "$ret"
976 return 1
977 fi
978 modes="700 500 570 750 550 770 555 777"
979 for m in $modes; do
980 commit_check_mode "$m" "0100755"
981 ret="$?"
982 if [ "$ret" != "0" ]; then
983 break
984 fi
985 done
986 if [ "$ret" != "0" ]; then
987 test_done "$testroot" "$ret"
988 return 1
989 fi
990 test_done "$testroot" "$ret"
993 test_commit_with_unrelated_submodule() {
994 local testroot=`test_init commit_with_unrelated_submodule`
996 make_single_file_repo $testroot/repo2 foo
998 (cd $testroot/repo && git submodule -q add ../repo2)
999 (cd $testroot/repo && git commit -q -m 'adding submodule')
1001 got checkout $testroot/repo $testroot/wt > /dev/null
1002 ret="$?"
1003 if [ "$ret" != "0" ]; then
1004 echo "checkout failed unexpectedly" >&2
1005 test_done "$testroot" "$ret"
1006 return 1
1009 echo "modified alpha" > $testroot/wt/alpha
1011 echo "" > $testroot/stdout.expected
1013 (cd $testroot/wt && got commit -m 'modify alpha' > $testroot/stdout)
1014 ret="$?"
1015 if [ "$ret" != "0" ]; then
1016 echo "commit failed unexpectedly" >&2
1017 test_done "$testroot" "$ret"
1018 return 1
1021 local head_rev=`git_show_head $testroot/repo`
1022 echo "M alpha" > $testroot/stdout.expected
1023 echo "Created commit $head_rev" >> $testroot/stdout.expected
1025 cmp -s $testroot/stdout.expected $testroot/stdout
1026 ret="$?"
1027 if [ "$ret" != "0" ]; then
1028 diff -u $testroot/stdout.expected $testroot/stdout
1030 test_done "$testroot" "$ret"
1033 check_symlinks() {
1034 local wtpath="$1"
1035 if ! [ -h $wtpath/alpha.link ]; then
1036 echo "alpha.link is not a symlink"
1037 return 1
1040 readlink $wtpath/alpha.link > $testroot/stdout
1041 echo "alpha" > $testroot/stdout.expected
1042 cmp -s $testroot/stdout.expected $testroot/stdout
1043 ret="$?"
1044 if [ "$ret" != "0" ]; then
1045 diff -u $testroot/stdout.expected $testroot/stdout
1046 return 1
1049 if ! [ -h $wtpath/epsilon.link ]; then
1050 echo "epsilon.link is not a symlink"
1051 return 1
1054 readlink $wtpath/epsilon.link > $testroot/stdout
1055 echo "epsilon" > $testroot/stdout.expected
1056 cmp -s $testroot/stdout.expected $testroot/stdout
1057 ret="$?"
1058 if [ "$ret" != "0" ]; then
1059 diff -u $testroot/stdout.expected $testroot/stdout
1060 return 1
1063 if [ -h $wtpath/passwd.link ]; then
1064 echo -n "passwd.link is a symlink and points outside of work tree: " >&2
1065 readlink $wtpath/passwd.link >&2
1066 return 1
1069 echo -n "/etc/passwd" > $testroot/content.expected
1070 cp $wtpath/passwd.link $testroot/content
1071 ret="$?"
1072 if [ "$ret" != "0" ]; then
1073 echo "cp command failed unexpectedly" >&2
1074 return 1
1077 cmp -s $testroot/content.expected $testroot/content
1078 ret="$?"
1079 if [ "$ret" != "0" ]; then
1080 diff -u $testroot/content.expected $testroot/content
1081 return 1
1084 readlink $wtpath/epsilon/beta.link > $testroot/stdout
1085 echo "../beta" > $testroot/stdout.expected
1086 cmp -s $testroot/stdout.expected $testroot/stdout
1087 ret="$?"
1088 if [ "$ret" != "0" ]; then
1089 diff -u $testroot/stdout.expected $testroot/stdout
1090 return 1
1093 readlink $wtpath/nonexistent.link > $testroot/stdout
1094 echo "nonexistent" > $testroot/stdout.expected
1095 cmp -s $testroot/stdout.expected $testroot/stdout
1096 ret="$?"
1097 if [ "$ret" != "0" ]; then
1098 diff -u $testroot/stdout.expected $testroot/stdout
1099 return 1
1102 return 0
1105 test_commit_symlink() {
1106 local testroot=`test_init commit_symlink`
1108 got checkout $testroot/repo $testroot/wt > /dev/null
1109 ret="$?"
1110 if [ "$ret" != "0" ]; then
1111 test_done "$testroot" "$ret"
1112 return 1
1115 (cd $testroot/wt && ln -s alpha alpha.link)
1116 (cd $testroot/wt && ln -s epsilon epsilon.link)
1117 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1118 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
1119 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
1120 (cd $testroot/wt && got add alpha.link epsilon.link passwd.link \
1121 epsilon/beta.link nonexistent.link > /dev/null)
1123 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1124 > $testroot/stdout 2> $testroot/stderr)
1125 ret="$?"
1126 if [ "$ret" = "0" ]; then
1127 echo "got commit succeeded unexpectedly" >&2
1128 test_done "$testroot" "$ret"
1129 return 1
1131 echo -n "got: $testroot/wt/passwd.link: " > $testroot/stderr.expected
1132 echo "symbolic link points outside of paths under version control" \
1133 >> $testroot/stderr.expected
1134 cmp -s $testroot/stderr.expected $testroot/stderr
1135 ret="$?"
1136 if [ "$ret" != "0" ]; then
1137 diff -u $testroot/stderr.expected $testroot/stderr
1138 test_done "$testroot" "$ret"
1139 return 1
1142 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1143 > $testroot/stdout)
1145 local head_rev=`git_show_head $testroot/repo`
1146 echo "A alpha.link" > $testroot/stdout.expected
1147 echo "A epsilon.link" >> $testroot/stdout.expected
1148 echo "A nonexistent.link" >> $testroot/stdout.expected
1149 echo "A passwd.link" >> $testroot/stdout.expected
1150 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1151 echo "Created commit $head_rev" >> $testroot/stdout.expected
1153 cmp -s $testroot/stdout.expected $testroot/stdout
1154 ret="$?"
1155 if [ "$ret" != "0" ]; then
1156 diff -u $testroot/stdout.expected $testroot/stdout
1157 test_done "$testroot" "$ret"
1158 return 1
1161 # verify created in-repository tree
1162 got checkout $testroot/repo $testroot/wt2 > /dev/null
1163 ret="$?"
1164 if [ "$ret" != "0" ]; then
1165 test_done "$testroot" "$ret"
1166 return 1
1168 check_symlinks $testroot/wt2
1169 ret="$?"
1170 if [ "$ret" != "0" ]; then
1171 test_done "$testroot" "$ret"
1172 return 1
1175 if ! [ -h $testroot/wt/passwd.link ]; then
1176 echo 'passwd.link is not a symlink' >&2
1177 test_done "$testroot" 1
1178 return 1
1181 # 'got update' should reinstall passwd.link as a regular file
1182 (cd $testroot/wt && got update > /dev/null)
1183 check_symlinks $testroot/wt
1184 ret="$?"
1185 if [ "$ret" != "0" ]; then
1186 test_done "$testroot" "$ret"
1187 return 1
1190 (cd $testroot/wt && ln -sf beta alpha.link)
1191 (cd $testroot/wt && ln -sfT gamma epsilon.link)
1192 rm $testroot/wt/epsilon/beta.link
1193 echo "this is a regular file" > $testroot/wt/epsilon/beta.link
1194 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
1195 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
1196 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
1197 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
1198 (cd $testroot/wt && ln -sf alpha new.link)
1199 (cd $testroot/wt && got add new.link > /dev/null)
1201 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1202 > $testroot/stdout 2> $testroot/stderr)
1203 ret="$?"
1204 if [ "$ret" = "0" ]; then
1205 echo "got commit succeeded unexpectedly" >&2
1206 test_done "$testroot" "$ret"
1207 return 1
1209 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
1210 echo "symbolic link points outside of paths under version control" \
1211 >> $testroot/stderr.expected
1212 cmp -s $testroot/stderr.expected $testroot/stderr
1213 ret="$?"
1214 if [ "$ret" != "0" ]; then
1215 diff -u $testroot/stderr.expected $testroot/stderr
1216 test_done "$testroot" "$ret"
1217 return 1
1220 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1221 > $testroot/stdout)
1223 local head_rev=`git_show_head $testroot/repo`
1224 echo "A dotgotbar.link" > $testroot/stdout.expected
1225 echo "A new.link" >> $testroot/stdout.expected
1226 echo "M alpha.link" >> $testroot/stdout.expected
1227 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1228 echo "M epsilon.link" >> $testroot/stdout.expected
1229 echo "D nonexistent.link" >> $testroot/stdout.expected
1230 echo "Created commit $head_rev" >> $testroot/stdout.expected
1232 cmp -s $testroot/stdout.expected $testroot/stdout
1233 ret="$?"
1234 if [ "$ret" != "0" ]; then
1235 diff -u $testroot/stdout.expected $testroot/stdout
1236 test_done "$testroot" "$ret"
1237 return 1
1240 got tree -r $testroot/repo -c $head_rev -R > $testroot/stdout
1241 cat > $testroot/stdout.expected <<EOF
1242 alpha
1243 alpha.link@ -> beta
1244 beta
1245 dotgotbar.link@ -> .got/bar
1246 epsilon/
1247 epsilon/beta.link
1248 epsilon/zeta
1249 epsilon.link@ -> gamma
1250 gamma/
1251 gamma/delta
1252 new.link@ -> alpha
1253 passwd.link@ -> /etc/passwd
1254 EOF
1255 cmp -s $testroot/stdout.expected $testroot/stdout
1256 ret="$?"
1257 if [ "$ret" != "0" ]; then
1258 diff -u $testroot/stdout.expected $testroot/stdout
1260 test_done "$testroot" "$ret"
1263 test_commit_fix_bad_symlink() {
1264 local testroot=`test_init commit_fix_bad_symlink`
1266 got checkout $testroot/repo $testroot/wt > /dev/null
1267 ret="$?"
1268 if [ "$ret" != "0" ]; then
1269 echo "got checkout failed unexpectedly" >&2
1270 test_done "$testroot" "$ret"
1271 return 1
1274 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1275 (cd $testroot/wt && got add passwd.link > /dev/null)
1277 (cd $testroot/wt && got commit -S -m 'commit bad symlink' \
1278 > $testroot/stdout)
1280 if ! [ -h $testroot/wt/passwd.link ]; then
1281 echo 'passwd.link is not a symlink' >&2
1282 test_done "$testroot" 1
1283 return 1
1285 (cd $testroot/wt && got update >/dev/null)
1286 if [ -h $testroot/wt/passwd.link ]; then
1287 echo "passwd.link is a symlink but should be a regular file" >&2
1288 test_done "$testroot" "1"
1289 return 1
1292 # create another work tree which will contain the "bad" symlink
1293 got checkout $testroot/repo $testroot/wt2 > /dev/null
1294 ret="$?"
1295 if [ "$ret" != "0" ]; then
1296 echo "got checkout failed unexpectedly" >&2
1297 test_done "$testroot" "$ret"
1298 return 1
1301 # change "bad" symlink back into a "good" symlink
1302 (cd $testroot/wt && ln -sfT alpha passwd.link)
1304 (cd $testroot/wt && got commit -m 'fix bad symlink' \
1305 > $testroot/stdout)
1307 local head_rev=`git_show_head $testroot/repo`
1308 echo "M passwd.link" > $testroot/stdout.expected
1309 echo "Created commit $head_rev" >> $testroot/stdout.expected
1311 cmp -s $testroot/stdout.expected $testroot/stdout
1312 ret="$?"
1313 if [ "$ret" != "0" ]; then
1314 diff -u $testroot/stdout.expected $testroot/stdout
1315 test_done "$testroot" "$ret"
1316 return 1
1319 if ! [ -h $testroot/wt/passwd.link ]; then
1320 echo 'passwd.link is not a symlink' >&2
1321 test_done "$testroot" 1
1322 return 1
1325 readlink $testroot/wt/passwd.link > $testroot/stdout
1326 echo "alpha" > $testroot/stdout.expected
1327 cmp -s $testroot/stdout.expected $testroot/stdout
1328 ret="$?"
1329 if [ "$ret" != "0" ]; then
1330 diff -u $testroot/stdout.expected $testroot/stdout
1331 return 1
1334 # Update the other work tree; the bad symlink should be fixed
1335 (cd $testroot/wt2 && got update > /dev/null)
1336 ret="$?"
1337 if [ "$ret" != "0" ]; then
1338 echo "got checkout failed unexpectedly" >&2
1339 test_done "$testroot" "$ret"
1340 return 1
1343 if ! [ -h $testroot/wt2/passwd.link ]; then
1344 echo 'passwd.link is not a symlink' >&2
1345 test_done "$testroot" 1
1346 return 1
1349 readlink $testroot/wt2/passwd.link > $testroot/stdout
1350 echo "alpha" > $testroot/stdout.expected
1351 cmp -s $testroot/stdout.expected $testroot/stdout
1352 ret="$?"
1353 if [ "$ret" != "0" ]; then
1354 diff -u $testroot/stdout.expected $testroot/stdout
1355 return 1
1358 test_done "$testroot" "0"
1361 test_commit_prepared_logmsg() {
1362 local testroot=`test_init commit_prepared_logmsg`
1364 got checkout $testroot/repo $testroot/wt > /dev/null
1365 ret="$?"
1366 if [ "$ret" != "0" ]; then
1367 test_done "$testroot" "$ret"
1368 return 1
1371 echo "modified alpha" > $testroot/wt/alpha
1372 (cd $testroot/wt && got rm beta >/dev/null)
1373 echo "new file" > $testroot/wt/new
1374 (cd $testroot/wt && got add new >/dev/null)
1376 echo 'test commit_prepared_logmsg' > $testroot/logmsg
1378 cat > $testroot/editor.sh <<EOF
1379 #!/bin/sh
1380 sed -i 's/foo/bar/' "\$1"
1381 EOF
1382 chmod +x $testroot/editor.sh
1384 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
1385 got commit -F "$testroot/logmsg" > $testroot/stdout)
1387 local head_rev=`git_show_head $testroot/repo`
1388 echo "A new" > $testroot/stdout.expected
1389 echo "M alpha" >> $testroot/stdout.expected
1390 echo "D beta" >> $testroot/stdout.expected
1391 echo "Created commit $head_rev" >> $testroot/stdout.expected
1393 cmp -s $testroot/stdout.expected $testroot/stdout
1394 ret="$?"
1395 if [ "$ret" != "0" ]; then
1396 diff -u $testroot/stdout.expected $testroot/stdout
1397 test_done "$testroot" "$ret"
1398 return 1
1401 local author_time=`git_show_author_time $testroot/repo`
1402 d=`env LC_TIME=C date -u -d "@$author_time" +"%a %b %e %X %Y UTC"`
1403 echo "-----------------------------------------------" > $testroot/stdout.expected
1404 echo "commit $head_rev (master)" >> $testroot/stdout.expected
1405 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
1406 echo "date: $d" >> $testroot/stdout.expected
1407 echo " " >> $testroot/stdout.expected
1408 echo " test commit_prepared_logmsg" >> $testroot/stdout.expected
1409 echo " " >> $testroot/stdout.expected
1411 (cd $testroot/wt && got log -l 1 > $testroot/stdout)
1412 cmp -s $testroot/stdout.expected $testroot/stdout
1413 ret="$?"
1414 if [ "$ret" != "0" ]; then
1415 diff -u $testroot/stdout.expected $testroot/stdout
1416 test_done "$testroot" "$ret"
1417 return 1
1420 echo "modified alpha again" > $testroot/wt/alpha
1422 echo 'test commit_prepared_logmsg non-interactive' \
1423 > $testroot/logmsg
1425 (cd $testroot/wt && got commit -N -F "$testroot/logmsg" \
1426 > $testroot/stdout)
1428 local head_rev=`git_show_head $testroot/repo`
1429 echo "M alpha" > $testroot/stdout.expected
1430 echo "Created commit $head_rev" >> $testroot/stdout.expected
1432 cmp -s $testroot/stdout.expected $testroot/stdout
1433 ret="$?"
1434 if [ "$ret" != "0" ]; then
1435 diff -u $testroot/stdout.expected $testroot/stdout
1436 test_done "$testroot" "$ret"
1437 return 1
1440 local author_time=`git_show_author_time $testroot/repo`
1441 d=`env LC_TIME=C date -u -d "@$author_time" +"%a %b %e %X %Y UTC"`
1442 echo "-----------------------------------------------" \
1443 > $testroot/stdout.expected
1444 echo "commit $head_rev (master)" >> $testroot/stdout.expected
1445 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
1446 echo "date: $d" >> $testroot/stdout.expected
1447 echo " " >> $testroot/stdout.expected
1448 echo " test commit_prepared_logmsg non-interactive" \
1449 >> $testroot/stdout.expected
1450 echo " " >> $testroot/stdout.expected
1452 (cd $testroot/wt && got log -l 1 > $testroot/stdout)
1453 cmp -s $testroot/stdout.expected $testroot/stdout
1454 ret="$?"
1455 if [ "$ret" != "0" ]; then
1456 diff -u $testroot/stdout.expected $testroot/stdout
1458 test_done "$testroot" "$ret"
1461 test_parseargs "$@"
1462 run_test test_commit_basic
1463 run_test test_commit_new_subdir
1464 run_test test_commit_subdir
1465 run_test test_commit_single_file
1466 run_test test_commit_out_of_date
1467 run_test test_commit_added_subdirs
1468 run_test test_commit_deleted_subdirs
1469 run_test test_commit_rejects_conflicted_file
1470 run_test test_commit_single_file_multiple
1471 run_test test_commit_added_and_modified_in_same_dir
1472 run_test test_commit_path_prefix
1473 run_test test_commit_dir_path
1474 run_test test_commit_selected_paths
1475 run_test test_commit_outside_refs_heads
1476 run_test test_commit_no_email
1477 run_test test_commit_tree_entry_sorting
1478 run_test test_commit_gotconfig_author
1479 run_test test_commit_gotconfig_worktree_author
1480 run_test test_commit_gitconfig_author
1481 run_test test_commit_xbit_change
1482 run_test test_commit_normalizes_filemodes
1483 run_test test_commit_with_unrelated_submodule
1484 run_test test_commit_symlink
1485 run_test test_commit_fix_bad_symlink
1486 run_test test_commit_prepared_logmsg