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 "commit - $commit1" >> $testroot/stdout.expected
432 echo "commit + $commit2" >> $testroot/stdout.expected
433 echo -n 'blob - ' >> $testroot/stdout.expected
434 got tree -r $testroot/repo -c $commit1 -i gamma | grep 'delta$' \
435 | cut -d' ' -f 1 >> $testroot/stdout.expected
436 echo -n 'blob + ' >> $testroot/stdout.expected
437 got tree -r $testroot/repo -c $commit2 -i gamma | grep 'delta$' | \
438 cut -d' ' -f 1 >> $testroot/stdout.expected
439 echo '--- gamma/delta' >> $testroot/stdout.expected
440 echo '+++ gamma/delta' >> $testroot/stdout.expected
441 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
442 echo '-delta' >> $testroot/stdout.expected
443 echo '+modified delta' >> $testroot/stdout.expected
445 got diff -r $testroot/repo $commit1 $commit2 > $testroot/stdout
446 cmp -s $testroot/stdout.expected $testroot/stdout
447 ret=$?
448 if [ $ret -ne 0 ]; then
449 diff -u $testroot/stdout.expected $testroot/stdout
450 test_done "$testroot" "$ret"
451 return 1
452 fi
454 (cd $testroot/wt && got rm delta > /dev/null)
455 echo new > $testroot/wt/new
456 (cd $testroot/wt && got add new > /dev/null)
458 (cd $testroot/wt && got commit -m 'remove gamma/delta; add gamma/new' \
459 > $testroot/stdout)
461 local commit3=`git_show_head $testroot/repo`
462 echo "A new" > $testroot/stdout.expected
463 echo "D delta" >> $testroot/stdout.expected
464 echo "Created commit $commit3" >> $testroot/stdout.expected
466 cmp -s $testroot/stdout.expected $testroot/stdout
467 ret=$?
468 if [ $ret -ne 0 ]; then
469 diff -u $testroot/stdout.expected $testroot/stdout
470 test_done "$testroot" "$ret"
471 return 1
472 fi
474 echo "diff $commit2 $commit3" > $testroot/stdout.expected
475 echo "commit - $commit2" >> $testroot/stdout.expected
476 echo "commit + $commit3" >> $testroot/stdout.expected
477 echo -n 'blob - ' >> $testroot/stdout.expected
478 got tree -r $testroot/repo -c $commit2 -i gamma | grep 'delta$' \
479 | cut -d' ' -f 1 | sed -e 's/$/ (mode 644)/' \
480 >> $testroot/stdout.expected
481 echo 'blob + /dev/null' >> $testroot/stdout.expected
482 echo '--- gamma/delta' >> $testroot/stdout.expected
483 echo '+++ /dev/null' >> $testroot/stdout.expected
484 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
485 echo '-modified delta' >> $testroot/stdout.expected
486 echo 'blob - /dev/null' >> $testroot/stdout.expected
487 echo -n 'blob + ' >> $testroot/stdout.expected
488 got tree -r $testroot/repo -c $commit3 -i gamma | grep 'new$' | \
489 cut -d' ' -f 1 | sed -e 's/$/ (mode 644)/' \
490 >> $testroot/stdout.expected
491 echo '--- /dev/null' >> $testroot/stdout.expected
492 echo '+++ gamma/new' >> $testroot/stdout.expected
493 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
494 echo '+new' >> $testroot/stdout.expected
496 got diff -r $testroot/repo $commit2 $commit3 > $testroot/stdout
497 cmp -s $testroot/stdout.expected $testroot/stdout
498 ret=$?
499 if [ $ret -ne 0 ]; then
500 diff -u $testroot/stdout.expected $testroot/stdout
501 fi
502 test_done "$testroot" "$ret"
503 return "$ret"
506 test_commit_dir_path() {
507 local testroot=`test_init commit_dir_path`
509 got checkout $testroot/repo $testroot/wt > /dev/null
510 ret=$?
511 if [ $ret -ne 0 ]; then
512 test_done "$testroot" "$ret"
513 return 1
514 fi
516 echo "modified alpha" > $testroot/wt/alpha
517 echo "modified zeta" > $testroot/wt/epsilon/zeta
519 (cd $testroot/wt && got commit -m 'changed zeta' epsilon \
520 > $testroot/stdout)
522 local head_rev=`git_show_head $testroot/repo`
523 echo "M epsilon/zeta" >> $testroot/stdout.expected
524 echo "Created commit $head_rev" >> $testroot/stdout.expected
526 cmp -s $testroot/stdout.expected $testroot/stdout
527 ret=$?
528 if [ $ret -ne 0 ]; then
529 diff -u $testroot/stdout.expected $testroot/stdout
530 test_done "$testroot" "$ret"
531 return 1
532 fi
534 echo "M alpha" > $testroot/stdout.expected
535 (cd $testroot/wt && got status > $testroot/stdout)
536 cmp -s $testroot/stdout.expected $testroot/stdout
537 ret=$?
538 if [ $ret -ne 0 ]; then
539 diff -u $testroot/stdout.expected $testroot/stdout
540 fi
541 test_done "$testroot" "$ret"
544 test_commit_selected_paths() {
545 local testroot=`test_init commit_selected_paths`
547 got checkout $testroot/repo $testroot/wt > /dev/null
548 ret=$?
549 if [ $ret -ne 0 ]; then
550 test_done "$testroot" "$ret"
551 return 1
552 fi
554 echo "modified alpha" > $testroot/wt/alpha
555 echo "modified delta" > $testroot/wt/gamma/delta
556 echo "modified zeta" > $testroot/wt/epsilon/zeta
557 (cd $testroot/wt && got rm beta >/dev/null)
558 echo "new file" > $testroot/wt/new
559 (cd $testroot/wt && got add new >/dev/null)
561 (cd $testroot/wt && got commit -m 'many paths' nonexistent alpha \
562 > $testroot/stdout 2> $testroot/stderr)
563 ret=$?
564 if [ $ret -eq 0 ]; then
565 echo "commit succeeded unexpectedly" >&2
566 test_done "$testroot" "1"
567 return 1
568 fi
569 echo "got: nonexistent: bad path" > $testroot/stderr.expected
571 cmp -s $testroot/stderr.expected $testroot/stderr
572 ret=$?
573 if [ $ret -ne 0 ]; then
574 diff -u $testroot/stderr.expected $testroot/stderr
575 test_done "$testroot" "$ret"
576 return 1
577 fi
579 (cd $testroot/wt && got commit -m 'many paths' \
580 beta new gamma > $testroot/stdout)
582 local head_rev=`git_show_head $testroot/repo`
583 echo "A new" > $testroot/stdout.expected
584 echo "D beta" >> $testroot/stdout.expected
585 echo "M gamma/delta" >> $testroot/stdout.expected
586 echo "Created commit $head_rev" >> $testroot/stdout.expected
588 cmp -s $testroot/stdout.expected $testroot/stdout
589 ret=$?
590 if [ $ret -ne 0 ]; then
591 diff -u $testroot/stdout.expected $testroot/stdout
592 fi
593 test_done "$testroot" "$ret"
596 test_commit_outside_refs_heads() {
597 local testroot=`test_init commit_outside_refs_heads`
599 got ref -r $testroot/repo -c master refs/remotes/origin/master
601 got checkout -b refs/remotes/origin/master \
602 $testroot/repo $testroot/wt > /dev/null
603 ret=$?
604 if [ $ret -ne 0 ]; then
605 test_done "$testroot" "$ret"
606 return 1
607 fi
609 echo "modified alpha" > $testroot/wt/alpha
611 (cd $testroot/wt && got commit -m 'change alpha' \
612 > $testroot/stdout 2> $testroot/stderr)
613 ret=$?
614 if [ $ret -eq 0 ]; then
615 echo "commit succeeded unexpectedly" >&2
616 test_done "$testroot" "1"
617 return 1
618 fi
620 echo -n > $testroot/stdout.expected
621 cmp -s $testroot/stdout.expected $testroot/stdout
622 ret=$?
623 if [ $ret -ne 0 ]; then
624 diff -u $testroot/stdout.expected $testroot/stdout
625 test_done "$testroot" "$ret"
626 return 1
627 fi
629 echo -n "got: will not commit to a branch outside the " \
630 > $testroot/stderr.expected
631 echo '"refs/heads/" reference namespace' \
632 >> $testroot/stderr.expected
633 cmp -s $testroot/stderr.expected $testroot/stderr
634 ret=$?
635 if [ $ret -ne 0 ]; then
636 diff -u $testroot/stderr.expected $testroot/stderr
637 fi
638 test_done "$testroot" "$ret"
641 test_commit_no_email() {
642 local testroot=`test_init commit_no_email`
644 got checkout $testroot/repo $testroot/wt > /dev/null
645 ret=$?
646 if [ $ret -ne 0 ]; then
647 test_done "$testroot" "$ret"
648 return 1
649 fi
651 echo "modified alpha" > $testroot/wt/alpha
652 (cd $testroot/wt && env GOT_AUTHOR=":flan_hacker:" \
653 got commit -m 'test no email' > $testroot/stdout \
654 2> $testroot/stderr)
656 echo -n "got: :flan_hacker:: commit author's email address " \
657 > $testroot/stderr.expected
658 echo "is required for compatibility with Git" \
659 >> $testroot/stderr.expected
660 cmp -s $testroot/stderr.expected $testroot/stderr
661 ret=$?
662 if [ $ret -ne 0 ]; then
663 diff -u $testroot/stderr.expected $testroot/stderr
664 test_done "$testroot" "$ret"
665 return 1
666 fi
668 echo -n > $testroot/stdout.expected
669 cmp -s $testroot/stdout.expected $testroot/stdout
670 ret=$?
671 if [ $ret -ne 0 ]; then
672 diff -u $testroot/stdout.expected $testroot/stdout
673 fi
674 test_done "$testroot" "$ret"
677 test_commit_tree_entry_sorting() {
678 local testroot=`test_init commit_tree_entry_sorting`
680 got checkout $testroot/repo $testroot/wt > /dev/null
681 ret=$?
682 if [ $ret -ne 0 ]; then
683 test_done "$testroot" "$ret"
684 return 1
685 fi
687 # Git's index gets corrupted when tree entries are written in the
688 # order defined by got_path_cmp() rather than Git's own ordering.
689 # Create a new tree where a directory "got" and a file "got-version"
690 # would sort in the wrong order according to Git's opinion.
691 mkdir $testroot/wt/got
692 touch $testroot/wt/got/foo
693 echo foo > $testroot/wt/got-version
694 echo zzz > $testroot/wt/zzz
695 (cd $testroot/wt && got add got-version got/foo zzz > /dev/null)
697 (cd $testroot/wt && got commit -m 'test' > /dev/null)
699 # Let git-fsck verify the newly written tree to make sure Git is happy
700 (cd $testroot/repo && git fsck --strict \
701 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
702 ret=$?
703 test_done "$testroot" "$ret"
706 test_commit_gotconfig_author() {
707 local testroot=`test_init commit_gotconfig_author`
709 got checkout $testroot/repo $testroot/wt > /dev/null
710 ret=$?
711 if [ $ret -ne 0 ]; then
712 test_done "$testroot" "$ret"
713 return 1
714 fi
715 echo 'author "Flan Luck <flan_luck@openbsd.org>"' \
716 > $testroot/repo/.git/got.conf
718 echo "modified alpha" > $testroot/wt/alpha
719 (cd $testroot/wt && got commit -m 'test gotconfig author' > /dev/null)
720 ret=$?
721 if [ $ret -ne 0 ]; then
722 test_done "$testroot" "$ret"
723 return 1
724 fi
726 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
727 ret=$?
728 if [ $ret -ne 0 ]; then
729 test_done "$testroot" "$ret"
730 return 1
731 fi
733 echo "from: Flan Luck <flan_luck@openbsd.org>" \
734 > $testroot/stdout.expected
735 cmp -s $testroot/stdout.expected $testroot/stdout
736 ret=$?
737 if [ $ret -ne 0 ]; then
738 diff -u $testroot/stdout.expected $testroot/stdout
739 fi
740 test_done "$testroot" "$ret"
743 test_commit_gotconfig_worktree_author() {
744 local testroot=`test_init commit_gotconfig_worktree_author`
746 got checkout $testroot/repo $testroot/wt > /dev/null
747 ret=$?
748 if [ $ret -ne 0 ]; then
749 test_done "$testroot" "$ret"
750 return 1
751 fi
752 echo 'author "Flan Luck <flan_luck@openbsd.org>"' \
753 > $testroot/repo/.git/got.conf
754 echo 'author "Flan Squee <flan_squee@openbsd.org>"' \
755 > $testroot/wt/.got/got.conf
757 echo "modified alpha" > $testroot/wt/alpha
758 (cd $testroot/wt && got commit -m 'test gotconfig author' > /dev/null)
759 ret=$?
760 if [ $ret -ne 0 ]; then
761 test_done "$testroot" "$ret"
762 return 1
763 fi
765 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
766 ret=$?
767 if [ $ret -ne 0 ]; then
768 test_done "$testroot" "$ret"
769 return 1
770 fi
772 echo "from: Flan Squee <flan_squee@openbsd.org>" \
773 > $testroot/stdout.expected
774 cmp -s $testroot/stdout.expected $testroot/stdout
775 ret=$?
776 if [ $ret -ne 0 ]; then
777 diff -u $testroot/stdout.expected $testroot/stdout
778 fi
779 test_done "$testroot" "$ret"
782 test_commit_gitconfig_author() {
783 local testroot=`test_init commit_gitconfig_author`
785 got checkout $testroot/repo $testroot/wt > /dev/null
786 ret=$?
787 if [ $ret -ne 0 ]; then
788 test_done "$testroot" "$ret"
789 return 1
790 fi
792 (cd $testroot/repo && git config user.name 'Flan Luck')
793 (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
795 echo "modified alpha" > $testroot/wt/alpha
796 (cd $testroot/wt && got commit -m 'test gitconfig author' > /dev/null)
797 ret=$?
798 if [ $ret -ne 0 ]; then
799 test_done "$testroot" "$ret"
800 return 1
801 fi
803 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
804 ret=$?
805 if [ $ret -ne 0 ]; then
806 test_done "$testroot" "$ret"
807 return 1
808 fi
810 echo "from: Flan Luck <flan_luck@openbsd.org>" \
811 > $testroot/stdout.expected
812 cmp -s $testroot/stdout.expected $testroot/stdout
813 ret=$?
814 if [ $ret -ne 0 ]; then
815 diff -u $testroot/stdout.expected $testroot/stdout
816 fi
817 test_done "$testroot" "$ret"
820 test_commit_xbit_change() {
821 local testroot=`test_init commit_xbit_change`
823 got checkout $testroot/repo $testroot/wt > /dev/null
824 ret=$?
825 if [ $ret -ne 0 ]; then
826 test_done "$testroot" "$ret"
827 return 1
828 fi
830 chmod +x $testroot/wt/alpha
832 echo 'm alpha' > $testroot/stdout.expected
833 (cd $testroot/wt && got status > $testroot/stdout)
835 cmp -s $testroot/stdout.expected $testroot/stdout
836 ret=$?
837 if [ $ret -ne 0 ]; then
838 diff -u $testroot/stdout.expected $testroot/stdout
839 test_done "$testroot" "$ret"
840 return 1
841 fi
843 (cd $testroot/wt && got commit -mx > $testroot/stdout)
844 ret=$?
845 if [ $ret -ne 0 ]; then
846 echo "got commit failed unexpectedly"
847 test_done "$testroot" "$ret"
848 return 1
849 fi
851 local commit_id=`git_show_head $testroot/repo`
852 echo 'm alpha' > $testroot/stdout.expected
853 echo "Created commit $commit_id" >> $testroot/stdout.expected
854 cmp -s $testroot/stdout.expected $testroot/stdout
855 ret=$?
856 if [ $ret -ne 0 ]; then
857 diff -u $testroot/stdout.expected $testroot/stdout
858 test_done "$testroot" "$ret"
859 return 1
860 fi
862 (cd $testroot/wt && got status > $testroot/stdout)
864 echo -n > $testroot/stdout.expected
865 cmp -s $testroot/stdout.expected $testroot/stdout
866 ret=$?
867 if [ $ret -ne 0 ]; then
868 diff -u $testroot/stdout.expected $testroot/stdout
869 test_done "$testroot" "$ret"
870 return 1
871 fi
873 chmod -x $testroot/wt/alpha
875 echo 'm alpha' > $testroot/stdout.expected
876 (cd $testroot/wt && got status > $testroot/stdout)
878 cmp -s $testroot/stdout.expected $testroot/stdout
879 ret=$?
880 if [ $ret -ne 0 ]; then
881 diff -u $testroot/stdout.expected $testroot/stdout
882 test_done "$testroot" "$ret"
883 return 1
884 fi
886 (cd $testroot/wt && got commit -mx > $testroot/stdout)
887 ret=$?
888 if [ $ret -ne 0 ]; then
889 echo "got commit failed unexpectedly"
890 test_done "$testroot" "$ret"
891 return 1
892 fi
894 local commit_id=`git_show_head $testroot/repo`
895 echo 'm alpha' > $testroot/stdout.expected
896 echo "Created commit $commit_id" >> $testroot/stdout.expected
897 cmp -s $testroot/stdout.expected $testroot/stdout
898 ret=$?
899 if [ $ret -ne 0 ]; then
900 diff -u $testroot/stdout.expected $testroot/stdout
901 test_done "$testroot" "$ret"
902 return 1
903 fi
905 chmod +x $testroot/wt/alpha
907 echo 'm alpha' > $testroot/stdout.expected
908 (cd $testroot/wt && got status > $testroot/stdout)
910 cmp -s $testroot/stdout.expected $testroot/stdout
911 ret=$?
912 if [ $ret -ne 0 ]; then
913 diff -u $testroot/stdout.expected $testroot/stdout
914 fi
915 test_done "$testroot" "$ret"
918 commit_check_mode() {
919 local mode="$1"
920 local expected_mode="$2"
922 chmod 644 $testroot/wt/alpha
923 echo a >> $testroot/wt/alpha
924 chmod $mode $testroot/wt/alpha
926 (cd $testroot/wt && got commit -mm > $testroot/stdout)
927 ret=$?
928 if [ $ret -ne 0 ]; then
929 echo "got commit failed unexpectedly"
930 test_done "$testroot" "$ret"
931 return 1
932 fi
934 local commit_id=`git_show_head $testroot/repo`
935 echo 'M alpha' > $testroot/stdout.expected
936 echo "Created commit $commit_id" >> $testroot/stdout.expected
937 cmp -s $testroot/stdout.expected $testroot/stdout
938 ret=$?
939 if [ $ret -ne 0 ]; then
940 diff -u $testroot/stdout.expected $testroot/stdout
941 test_done "$testroot" "$ret"
942 return 1
943 fi
945 local tree_id=$(got cat -r $testroot/repo $commit_id | \
946 grep ^tree | cut -d' ' -f2)
947 local alpha_id=$(got cat -r $testroot/repo $tree_id | \
948 grep 'alpha$' | cut -d' ' -f1)
949 echo "$alpha_id $expected_mode alpha" > $testroot/stdout.expected
950 got cat -r $testroot/repo $tree_id | grep 'alpha$' > $testroot/stdout
951 cmp -s $testroot/stdout.expected $testroot/stdout
952 ret=$?
953 if [ $ret -ne 0 ]; then
954 diff -u $testroot/stdout.expected $testroot/stdout
955 fi
956 return $ret
959 test_commit_normalizes_filemodes() {
960 local testroot=`test_init commit_normalizes_filemodes`
962 got checkout $testroot/repo $testroot/wt > /dev/null
963 ret=$?
964 if [ $ret -ne 0 ]; then
965 test_done "$testroot" "$ret"
966 return 1
967 fi
969 modes="600 400 460 640 440 660 444 666"
970 for m in $modes; do
971 commit_check_mode "$m" "0100644"
972 ret=$?
973 if [ $ret -ne 0 ]; then
974 break
975 fi
976 done
977 if [ $ret -ne 0 ]; then
978 test_done "$testroot" "$ret"
979 return 1
980 fi
981 modes="700 500 570 750 550 770 555 777"
982 for m in $modes; do
983 commit_check_mode "$m" "0100755"
984 ret=$?
985 if [ $ret -ne 0 ]; then
986 break
987 fi
988 done
989 if [ $ret -ne 0 ]; then
990 test_done "$testroot" "$ret"
991 return 1
992 fi
993 test_done "$testroot" "$ret"
996 test_commit_with_unrelated_submodule() {
997 local testroot=`test_init commit_with_unrelated_submodule`
999 make_single_file_repo $testroot/repo2 foo
1001 (cd $testroot/repo && git submodule -q add ../repo2)
1002 (cd $testroot/repo && git commit -q -m 'adding submodule')
1004 got checkout $testroot/repo $testroot/wt > /dev/null
1005 ret=$?
1006 if [ $ret -ne 0 ]; then
1007 echo "checkout failed unexpectedly" >&2
1008 test_done "$testroot" "$ret"
1009 return 1
1012 echo "modified alpha" > $testroot/wt/alpha
1014 echo "" > $testroot/stdout.expected
1016 (cd $testroot/wt && got commit -m 'modify alpha' > $testroot/stdout)
1017 ret=$?
1018 if [ $ret -ne 0 ]; then
1019 echo "commit failed unexpectedly" >&2
1020 test_done "$testroot" "$ret"
1021 return 1
1024 local head_rev=`git_show_head $testroot/repo`
1025 echo "M alpha" > $testroot/stdout.expected
1026 echo "Created commit $head_rev" >> $testroot/stdout.expected
1028 cmp -s $testroot/stdout.expected $testroot/stdout
1029 ret=$?
1030 if [ $ret -ne 0 ]; then
1031 diff -u $testroot/stdout.expected $testroot/stdout
1033 test_done "$testroot" "$ret"
1036 check_symlinks() {
1037 local wtpath="$1"
1038 if ! [ -h $wtpath/alpha.link ]; then
1039 echo "alpha.link is not a symlink"
1040 return 1
1043 readlink $wtpath/alpha.link > $testroot/stdout
1044 echo "alpha" > $testroot/stdout.expected
1045 cmp -s $testroot/stdout.expected $testroot/stdout
1046 ret=$?
1047 if [ $ret -ne 0 ]; then
1048 diff -u $testroot/stdout.expected $testroot/stdout
1049 return 1
1052 if ! [ -h $wtpath/epsilon.link ]; then
1053 echo "epsilon.link is not a symlink"
1054 return 1
1057 readlink $wtpath/epsilon.link > $testroot/stdout
1058 echo "epsilon" > $testroot/stdout.expected
1059 cmp -s $testroot/stdout.expected $testroot/stdout
1060 ret=$?
1061 if [ $ret -ne 0 ]; then
1062 diff -u $testroot/stdout.expected $testroot/stdout
1063 return 1
1066 if [ -h $wtpath/passwd.link ]; then
1067 echo -n "passwd.link is a symlink and points outside of work tree: " >&2
1068 readlink $wtpath/passwd.link >&2
1069 return 1
1072 echo -n "/etc/passwd" > $testroot/content.expected
1073 cp $wtpath/passwd.link $testroot/content
1074 ret=$?
1075 if [ $ret -ne 0 ]; then
1076 echo "cp command failed unexpectedly" >&2
1077 return 1
1080 cmp -s $testroot/content.expected $testroot/content
1081 ret=$?
1082 if [ $ret -ne 0 ]; then
1083 diff -u $testroot/content.expected $testroot/content
1084 return 1
1087 readlink $wtpath/epsilon/beta.link > $testroot/stdout
1088 echo "../beta" > $testroot/stdout.expected
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 return 1
1096 readlink $wtpath/nonexistent.link > $testroot/stdout
1097 echo "nonexistent" > $testroot/stdout.expected
1098 cmp -s $testroot/stdout.expected $testroot/stdout
1099 ret=$?
1100 if [ $ret -ne 0 ]; then
1101 diff -u $testroot/stdout.expected $testroot/stdout
1102 return 1
1105 return 0
1108 test_commit_symlink() {
1109 local testroot=`test_init commit_symlink`
1111 got checkout $testroot/repo $testroot/wt > /dev/null
1112 ret=$?
1113 if [ $ret -ne 0 ]; then
1114 test_done "$testroot" "$ret"
1115 return 1
1118 (cd $testroot/wt && ln -s alpha alpha.link)
1119 (cd $testroot/wt && ln -s epsilon epsilon.link)
1120 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1121 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
1122 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
1123 (cd $testroot/wt && got add alpha.link epsilon.link passwd.link \
1124 epsilon/beta.link nonexistent.link > /dev/null)
1126 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1127 > $testroot/stdout 2> $testroot/stderr)
1128 ret=$?
1129 if [ $ret -eq 0 ]; then
1130 echo "got commit succeeded unexpectedly" >&2
1131 test_done "$testroot" "$ret"
1132 return 1
1134 echo -n "got: $testroot/wt/passwd.link: " > $testroot/stderr.expected
1135 echo "symbolic link points outside of paths under version control" \
1136 >> $testroot/stderr.expected
1137 cmp -s $testroot/stderr.expected $testroot/stderr
1138 ret=$?
1139 if [ $ret -ne 0 ]; then
1140 diff -u $testroot/stderr.expected $testroot/stderr
1141 test_done "$testroot" "$ret"
1142 return 1
1145 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1146 > $testroot/stdout)
1148 local head_rev=`git_show_head $testroot/repo`
1149 echo "A alpha.link" > $testroot/stdout.expected
1150 echo "A epsilon.link" >> $testroot/stdout.expected
1151 echo "A nonexistent.link" >> $testroot/stdout.expected
1152 echo "A passwd.link" >> $testroot/stdout.expected
1153 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1154 echo "Created commit $head_rev" >> $testroot/stdout.expected
1156 cmp -s $testroot/stdout.expected $testroot/stdout
1157 ret=$?
1158 if [ $ret -ne 0 ]; then
1159 diff -u $testroot/stdout.expected $testroot/stdout
1160 test_done "$testroot" "$ret"
1161 return 1
1164 # verify created in-repository tree
1165 got checkout $testroot/repo $testroot/wt2 > /dev/null
1166 ret=$?
1167 if [ $ret -ne 0 ]; then
1168 test_done "$testroot" "$ret"
1169 return 1
1171 check_symlinks $testroot/wt2
1172 ret=$?
1173 if [ $ret -ne 0 ]; then
1174 test_done "$testroot" "$ret"
1175 return 1
1178 if ! [ -h $testroot/wt/passwd.link ]; then
1179 echo 'passwd.link is not a symlink' >&2
1180 test_done "$testroot" 1
1181 return 1
1184 # 'got update' should reinstall passwd.link as a regular file
1185 (cd $testroot/wt && got update > /dev/null)
1186 check_symlinks $testroot/wt
1187 ret=$?
1188 if [ $ret -ne 0 ]; then
1189 test_done "$testroot" "$ret"
1190 return 1
1193 (cd $testroot/wt && ln -sf beta alpha.link)
1194 (cd $testroot/wt && ln -sfh gamma epsilon.link)
1195 rm $testroot/wt/epsilon/beta.link
1196 echo "this is a regular file" > $testroot/wt/epsilon/beta.link
1197 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
1198 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
1199 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
1200 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
1201 (cd $testroot/wt && ln -sf alpha new.link)
1202 (cd $testroot/wt && got add new.link > /dev/null)
1204 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1205 > $testroot/stdout 2> $testroot/stderr)
1206 ret=$?
1207 if [ $ret -eq 0 ]; then
1208 echo "got commit succeeded unexpectedly" >&2
1209 test_done "$testroot" "$ret"
1210 return 1
1212 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
1213 echo "symbolic link points outside of paths under version control" \
1214 >> $testroot/stderr.expected
1215 cmp -s $testroot/stderr.expected $testroot/stderr
1216 ret=$?
1217 if [ $ret -ne 0 ]; then
1218 diff -u $testroot/stderr.expected $testroot/stderr
1219 test_done "$testroot" "$ret"
1220 return 1
1223 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1224 > $testroot/stdout)
1226 local head_rev=`git_show_head $testroot/repo`
1227 echo "A dotgotbar.link" > $testroot/stdout.expected
1228 echo "A new.link" >> $testroot/stdout.expected
1229 echo "M alpha.link" >> $testroot/stdout.expected
1230 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1231 echo "M epsilon.link" >> $testroot/stdout.expected
1232 echo "D nonexistent.link" >> $testroot/stdout.expected
1233 echo "Created commit $head_rev" >> $testroot/stdout.expected
1235 cmp -s $testroot/stdout.expected $testroot/stdout
1236 ret=$?
1237 if [ $ret -ne 0 ]; then
1238 diff -u $testroot/stdout.expected $testroot/stdout
1239 test_done "$testroot" "$ret"
1240 return 1
1243 got tree -r $testroot/repo -c $head_rev -R > $testroot/stdout
1244 cat > $testroot/stdout.expected <<EOF
1245 alpha
1246 alpha.link@ -> beta
1247 beta
1248 dotgotbar.link@ -> .got/bar
1249 epsilon/
1250 epsilon/beta.link
1251 epsilon/zeta
1252 epsilon.link@ -> gamma
1253 gamma/
1254 gamma/delta
1255 new.link@ -> alpha
1256 passwd.link@ -> /etc/passwd
1257 EOF
1258 cmp -s $testroot/stdout.expected $testroot/stdout
1259 ret=$?
1260 if [ $ret -ne 0 ]; then
1261 diff -u $testroot/stdout.expected $testroot/stdout
1263 test_done "$testroot" "$ret"
1266 test_commit_fix_bad_symlink() {
1267 local testroot=`test_init commit_fix_bad_symlink`
1269 got checkout $testroot/repo $testroot/wt > /dev/null
1270 ret=$?
1271 if [ $ret -ne 0 ]; then
1272 echo "got checkout failed unexpectedly" >&2
1273 test_done "$testroot" "$ret"
1274 return 1
1277 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1278 (cd $testroot/wt && got add passwd.link > /dev/null)
1280 (cd $testroot/wt && got commit -S -m 'commit bad symlink' \
1281 > $testroot/stdout)
1283 if ! [ -h $testroot/wt/passwd.link ]; then
1284 echo 'passwd.link is not a symlink' >&2
1285 test_done "$testroot" 1
1286 return 1
1288 (cd $testroot/wt && got update >/dev/null)
1289 if [ -h $testroot/wt/passwd.link ]; then
1290 echo "passwd.link is a symlink but should be a regular file" >&2
1291 test_done "$testroot" "1"
1292 return 1
1295 # create another work tree which will contain the "bad" symlink
1296 got checkout $testroot/repo $testroot/wt2 > /dev/null
1297 ret=$?
1298 if [ $ret -ne 0 ]; then
1299 echo "got checkout failed unexpectedly" >&2
1300 test_done "$testroot" "$ret"
1301 return 1
1304 # change "bad" symlink back into a "good" symlink
1305 (cd $testroot/wt && ln -sfh alpha passwd.link)
1307 (cd $testroot/wt && got commit -m 'fix bad symlink' \
1308 > $testroot/stdout)
1310 local head_rev=`git_show_head $testroot/repo`
1311 echo "M passwd.link" > $testroot/stdout.expected
1312 echo "Created commit $head_rev" >> $testroot/stdout.expected
1314 cmp -s $testroot/stdout.expected $testroot/stdout
1315 ret=$?
1316 if [ $ret -ne 0 ]; then
1317 diff -u $testroot/stdout.expected $testroot/stdout
1318 test_done "$testroot" "$ret"
1319 return 1
1322 if ! [ -h $testroot/wt/passwd.link ]; then
1323 echo 'passwd.link is not a symlink' >&2
1324 test_done "$testroot" 1
1325 return 1
1328 readlink $testroot/wt/passwd.link > $testroot/stdout
1329 echo "alpha" > $testroot/stdout.expected
1330 cmp -s $testroot/stdout.expected $testroot/stdout
1331 ret=$?
1332 if [ $ret -ne 0 ]; then
1333 diff -u $testroot/stdout.expected $testroot/stdout
1334 return 1
1337 # Update the other work tree; the bad symlink should be fixed
1338 (cd $testroot/wt2 && got update > /dev/null)
1339 ret=$?
1340 if [ $ret -ne 0 ]; then
1341 echo "got checkout failed unexpectedly" >&2
1342 test_done "$testroot" "$ret"
1343 return 1
1346 if ! [ -h $testroot/wt2/passwd.link ]; then
1347 echo 'passwd.link is not a symlink' >&2
1348 test_done "$testroot" 1
1349 return 1
1352 readlink $testroot/wt2/passwd.link > $testroot/stdout
1353 echo "alpha" > $testroot/stdout.expected
1354 cmp -s $testroot/stdout.expected $testroot/stdout
1355 ret=$?
1356 if [ $ret -ne 0 ]; then
1357 diff -u $testroot/stdout.expected $testroot/stdout
1358 return 1
1361 test_done "$testroot" "0"
1364 test_commit_prepared_logmsg() {
1365 local testroot=`test_init commit_prepared_logmsg`
1367 got checkout $testroot/repo $testroot/wt > /dev/null
1368 ret=$?
1369 if [ $ret -ne 0 ]; then
1370 test_done "$testroot" "$ret"
1371 return 1
1374 echo "modified alpha" > $testroot/wt/alpha
1375 (cd $testroot/wt && got rm beta >/dev/null)
1376 echo "new file" > $testroot/wt/new
1377 (cd $testroot/wt && got add new >/dev/null)
1379 echo 'test commit_prepared_logmsg' > $testroot/logmsg
1381 cat > $testroot/editor.sh <<EOF
1382 #!/bin/sh
1383 sed -i 's/foo/bar/' "\$1"
1384 EOF
1385 chmod +x $testroot/editor.sh
1387 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
1388 got commit -F "$testroot/logmsg" > $testroot/stdout)
1390 local head_rev=`git_show_head $testroot/repo`
1391 echo "A new" > $testroot/stdout.expected
1392 echo "M alpha" >> $testroot/stdout.expected
1393 echo "D beta" >> $testroot/stdout.expected
1394 echo "Created commit $head_rev" >> $testroot/stdout.expected
1396 cmp -s $testroot/stdout.expected $testroot/stdout
1397 ret=$?
1398 if [ $ret -ne 0 ]; then
1399 diff -u $testroot/stdout.expected $testroot/stdout
1400 test_done "$testroot" "$ret"
1401 return 1
1404 local author_time=`git_show_author_time $testroot/repo`
1405 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
1406 echo "-----------------------------------------------" > $testroot/stdout.expected
1407 echo "commit $head_rev (master)" >> $testroot/stdout.expected
1408 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
1409 echo "date: $d" >> $testroot/stdout.expected
1410 echo " " >> $testroot/stdout.expected
1411 echo " test commit_prepared_logmsg" >> $testroot/stdout.expected
1412 echo " " >> $testroot/stdout.expected
1414 (cd $testroot/wt && got log -l 1 > $testroot/stdout)
1415 cmp -s $testroot/stdout.expected $testroot/stdout
1416 ret=$?
1417 if [ $ret -ne 0 ]; then
1418 diff -u $testroot/stdout.expected $testroot/stdout
1419 test_done "$testroot" "$ret"
1420 return 1
1423 echo "modified alpha again" > $testroot/wt/alpha
1425 echo 'test commit_prepared_logmsg non-interactive' \
1426 > $testroot/logmsg
1428 (cd $testroot/wt && got commit -N -F "$testroot/logmsg" \
1429 > $testroot/stdout)
1431 local head_rev=`git_show_head $testroot/repo`
1432 echo "M alpha" > $testroot/stdout.expected
1433 echo "Created commit $head_rev" >> $testroot/stdout.expected
1435 cmp -s $testroot/stdout.expected $testroot/stdout
1436 ret=$?
1437 if [ $ret -ne 0 ]; then
1438 diff -u $testroot/stdout.expected $testroot/stdout
1439 test_done "$testroot" "$ret"
1440 return 1
1443 local author_time=`git_show_author_time $testroot/repo`
1444 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
1445 echo "-----------------------------------------------" \
1446 > $testroot/stdout.expected
1447 echo "commit $head_rev (master)" >> $testroot/stdout.expected
1448 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
1449 echo "date: $d" >> $testroot/stdout.expected
1450 echo " " >> $testroot/stdout.expected
1451 echo " test commit_prepared_logmsg non-interactive" \
1452 >> $testroot/stdout.expected
1453 echo " " >> $testroot/stdout.expected
1455 (cd $testroot/wt && got log -l 1 > $testroot/stdout)
1456 cmp -s $testroot/stdout.expected $testroot/stdout
1457 ret=$?
1458 if [ $ret -ne 0 ]; then
1459 diff -u $testroot/stdout.expected $testroot/stdout
1461 test_done "$testroot" "$ret"
1464 test_commit_large_file() {
1465 local testroot=`test_init commit_large_file`
1467 got checkout $testroot/repo $testroot/wt > /dev/null
1468 ret=$?
1469 if [ $ret -ne 0 ]; then
1470 test_done "$testroot" "$ret"
1471 return 1
1474 dd status=none if=/dev/zero of=$testroot/wt/new bs=1M count=64
1475 (cd $testroot/wt && got add new >/dev/null)
1477 (cd $testroot/wt && got commit -m 'test commit_large_file' \
1478 > $testroot/stdout)
1480 local head_rev=`git_show_head $testroot/repo`
1481 echo "A new" > $testroot/stdout.expected
1482 echo "Created commit $head_rev" >> $testroot/stdout.expected
1484 cmp -s $testroot/stdout.expected $testroot/stdout
1485 ret=$?
1486 if [ $ret -ne 0 ]; then
1487 diff -u $testroot/stdout.expected $testroot/stdout
1488 test_done "$testroot" "$ret"
1489 return 1
1492 new_id=`get_blob_id $testroot/repo "" new`
1493 got cat -r $testroot/repo $new_id > $testroot/new
1494 ret=$?
1495 if [ $ret -ne 0 ]; then
1496 echo "commit failed unexpectedly" >&2
1497 test_done "$testroot" "1"
1498 return 1
1501 cmp -s $testroot/new $testroot/wt/new
1502 ret=$?
1503 if [ $ret -ne 0 ]; then
1504 diff -u $testroot/new $testroot/wt/new
1506 test_done "$testroot" "$ret"
1512 test_parseargs "$@"
1513 run_test test_commit_basic
1514 run_test test_commit_new_subdir
1515 run_test test_commit_subdir
1516 run_test test_commit_single_file
1517 run_test test_commit_out_of_date
1518 run_test test_commit_added_subdirs
1519 run_test test_commit_deleted_subdirs
1520 run_test test_commit_rejects_conflicted_file
1521 run_test test_commit_single_file_multiple
1522 run_test test_commit_added_and_modified_in_same_dir
1523 run_test test_commit_path_prefix
1524 run_test test_commit_dir_path
1525 run_test test_commit_selected_paths
1526 run_test test_commit_outside_refs_heads
1527 run_test test_commit_no_email
1528 run_test test_commit_tree_entry_sorting
1529 run_test test_commit_gotconfig_author
1530 run_test test_commit_gotconfig_worktree_author
1531 run_test test_commit_gitconfig_author
1532 run_test test_commit_xbit_change
1533 run_test test_commit_normalizes_filemodes
1534 run_test test_commit_with_unrelated_submodule
1535 run_test test_commit_symlink
1536 run_test test_commit_fix_bad_symlink
1537 run_test test_commit_prepared_logmsg
1538 run_test test_commit_large_file