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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -eq 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 -ne 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 -ne 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 -ne 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 -eq 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 -ne 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 -ne 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 -ne 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: :flan_hacker:: commit author's email address " \
653 > $testroot/stderr.expected
654 echo "is required for compatibility with Git" \
655 >> $testroot/stderr.expected
656 cmp -s $testroot/stderr.expected $testroot/stderr
657 ret=$?
658 if [ $ret -ne 0 ]; then
659 diff -u $testroot/stderr.expected $testroot/stderr
660 test_done "$testroot" "$ret"
661 return 1
662 fi
664 echo -n > $testroot/stdout.expected
665 cmp -s $testroot/stdout.expected $testroot/stdout
666 ret=$?
667 if [ $ret -ne 0 ]; then
668 diff -u $testroot/stdout.expected $testroot/stdout
669 fi
670 test_done "$testroot" "$ret"
673 test_commit_tree_entry_sorting() {
674 local testroot=`test_init commit_tree_entry_sorting`
676 got checkout $testroot/repo $testroot/wt > /dev/null
677 ret=$?
678 if [ $ret -ne 0 ]; then
679 test_done "$testroot" "$ret"
680 return 1
681 fi
683 # Git's index gets corrupted when tree entries are written in the
684 # order defined by got_path_cmp() rather than Git's own ordering.
685 # Create a new tree where a directory "got" and a file "got-version"
686 # would sort in the wrong order according to Git's opinion.
687 mkdir $testroot/wt/got
688 touch $testroot/wt/got/foo
689 echo foo > $testroot/wt/got-version
690 echo zzz > $testroot/wt/zzz
691 (cd $testroot/wt && got add got-version got/foo zzz > /dev/null)
693 (cd $testroot/wt && got commit -m 'test' > /dev/null)
695 # Let git-fsck verify the newly written tree to make sure Git is happy
696 (cd $testroot/repo && git fsck --strict \
697 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
698 ret=$?
699 test_done "$testroot" "$ret"
702 test_commit_gotconfig_author() {
703 local testroot=`test_init commit_gotconfig_author`
705 got checkout $testroot/repo $testroot/wt > /dev/null
706 ret=$?
707 if [ $ret -ne 0 ]; then
708 test_done "$testroot" "$ret"
709 return 1
710 fi
711 echo 'author "Flan Luck <flan_luck@openbsd.org>"' \
712 > $testroot/repo/.git/got.conf
714 echo "modified alpha" > $testroot/wt/alpha
715 (cd $testroot/wt && got commit -m 'test gotconfig author' > /dev/null)
716 ret=$?
717 if [ $ret -ne 0 ]; then
718 test_done "$testroot" "$ret"
719 return 1
720 fi
722 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
723 ret=$?
724 if [ $ret -ne 0 ]; then
725 test_done "$testroot" "$ret"
726 return 1
727 fi
729 echo "from: Flan Luck <flan_luck@openbsd.org>" \
730 > $testroot/stdout.expected
731 cmp -s $testroot/stdout.expected $testroot/stdout
732 ret=$?
733 if [ $ret -ne 0 ]; then
734 diff -u $testroot/stdout.expected $testroot/stdout
735 fi
736 test_done "$testroot" "$ret"
739 test_commit_gotconfig_worktree_author() {
740 local testroot=`test_init commit_gotconfig_worktree_author`
742 got checkout $testroot/repo $testroot/wt > /dev/null
743 ret=$?
744 if [ $ret -ne 0 ]; then
745 test_done "$testroot" "$ret"
746 return 1
747 fi
748 echo 'author "Flan Luck <flan_luck@openbsd.org>"' \
749 > $testroot/repo/.git/got.conf
750 echo 'author "Flan Squee <flan_squee@openbsd.org>"' \
751 > $testroot/wt/.got/got.conf
753 echo "modified alpha" > $testroot/wt/alpha
754 (cd $testroot/wt && got commit -m 'test gotconfig author' > /dev/null)
755 ret=$?
756 if [ $ret -ne 0 ]; then
757 test_done "$testroot" "$ret"
758 return 1
759 fi
761 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
762 ret=$?
763 if [ $ret -ne 0 ]; then
764 test_done "$testroot" "$ret"
765 return 1
766 fi
768 echo "from: Flan Squee <flan_squee@openbsd.org>" \
769 > $testroot/stdout.expected
770 cmp -s $testroot/stdout.expected $testroot/stdout
771 ret=$?
772 if [ $ret -ne 0 ]; then
773 diff -u $testroot/stdout.expected $testroot/stdout
774 fi
775 test_done "$testroot" "$ret"
778 test_commit_gitconfig_author() {
779 local testroot=`test_init commit_gitconfig_author`
781 got checkout $testroot/repo $testroot/wt > /dev/null
782 ret=$?
783 if [ $ret -ne 0 ]; then
784 test_done "$testroot" "$ret"
785 return 1
786 fi
788 (cd $testroot/repo && git config user.name 'Flan Luck')
789 (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
791 echo "modified alpha" > $testroot/wt/alpha
792 (cd $testroot/wt && got commit -m 'test gitconfig author' > /dev/null)
793 ret=$?
794 if [ $ret -ne 0 ]; then
795 test_done "$testroot" "$ret"
796 return 1
797 fi
799 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
800 ret=$?
801 if [ $ret -ne 0 ]; then
802 test_done "$testroot" "$ret"
803 return 1
804 fi
806 echo "from: Flan Luck <flan_luck@openbsd.org>" \
807 > $testroot/stdout.expected
808 cmp -s $testroot/stdout.expected $testroot/stdout
809 ret=$?
810 if [ $ret -ne 0 ]; then
811 diff -u $testroot/stdout.expected $testroot/stdout
812 fi
813 test_done "$testroot" "$ret"
816 test_commit_xbit_change() {
817 local testroot=`test_init commit_xbit_change`
819 got checkout $testroot/repo $testroot/wt > /dev/null
820 ret=$?
821 if [ $ret -ne 0 ]; then
822 test_done "$testroot" "$ret"
823 return 1
824 fi
826 chmod +x $testroot/wt/alpha
828 echo 'm alpha' > $testroot/stdout.expected
829 (cd $testroot/wt && got status > $testroot/stdout)
831 cmp -s $testroot/stdout.expected $testroot/stdout
832 ret=$?
833 if [ $ret -ne 0 ]; then
834 diff -u $testroot/stdout.expected $testroot/stdout
835 test_done "$testroot" "$ret"
836 return 1
837 fi
839 (cd $testroot/wt && got commit -mx > $testroot/stdout)
840 ret=$?
841 if [ $ret -ne 0 ]; then
842 echo "got commit failed unexpectedly"
843 test_done "$testroot" "$ret"
844 return 1
845 fi
847 local commit_id=`git_show_head $testroot/repo`
848 echo 'm alpha' > $testroot/stdout.expected
849 echo "Created commit $commit_id" >> $testroot/stdout.expected
850 cmp -s $testroot/stdout.expected $testroot/stdout
851 ret=$?
852 if [ $ret -ne 0 ]; then
853 diff -u $testroot/stdout.expected $testroot/stdout
854 test_done "$testroot" "$ret"
855 return 1
856 fi
858 (cd $testroot/wt && got status > $testroot/stdout)
860 echo -n > $testroot/stdout.expected
861 cmp -s $testroot/stdout.expected $testroot/stdout
862 ret=$?
863 if [ $ret -ne 0 ]; then
864 diff -u $testroot/stdout.expected $testroot/stdout
865 test_done "$testroot" "$ret"
866 return 1
867 fi
869 chmod -x $testroot/wt/alpha
871 echo 'm alpha' > $testroot/stdout.expected
872 (cd $testroot/wt && got status > $testroot/stdout)
874 cmp -s $testroot/stdout.expected $testroot/stdout
875 ret=$?
876 if [ $ret -ne 0 ]; then
877 diff -u $testroot/stdout.expected $testroot/stdout
878 test_done "$testroot" "$ret"
879 return 1
880 fi
882 (cd $testroot/wt && got commit -mx > $testroot/stdout)
883 ret=$?
884 if [ $ret -ne 0 ]; then
885 echo "got commit failed unexpectedly"
886 test_done "$testroot" "$ret"
887 return 1
888 fi
890 local commit_id=`git_show_head $testroot/repo`
891 echo 'm alpha' > $testroot/stdout.expected
892 echo "Created commit $commit_id" >> $testroot/stdout.expected
893 cmp -s $testroot/stdout.expected $testroot/stdout
894 ret=$?
895 if [ $ret -ne 0 ]; then
896 diff -u $testroot/stdout.expected $testroot/stdout
897 test_done "$testroot" "$ret"
898 return 1
899 fi
901 chmod +x $testroot/wt/alpha
903 echo 'm alpha' > $testroot/stdout.expected
904 (cd $testroot/wt && got status > $testroot/stdout)
906 cmp -s $testroot/stdout.expected $testroot/stdout
907 ret=$?
908 if [ $ret -ne 0 ]; then
909 diff -u $testroot/stdout.expected $testroot/stdout
910 fi
911 test_done "$testroot" "$ret"
914 commit_check_mode() {
915 local mode="$1"
916 local expected_mode="$2"
918 chmod 644 $testroot/wt/alpha
919 echo a >> $testroot/wt/alpha
920 chmod $mode $testroot/wt/alpha
922 (cd $testroot/wt && got commit -mm > $testroot/stdout)
923 ret=$?
924 if [ $ret -ne 0 ]; then
925 echo "got commit failed unexpectedly"
926 test_done "$testroot" "$ret"
927 return 1
928 fi
930 local commit_id=`git_show_head $testroot/repo`
931 echo 'M alpha' > $testroot/stdout.expected
932 echo "Created commit $commit_id" >> $testroot/stdout.expected
933 cmp -s $testroot/stdout.expected $testroot/stdout
934 ret=$?
935 if [ $ret -ne 0 ]; then
936 diff -u $testroot/stdout.expected $testroot/stdout
937 test_done "$testroot" "$ret"
938 return 1
939 fi
941 local tree_id=$(got cat -r $testroot/repo $commit_id | \
942 grep ^tree | cut -d' ' -f2)
943 local alpha_id=$(got cat -r $testroot/repo $tree_id | \
944 grep 'alpha$' | cut -d' ' -f1)
945 echo "$alpha_id $expected_mode alpha" > $testroot/stdout.expected
946 got cat -r $testroot/repo $tree_id | grep 'alpha$' > $testroot/stdout
947 cmp -s $testroot/stdout.expected $testroot/stdout
948 ret=$?
949 if [ $ret -ne 0 ]; then
950 diff -u $testroot/stdout.expected $testroot/stdout
951 fi
952 return $ret
955 test_commit_normalizes_filemodes() {
956 local testroot=`test_init commit_normalizes_filemodes`
958 got checkout $testroot/repo $testroot/wt > /dev/null
959 ret=$?
960 if [ $ret -ne 0 ]; then
961 test_done "$testroot" "$ret"
962 return 1
963 fi
965 modes="600 400 460 640 440 660 444 666"
966 for m in $modes; do
967 commit_check_mode "$m" "0100644"
968 ret=$?
969 if [ $ret -ne 0 ]; then
970 break
971 fi
972 done
973 if [ $ret -ne 0 ]; then
974 test_done "$testroot" "$ret"
975 return 1
976 fi
977 modes="700 500 570 750 550 770 555 777"
978 for m in $modes; do
979 commit_check_mode "$m" "0100755"
980 ret=$?
981 if [ $ret -ne 0 ]; then
982 break
983 fi
984 done
985 if [ $ret -ne 0 ]; then
986 test_done "$testroot" "$ret"
987 return 1
988 fi
989 test_done "$testroot" "$ret"
992 test_commit_with_unrelated_submodule() {
993 local testroot=`test_init commit_with_unrelated_submodule`
995 make_single_file_repo $testroot/repo2 foo
997 (cd $testroot/repo && git submodule -q add ../repo2)
998 (cd $testroot/repo && git commit -q -m 'adding submodule')
1000 got checkout $testroot/repo $testroot/wt > /dev/null
1001 ret=$?
1002 if [ $ret -ne 0 ]; then
1003 echo "checkout failed unexpectedly" >&2
1004 test_done "$testroot" "$ret"
1005 return 1
1008 echo "modified alpha" > $testroot/wt/alpha
1010 echo "" > $testroot/stdout.expected
1012 (cd $testroot/wt && got commit -m 'modify alpha' > $testroot/stdout)
1013 ret=$?
1014 if [ $ret -ne 0 ]; then
1015 echo "commit failed unexpectedly" >&2
1016 test_done "$testroot" "$ret"
1017 return 1
1020 local head_rev=`git_show_head $testroot/repo`
1021 echo "M alpha" > $testroot/stdout.expected
1022 echo "Created commit $head_rev" >> $testroot/stdout.expected
1024 cmp -s $testroot/stdout.expected $testroot/stdout
1025 ret=$?
1026 if [ $ret -ne 0 ]; then
1027 diff -u $testroot/stdout.expected $testroot/stdout
1029 test_done "$testroot" "$ret"
1032 check_symlinks() {
1033 local wtpath="$1"
1034 if ! [ -h $wtpath/alpha.link ]; then
1035 echo "alpha.link is not a symlink"
1036 return 1
1039 readlink $wtpath/alpha.link > $testroot/stdout
1040 echo "alpha" > $testroot/stdout.expected
1041 cmp -s $testroot/stdout.expected $testroot/stdout
1042 ret=$?
1043 if [ $ret -ne 0 ]; then
1044 diff -u $testroot/stdout.expected $testroot/stdout
1045 return 1
1048 if ! [ -h $wtpath/epsilon.link ]; then
1049 echo "epsilon.link is not a symlink"
1050 return 1
1053 readlink $wtpath/epsilon.link > $testroot/stdout
1054 echo "epsilon" > $testroot/stdout.expected
1055 cmp -s $testroot/stdout.expected $testroot/stdout
1056 ret=$?
1057 if [ $ret -ne 0 ]; then
1058 diff -u $testroot/stdout.expected $testroot/stdout
1059 return 1
1062 if [ -h $wtpath/passwd.link ]; then
1063 echo -n "passwd.link is a symlink and points outside of work tree: " >&2
1064 readlink $wtpath/passwd.link >&2
1065 return 1
1068 echo -n "/etc/passwd" > $testroot/content.expected
1069 cp $wtpath/passwd.link $testroot/content
1070 ret=$?
1071 if [ $ret -ne 0 ]; then
1072 echo "cp command failed unexpectedly" >&2
1073 return 1
1076 cmp -s $testroot/content.expected $testroot/content
1077 ret=$?
1078 if [ $ret -ne 0 ]; then
1079 diff -u $testroot/content.expected $testroot/content
1080 return 1
1083 readlink $wtpath/epsilon/beta.link > $testroot/stdout
1084 echo "../beta" > $testroot/stdout.expected
1085 cmp -s $testroot/stdout.expected $testroot/stdout
1086 ret=$?
1087 if [ $ret -ne 0 ]; then
1088 diff -u $testroot/stdout.expected $testroot/stdout
1089 return 1
1092 readlink $wtpath/nonexistent.link > $testroot/stdout
1093 echo "nonexistent" > $testroot/stdout.expected
1094 cmp -s $testroot/stdout.expected $testroot/stdout
1095 ret=$?
1096 if [ $ret -ne 0 ]; then
1097 diff -u $testroot/stdout.expected $testroot/stdout
1098 return 1
1101 return 0
1104 test_commit_symlink() {
1105 local testroot=`test_init commit_symlink`
1107 got checkout $testroot/repo $testroot/wt > /dev/null
1108 ret=$?
1109 if [ $ret -ne 0 ]; then
1110 test_done "$testroot" "$ret"
1111 return 1
1114 (cd $testroot/wt && ln -s alpha alpha.link)
1115 (cd $testroot/wt && ln -s epsilon epsilon.link)
1116 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1117 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
1118 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
1119 (cd $testroot/wt && got add alpha.link epsilon.link passwd.link \
1120 epsilon/beta.link nonexistent.link > /dev/null)
1122 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1123 > $testroot/stdout 2> $testroot/stderr)
1124 ret=$?
1125 if [ $ret -eq 0 ]; then
1126 echo "got commit succeeded unexpectedly" >&2
1127 test_done "$testroot" "$ret"
1128 return 1
1130 echo -n "got: $testroot/wt/passwd.link: " > $testroot/stderr.expected
1131 echo "symbolic link points outside of paths under version control" \
1132 >> $testroot/stderr.expected
1133 cmp -s $testroot/stderr.expected $testroot/stderr
1134 ret=$?
1135 if [ $ret -ne 0 ]; then
1136 diff -u $testroot/stderr.expected $testroot/stderr
1137 test_done "$testroot" "$ret"
1138 return 1
1141 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1142 > $testroot/stdout)
1144 local head_rev=`git_show_head $testroot/repo`
1145 echo "A alpha.link" > $testroot/stdout.expected
1146 echo "A epsilon.link" >> $testroot/stdout.expected
1147 echo "A nonexistent.link" >> $testroot/stdout.expected
1148 echo "A passwd.link" >> $testroot/stdout.expected
1149 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1150 echo "Created commit $head_rev" >> $testroot/stdout.expected
1152 cmp -s $testroot/stdout.expected $testroot/stdout
1153 ret=$?
1154 if [ $ret -ne 0 ]; then
1155 diff -u $testroot/stdout.expected $testroot/stdout
1156 test_done "$testroot" "$ret"
1157 return 1
1160 # verify created in-repository tree
1161 got checkout $testroot/repo $testroot/wt2 > /dev/null
1162 ret=$?
1163 if [ $ret -ne 0 ]; then
1164 test_done "$testroot" "$ret"
1165 return 1
1167 check_symlinks $testroot/wt2
1168 ret=$?
1169 if [ $ret -ne 0 ]; then
1170 test_done "$testroot" "$ret"
1171 return 1
1174 if ! [ -h $testroot/wt/passwd.link ]; then
1175 echo 'passwd.link is not a symlink' >&2
1176 test_done "$testroot" 1
1177 return 1
1180 # 'got update' should reinstall passwd.link as a regular file
1181 (cd $testroot/wt && got update > /dev/null)
1182 check_symlinks $testroot/wt
1183 ret=$?
1184 if [ $ret -ne 0 ]; then
1185 test_done "$testroot" "$ret"
1186 return 1
1189 (cd $testroot/wt && ln -sf beta alpha.link)
1190 (cd $testroot/wt && ln -sfh gamma epsilon.link)
1191 rm $testroot/wt/epsilon/beta.link
1192 echo "this is a regular file" > $testroot/wt/epsilon/beta.link
1193 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
1194 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
1195 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
1196 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
1197 (cd $testroot/wt && ln -sf alpha new.link)
1198 (cd $testroot/wt && got add new.link > /dev/null)
1200 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1201 > $testroot/stdout 2> $testroot/stderr)
1202 ret=$?
1203 if [ $ret -eq 0 ]; then
1204 echo "got commit succeeded unexpectedly" >&2
1205 test_done "$testroot" "$ret"
1206 return 1
1208 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
1209 echo "symbolic link points outside of paths under version control" \
1210 >> $testroot/stderr.expected
1211 cmp -s $testroot/stderr.expected $testroot/stderr
1212 ret=$?
1213 if [ $ret -ne 0 ]; then
1214 diff -u $testroot/stderr.expected $testroot/stderr
1215 test_done "$testroot" "$ret"
1216 return 1
1219 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1220 > $testroot/stdout)
1222 local head_rev=`git_show_head $testroot/repo`
1223 echo "A dotgotbar.link" > $testroot/stdout.expected
1224 echo "A new.link" >> $testroot/stdout.expected
1225 echo "M alpha.link" >> $testroot/stdout.expected
1226 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1227 echo "M epsilon.link" >> $testroot/stdout.expected
1228 echo "D nonexistent.link" >> $testroot/stdout.expected
1229 echo "Created commit $head_rev" >> $testroot/stdout.expected
1231 cmp -s $testroot/stdout.expected $testroot/stdout
1232 ret=$?
1233 if [ $ret -ne 0 ]; then
1234 diff -u $testroot/stdout.expected $testroot/stdout
1235 test_done "$testroot" "$ret"
1236 return 1
1239 got tree -r $testroot/repo -c $head_rev -R > $testroot/stdout
1240 cat > $testroot/stdout.expected <<EOF
1241 alpha
1242 alpha.link@ -> beta
1243 beta
1244 dotgotbar.link@ -> .got/bar
1245 epsilon/
1246 epsilon/beta.link
1247 epsilon/zeta
1248 epsilon.link@ -> gamma
1249 gamma/
1250 gamma/delta
1251 new.link@ -> alpha
1252 passwd.link@ -> /etc/passwd
1253 EOF
1254 cmp -s $testroot/stdout.expected $testroot/stdout
1255 ret=$?
1256 if [ $ret -ne 0 ]; then
1257 diff -u $testroot/stdout.expected $testroot/stdout
1259 test_done "$testroot" "$ret"
1262 test_commit_fix_bad_symlink() {
1263 local testroot=`test_init commit_fix_bad_symlink`
1265 got checkout $testroot/repo $testroot/wt > /dev/null
1266 ret=$?
1267 if [ $ret -ne 0 ]; then
1268 echo "got checkout failed unexpectedly" >&2
1269 test_done "$testroot" "$ret"
1270 return 1
1273 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1274 (cd $testroot/wt && got add passwd.link > /dev/null)
1276 (cd $testroot/wt && got commit -S -m 'commit bad symlink' \
1277 > $testroot/stdout)
1279 if ! [ -h $testroot/wt/passwd.link ]; then
1280 echo 'passwd.link is not a symlink' >&2
1281 test_done "$testroot" 1
1282 return 1
1284 (cd $testroot/wt && got update >/dev/null)
1285 if [ -h $testroot/wt/passwd.link ]; then
1286 echo "passwd.link is a symlink but should be a regular file" >&2
1287 test_done "$testroot" "1"
1288 return 1
1291 # create another work tree which will contain the "bad" symlink
1292 got checkout $testroot/repo $testroot/wt2 > /dev/null
1293 ret=$?
1294 if [ $ret -ne 0 ]; then
1295 echo "got checkout failed unexpectedly" >&2
1296 test_done "$testroot" "$ret"
1297 return 1
1300 # change "bad" symlink back into a "good" symlink
1301 (cd $testroot/wt && ln -sfh alpha passwd.link)
1303 (cd $testroot/wt && got commit -m 'fix bad symlink' \
1304 > $testroot/stdout)
1306 local head_rev=`git_show_head $testroot/repo`
1307 echo "M passwd.link" > $testroot/stdout.expected
1308 echo "Created commit $head_rev" >> $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 test_done "$testroot" "$ret"
1315 return 1
1318 if ! [ -h $testroot/wt/passwd.link ]; then
1319 echo 'passwd.link is not a symlink' >&2
1320 test_done "$testroot" 1
1321 return 1
1324 readlink $testroot/wt/passwd.link > $testroot/stdout
1325 echo "alpha" > $testroot/stdout.expected
1326 cmp -s $testroot/stdout.expected $testroot/stdout
1327 ret=$?
1328 if [ $ret -ne 0 ]; then
1329 diff -u $testroot/stdout.expected $testroot/stdout
1330 return 1
1333 # Update the other work tree; the bad symlink should be fixed
1334 (cd $testroot/wt2 && got update > /dev/null)
1335 ret=$?
1336 if [ $ret -ne 0 ]; then
1337 echo "got checkout failed unexpectedly" >&2
1338 test_done "$testroot" "$ret"
1339 return 1
1342 if ! [ -h $testroot/wt2/passwd.link ]; then
1343 echo 'passwd.link is not a symlink' >&2
1344 test_done "$testroot" 1
1345 return 1
1348 readlink $testroot/wt2/passwd.link > $testroot/stdout
1349 echo "alpha" > $testroot/stdout.expected
1350 cmp -s $testroot/stdout.expected $testroot/stdout
1351 ret=$?
1352 if [ $ret -ne 0 ]; then
1353 diff -u $testroot/stdout.expected $testroot/stdout
1354 return 1
1357 test_done "$testroot" "0"
1360 test_commit_prepared_logmsg() {
1361 local testroot=`test_init commit_prepared_logmsg`
1363 got checkout $testroot/repo $testroot/wt > /dev/null
1364 ret=$?
1365 if [ $ret -ne 0 ]; then
1366 test_done "$testroot" "$ret"
1367 return 1
1370 echo "modified alpha" > $testroot/wt/alpha
1371 (cd $testroot/wt && got rm beta >/dev/null)
1372 echo "new file" > $testroot/wt/new
1373 (cd $testroot/wt && got add new >/dev/null)
1375 echo 'test commit_prepared_logmsg' > $testroot/logmsg
1377 cat > $testroot/editor.sh <<EOF
1378 #!/bin/sh
1379 sed -i 's/foo/bar/' "\$1"
1380 EOF
1381 chmod +x $testroot/editor.sh
1383 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
1384 got commit -F "$testroot/logmsg" > $testroot/stdout)
1386 local head_rev=`git_show_head $testroot/repo`
1387 echo "A new" > $testroot/stdout.expected
1388 echo "M alpha" >> $testroot/stdout.expected
1389 echo "D beta" >> $testroot/stdout.expected
1390 echo "Created commit $head_rev" >> $testroot/stdout.expected
1392 cmp -s $testroot/stdout.expected $testroot/stdout
1393 ret=$?
1394 if [ $ret -ne 0 ]; then
1395 diff -u $testroot/stdout.expected $testroot/stdout
1396 test_done "$testroot" "$ret"
1397 return 1
1400 local author_time=`git_show_author_time $testroot/repo`
1401 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
1402 echo "-----------------------------------------------" > $testroot/stdout.expected
1403 echo "commit $head_rev (master)" >> $testroot/stdout.expected
1404 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
1405 echo "date: $d" >> $testroot/stdout.expected
1406 echo " " >> $testroot/stdout.expected
1407 echo " test commit_prepared_logmsg" >> $testroot/stdout.expected
1408 echo " " >> $testroot/stdout.expected
1410 (cd $testroot/wt && got log -l 1 > $testroot/stdout)
1411 cmp -s $testroot/stdout.expected $testroot/stdout
1412 ret=$?
1413 if [ $ret -ne 0 ]; then
1414 diff -u $testroot/stdout.expected $testroot/stdout
1415 test_done "$testroot" "$ret"
1416 return 1
1419 echo "modified alpha again" > $testroot/wt/alpha
1421 echo 'test commit_prepared_logmsg non-interactive' \
1422 > $testroot/logmsg
1424 (cd $testroot/wt && got commit -N -F "$testroot/logmsg" \
1425 > $testroot/stdout)
1427 local head_rev=`git_show_head $testroot/repo`
1428 echo "M alpha" > $testroot/stdout.expected
1429 echo "Created commit $head_rev" >> $testroot/stdout.expected
1431 cmp -s $testroot/stdout.expected $testroot/stdout
1432 ret=$?
1433 if [ $ret -ne 0 ]; then
1434 diff -u $testroot/stdout.expected $testroot/stdout
1435 test_done "$testroot" "$ret"
1436 return 1
1439 local author_time=`git_show_author_time $testroot/repo`
1440 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
1441 echo "-----------------------------------------------" \
1442 > $testroot/stdout.expected
1443 echo "commit $head_rev (master)" >> $testroot/stdout.expected
1444 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
1445 echo "date: $d" >> $testroot/stdout.expected
1446 echo " " >> $testroot/stdout.expected
1447 echo " test commit_prepared_logmsg non-interactive" \
1448 >> $testroot/stdout.expected
1449 echo " " >> $testroot/stdout.expected
1451 (cd $testroot/wt && got log -l 1 > $testroot/stdout)
1452 cmp -s $testroot/stdout.expected $testroot/stdout
1453 ret=$?
1454 if [ $ret -ne 0 ]; then
1455 diff -u $testroot/stdout.expected $testroot/stdout
1457 test_done "$testroot" "$ret"
1460 test_commit_large_file() {
1461 local testroot=`test_init commit_large_file`
1463 got checkout $testroot/repo $testroot/wt > /dev/null
1464 ret=$?
1465 if [ $ret -ne 0 ]; then
1466 test_done "$testroot" "$ret"
1467 return 1
1470 dd status=none if=/dev/zero of=$testroot/wt/new bs=1m count=64
1471 (cd $testroot/wt && got add new >/dev/null)
1473 (cd $testroot/wt && got commit -m 'test commit_large_file' \
1474 > $testroot/stdout)
1476 local head_rev=`git_show_head $testroot/repo`
1477 echo "A new" > $testroot/stdout.expected
1478 echo "Created commit $head_rev" >> $testroot/stdout.expected
1480 cmp -s $testroot/stdout.expected $testroot/stdout
1481 ret=$?
1482 if [ $ret -ne 0 ]; then
1483 diff -u $testroot/stdout.expected $testroot/stdout
1484 test_done "$testroot" "$ret"
1485 return 1
1488 new_id=`get_blob_id $testroot/repo "" new`
1489 got cat -r $testroot/repo $new_id > $testroot/new
1490 ret=$?
1491 if [ $ret -ne 0 ]; then
1492 echo "commit failed unexpectedly" >&2
1493 test_done "$testroot" "1"
1494 return 1
1497 cmp -s $testroot/new $testroot/wt/new
1498 ret=$?
1499 if [ $ret -ne 0 ]; then
1500 diff -u $testroot/new $testroot/wt/new
1502 test_done "$testroot" "$ret"
1508 test_parseargs "$@"
1509 run_test test_commit_basic
1510 run_test test_commit_new_subdir
1511 run_test test_commit_subdir
1512 run_test test_commit_single_file
1513 run_test test_commit_out_of_date
1514 run_test test_commit_added_subdirs
1515 run_test test_commit_deleted_subdirs
1516 run_test test_commit_rejects_conflicted_file
1517 run_test test_commit_single_file_multiple
1518 run_test test_commit_added_and_modified_in_same_dir
1519 run_test test_commit_path_prefix
1520 run_test test_commit_dir_path
1521 run_test test_commit_selected_paths
1522 run_test test_commit_outside_refs_heads
1523 run_test test_commit_no_email
1524 run_test test_commit_tree_entry_sorting
1525 run_test test_commit_gotconfig_author
1526 run_test test_commit_gotconfig_worktree_author
1527 run_test test_commit_gitconfig_author
1528 run_test test_commit_xbit_change
1529 run_test test_commit_normalizes_filemodes
1530 run_test test_commit_with_unrelated_submodule
1531 run_test test_commit_symlink
1532 run_test test_commit_fix_bad_symlink
1533 run_test test_commit_prepared_logmsg
1534 run_test test_commit_large_file