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`
643 local errmsg=""
645 errmsg="commit author's email address is required for"
646 errmsg="$errmsg compatibility with Git"
648 got checkout $testroot/repo $testroot/wt > /dev/null
649 ret=$?
650 if [ $ret -ne 0 ]; then
651 test_done "$testroot" "$ret"
652 return 1
653 fi
655 echo "modified alpha" > $testroot/wt/alpha
656 (cd $testroot/wt && env GOT_AUTHOR=":flan_hacker:" \
657 got commit -m 'test no email' > $testroot/stdout \
658 2> $testroot/stderr)
660 printf "got: :flan_hacker:: %s\n" "$errmsg" > $testroot/stderr.expected
661 cmp -s $testroot/stderr.expected $testroot/stderr
662 ret=$?
663 if [ $ret -ne 0 ]; then
664 diff -u $testroot/stderr.expected $testroot/stderr
665 test_done "$testroot" "$ret"
666 return 1
667 fi
669 echo -n > $testroot/stdout.expected
670 cmp -s $testroot/stdout.expected $testroot/stdout
671 ret=$?
672 if [ $ret -ne 0 ]; then
673 diff -u $testroot/stdout.expected $testroot/stdout
674 test_done "$testroot" $ret
675 return 1
676 fi
678 # try again with a newline inside the email
679 (cd $testroot/wt \
680 && FS=' ' env GOT_AUTHOR="$(printf "Flan <hack\ner>")" \
681 got commit -m 'test invalid email' > $testroot/stdout \
682 2> $testroot/stderr)
684 printf "got: Flan <hack\ner>: %s\n" "$errmsg" \
685 > $testroot/stderr.expected
686 cmp -s $testroot/stderr.expected $testroot/stderr
687 ret=$?
688 if [ $ret -ne 0 ]; then
689 diff -u $testroot/stderr.expected $testroot/stderr
690 test_done "$testroot" $ret
691 return 1
692 fi
694 echo -n > $testroot/stdout.expected
695 cmp -s $testroot/stdout.expected $testroot/stdout
696 ret=$?
697 if [ $ret -ne 0 ]; then
698 diff -u $testroot/stdout.expected $testroot/stdout
699 test_done "$testroot" $ret
700 return 1
701 fi
703 # try again with a < inside the email
704 (cd $testroot/wt && env GOT_AUTHOR="$(printf "Flan <ha<ker>")" \
705 got commit -m 'test invalid email' > $testroot/stdout \
706 2> $testroot/stderr)
708 printf "got: Flan <ha<ker>: %s\n" "$errmsg" > $testroot/stderr.expected
709 cmp -s $testroot/stderr.expected $testroot/stderr
710 ret=$?
711 if [ $ret -ne 0 ]; then
712 diff -u $testroot/stderr.expected $testroot/stderr
713 test_done "$testroot" $ret
714 return 1
715 fi
717 echo -n > $testroot/stdout.expected
718 cmp -s $testroot/stdout.expected $testroot/stdout
719 ret=$?
720 if [ $ret -ne 0 ]; then
721 diff -u $testroot/stdout.expected $testroot/stdout
722 fi
723 test_done "$testroot" $ret
726 test_commit_tree_entry_sorting() {
727 local testroot=`test_init commit_tree_entry_sorting`
729 got checkout $testroot/repo $testroot/wt > /dev/null
730 ret=$?
731 if [ $ret -ne 0 ]; then
732 test_done "$testroot" "$ret"
733 return 1
734 fi
736 # Git's index gets corrupted when tree entries are written in the
737 # order defined by got_path_cmp() rather than Git's own ordering.
738 # Create a new tree where a directory "got" and a file "got-version"
739 # would sort in the wrong order according to Git's opinion.
740 mkdir $testroot/wt/got
741 touch $testroot/wt/got/foo
742 echo foo > $testroot/wt/got-version
743 echo zzz > $testroot/wt/zzz
744 (cd $testroot/wt && got add got-version got/foo zzz > /dev/null)
746 (cd $testroot/wt && got commit -m 'test' > /dev/null)
748 # Let git-fsck verify the newly written tree to make sure Git is happy
749 (cd $testroot/repo && git fsck --strict \
750 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
751 ret=$?
752 test_done "$testroot" "$ret"
755 test_commit_cmdline_author() {
756 local testroot=`test_init commit_cmdline_author`
758 got checkout $testroot/repo $testroot/wt > /dev/null
759 ret=$?
760 if [ $ret -ne 0 ]; then
761 test_done "$testroot" $ret
762 return 1
763 fi
765 echo "modified alpha" > $testroot/wt/alpha
767 # first try with a -A equals to $GOT_AUTHOR
768 (cd $testroot/wt && got commit -A "$GOT_AUTHOR" -m 'edit alpha') \
769 > /dev/null 2> $testroot/stderr
770 ret=$?
771 if [ $ret -eq 0 ]; then
772 test_done "$testroot" 1
773 return 1
774 fi
776 echo 'got: specified author is equal to the default one' \
777 > $testroot/stderr.expected
778 cmp -s $testroot/stderr.expected $testroot/stderr
779 ret=$?
780 if [ $ret -ne 0 ]; then
781 diff -u $testroot/stderr.expected $testroot/stderr
782 test_done "$testroot" $ret
783 return 1
784 fi
786 # try again with a different author
787 local author="Foo <foo@example.com>"
788 (cd $testroot/wt && got commit -A "$author" -m 'edit alpha') \
789 > /dev/null
790 ret=$?
791 if [ $ret -ne 0 ]; then
792 test_done "$testroot" $ret
793 return 1
794 fi
796 (cd $testroot/repo && got log -l1 | egrep '^(from|via):') \
797 > $testroot/stdout
798 ret=$?
799 if [ $ret -ne 0 ]; then
800 test_done "$testroot" $ret
801 return 1
802 fi
804 echo "from: $author" > $testroot/stdout.expected
805 echo "via: $GOT_AUTHOR" >> $testroot/stdout.expected
806 cmp -s $testroot/stdout.expected $testroot/stdout
807 ret=$?
808 if [ $ret -ne 0 ]; then
809 diff -u $testroot/stdout.expected $testroot/stdout
810 fi
811 test_done "$testroot" $ret
814 test_commit_gotconfig_author() {
815 local testroot=`test_init commit_gotconfig_author`
817 got checkout $testroot/repo $testroot/wt > /dev/null
818 ret=$?
819 if [ $ret -ne 0 ]; then
820 test_done "$testroot" "$ret"
821 return 1
822 fi
823 echo 'author "Flan Luck <flan_luck@openbsd.org>"' \
824 > $testroot/repo/.git/got.conf
826 echo "modified alpha" > $testroot/wt/alpha
827 (cd $testroot/wt && got commit -m 'test gotconfig author' > /dev/null)
828 ret=$?
829 if [ $ret -ne 0 ]; then
830 test_done "$testroot" "$ret"
831 return 1
832 fi
834 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
835 ret=$?
836 if [ $ret -ne 0 ]; then
837 test_done "$testroot" "$ret"
838 return 1
839 fi
841 echo "from: Flan Luck <flan_luck@openbsd.org>" \
842 > $testroot/stdout.expected
843 cmp -s $testroot/stdout.expected $testroot/stdout
844 ret=$?
845 if [ $ret -ne 0 ]; then
846 diff -u $testroot/stdout.expected $testroot/stdout
847 fi
848 test_done "$testroot" "$ret"
851 test_commit_gotconfig_worktree_author() {
852 local testroot=`test_init commit_gotconfig_worktree_author`
854 got checkout $testroot/repo $testroot/wt > /dev/null
855 ret=$?
856 if [ $ret -ne 0 ]; then
857 test_done "$testroot" "$ret"
858 return 1
859 fi
860 echo 'author "Flan Luck <flan_luck@openbsd.org>"' \
861 > $testroot/repo/.git/got.conf
862 echo 'author "Flan Squee <flan_squee@openbsd.org>"' \
863 > $testroot/wt/.got/got.conf
865 echo "modified alpha" > $testroot/wt/alpha
866 (cd $testroot/wt && got commit -m 'test gotconfig author' > /dev/null)
867 ret=$?
868 if [ $ret -ne 0 ]; then
869 test_done "$testroot" "$ret"
870 return 1
871 fi
873 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
874 ret=$?
875 if [ $ret -ne 0 ]; then
876 test_done "$testroot" "$ret"
877 return 1
878 fi
880 echo "from: Flan Squee <flan_squee@openbsd.org>" \
881 > $testroot/stdout.expected
882 cmp -s $testroot/stdout.expected $testroot/stdout
883 ret=$?
884 if [ $ret -ne 0 ]; then
885 diff -u $testroot/stdout.expected $testroot/stdout
886 fi
887 test_done "$testroot" "$ret"
890 test_commit_gitconfig_author() {
891 local testroot=`test_init commit_gitconfig_author`
893 got checkout $testroot/repo $testroot/wt > /dev/null
894 ret=$?
895 if [ $ret -ne 0 ]; then
896 test_done "$testroot" "$ret"
897 return 1
898 fi
900 (cd $testroot/repo && git config user.name 'Flan Luck')
901 (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
903 echo "modified alpha" > $testroot/wt/alpha
904 (cd $testroot/wt && got commit -m 'test gitconfig author' > /dev/null)
905 ret=$?
906 if [ $ret -ne 0 ]; then
907 test_done "$testroot" "$ret"
908 return 1
909 fi
911 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
912 ret=$?
913 if [ $ret -ne 0 ]; then
914 test_done "$testroot" "$ret"
915 return 1
916 fi
918 echo "from: Flan Luck <flan_luck@openbsd.org>" \
919 > $testroot/stdout.expected
920 cmp -s $testroot/stdout.expected $testroot/stdout
921 ret=$?
922 if [ $ret -ne 0 ]; then
923 diff -u $testroot/stdout.expected $testroot/stdout
924 fi
925 test_done "$testroot" "$ret"
928 test_commit_xbit_change() {
929 local testroot=`test_init commit_xbit_change`
931 got checkout $testroot/repo $testroot/wt > /dev/null
932 ret=$?
933 if [ $ret -ne 0 ]; then
934 test_done "$testroot" "$ret"
935 return 1
936 fi
938 chmod +x $testroot/wt/alpha
940 echo 'm alpha' > $testroot/stdout.expected
941 (cd $testroot/wt && got status > $testroot/stdout)
943 cmp -s $testroot/stdout.expected $testroot/stdout
944 ret=$?
945 if [ $ret -ne 0 ]; then
946 diff -u $testroot/stdout.expected $testroot/stdout
947 test_done "$testroot" "$ret"
948 return 1
949 fi
951 (cd $testroot/wt && got commit -mx > $testroot/stdout)
952 ret=$?
953 if [ $ret -ne 0 ]; then
954 echo "got commit failed unexpectedly"
955 test_done "$testroot" "$ret"
956 return 1
957 fi
959 local commit_id=`git_show_head $testroot/repo`
960 echo 'm alpha' > $testroot/stdout.expected
961 echo "Created commit $commit_id" >> $testroot/stdout.expected
962 cmp -s $testroot/stdout.expected $testroot/stdout
963 ret=$?
964 if [ $ret -ne 0 ]; then
965 diff -u $testroot/stdout.expected $testroot/stdout
966 test_done "$testroot" "$ret"
967 return 1
968 fi
970 (cd $testroot/wt && got status > $testroot/stdout)
972 echo -n > $testroot/stdout.expected
973 cmp -s $testroot/stdout.expected $testroot/stdout
974 ret=$?
975 if [ $ret -ne 0 ]; then
976 diff -u $testroot/stdout.expected $testroot/stdout
977 test_done "$testroot" "$ret"
978 return 1
979 fi
981 chmod -x $testroot/wt/alpha
983 echo 'm alpha' > $testroot/stdout.expected
984 (cd $testroot/wt && got status > $testroot/stdout)
986 cmp -s $testroot/stdout.expected $testroot/stdout
987 ret=$?
988 if [ $ret -ne 0 ]; then
989 diff -u $testroot/stdout.expected $testroot/stdout
990 test_done "$testroot" "$ret"
991 return 1
992 fi
994 (cd $testroot/wt && got commit -mx > $testroot/stdout)
995 ret=$?
996 if [ $ret -ne 0 ]; then
997 echo "got commit failed unexpectedly"
998 test_done "$testroot" "$ret"
999 return 1
1002 local commit_id=`git_show_head $testroot/repo`
1003 echo 'm alpha' > $testroot/stdout.expected
1004 echo "Created commit $commit_id" >> $testroot/stdout.expected
1005 cmp -s $testroot/stdout.expected $testroot/stdout
1006 ret=$?
1007 if [ $ret -ne 0 ]; then
1008 diff -u $testroot/stdout.expected $testroot/stdout
1009 test_done "$testroot" "$ret"
1010 return 1
1013 chmod +x $testroot/wt/alpha
1015 echo 'm alpha' > $testroot/stdout.expected
1016 (cd $testroot/wt && got status > $testroot/stdout)
1018 cmp -s $testroot/stdout.expected $testroot/stdout
1019 ret=$?
1020 if [ $ret -ne 0 ]; then
1021 diff -u $testroot/stdout.expected $testroot/stdout
1023 test_done "$testroot" "$ret"
1026 commit_check_mode() {
1027 local mode="$1"
1028 local expected_mode="$2"
1030 chmod 644 $testroot/wt/alpha
1031 echo a >> $testroot/wt/alpha
1032 chmod $mode $testroot/wt/alpha
1034 (cd $testroot/wt && got commit -mm > $testroot/stdout)
1035 ret=$?
1036 if [ $ret -ne 0 ]; then
1037 echo "got commit failed unexpectedly"
1038 test_done "$testroot" "$ret"
1039 return 1
1042 local commit_id=`git_show_head $testroot/repo`
1043 echo 'M alpha' > $testroot/stdout.expected
1044 echo "Created commit $commit_id" >> $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 test_done "$testroot" "$ret"
1050 return 1
1053 local tree_id=$(got cat -r $testroot/repo $commit_id | \
1054 grep ^tree | cut -d' ' -f2)
1055 local alpha_id=$(got cat -r $testroot/repo $tree_id | \
1056 grep 'alpha$' | cut -d' ' -f1)
1057 echo "$alpha_id $expected_mode alpha" > $testroot/stdout.expected
1058 got cat -r $testroot/repo $tree_id | grep 'alpha$' > $testroot/stdout
1059 cmp -s $testroot/stdout.expected $testroot/stdout
1060 ret=$?
1061 if [ $ret -ne 0 ]; then
1062 diff -u $testroot/stdout.expected $testroot/stdout
1064 return $ret
1067 test_commit_normalizes_filemodes() {
1068 local testroot=`test_init commit_normalizes_filemodes`
1070 got checkout $testroot/repo $testroot/wt > /dev/null
1071 ret=$?
1072 if [ $ret -ne 0 ]; then
1073 test_done "$testroot" "$ret"
1074 return 1
1077 modes="600 400 460 640 440 660 444 666"
1078 for m in $modes; do
1079 commit_check_mode "$m" "0100644"
1080 ret=$?
1081 if [ $ret -ne 0 ]; then
1082 break
1084 done
1085 if [ $ret -ne 0 ]; then
1086 test_done "$testroot" "$ret"
1087 return 1
1089 modes="700 500 570 750 550 770 555 777"
1090 for m in $modes; do
1091 commit_check_mode "$m" "0100755"
1092 ret=$?
1093 if [ $ret -ne 0 ]; then
1094 break
1096 done
1097 if [ $ret -ne 0 ]; then
1098 test_done "$testroot" "$ret"
1099 return 1
1101 test_done "$testroot" "$ret"
1104 test_commit_with_unrelated_submodule() {
1105 local testroot=`test_init commit_with_unrelated_submodule`
1107 make_single_file_repo $testroot/repo2 foo
1109 (cd $testroot/repo && git submodule -q add ../repo2)
1110 (cd $testroot/repo && git commit -q -m 'adding submodule')
1112 got checkout $testroot/repo $testroot/wt > /dev/null
1113 ret=$?
1114 if [ $ret -ne 0 ]; then
1115 echo "checkout failed unexpectedly" >&2
1116 test_done "$testroot" "$ret"
1117 return 1
1120 echo "modified alpha" > $testroot/wt/alpha
1122 echo "" > $testroot/stdout.expected
1124 (cd $testroot/wt && got commit -m 'modify alpha' > $testroot/stdout)
1125 ret=$?
1126 if [ $ret -ne 0 ]; then
1127 echo "commit failed unexpectedly" >&2
1128 test_done "$testroot" "$ret"
1129 return 1
1132 local head_rev=`git_show_head $testroot/repo`
1133 echo "M alpha" > $testroot/stdout.expected
1134 echo "Created commit $head_rev" >> $testroot/stdout.expected
1136 cmp -s $testroot/stdout.expected $testroot/stdout
1137 ret=$?
1138 if [ $ret -ne 0 ]; then
1139 diff -u $testroot/stdout.expected $testroot/stdout
1141 test_done "$testroot" "$ret"
1144 check_symlinks() {
1145 local wtpath="$1"
1146 if ! [ -h $wtpath/alpha.link ]; then
1147 echo "alpha.link is not a symlink"
1148 return 1
1151 readlink $wtpath/alpha.link > $testroot/stdout
1152 echo "alpha" > $testroot/stdout.expected
1153 cmp -s $testroot/stdout.expected $testroot/stdout
1154 ret=$?
1155 if [ $ret -ne 0 ]; then
1156 diff -u $testroot/stdout.expected $testroot/stdout
1157 return 1
1160 if ! [ -h $wtpath/epsilon.link ]; then
1161 echo "epsilon.link is not a symlink"
1162 return 1
1165 readlink $wtpath/epsilon.link > $testroot/stdout
1166 echo "epsilon" > $testroot/stdout.expected
1167 cmp -s $testroot/stdout.expected $testroot/stdout
1168 ret=$?
1169 if [ $ret -ne 0 ]; then
1170 diff -u $testroot/stdout.expected $testroot/stdout
1171 return 1
1174 if [ -h $wtpath/passwd.link ]; then
1175 echo -n "passwd.link is a symlink and points outside of work tree: " >&2
1176 readlink $wtpath/passwd.link >&2
1177 return 1
1180 echo -n "/etc/passwd" > $testroot/content.expected
1181 cp $wtpath/passwd.link $testroot/content
1182 ret=$?
1183 if [ $ret -ne 0 ]; then
1184 echo "cp command failed unexpectedly" >&2
1185 return 1
1188 cmp -s $testroot/content.expected $testroot/content
1189 ret=$?
1190 if [ $ret -ne 0 ]; then
1191 diff -u $testroot/content.expected $testroot/content
1192 return 1
1195 readlink $wtpath/epsilon/beta.link > $testroot/stdout
1196 echo "../beta" > $testroot/stdout.expected
1197 cmp -s $testroot/stdout.expected $testroot/stdout
1198 ret=$?
1199 if [ $ret -ne 0 ]; then
1200 diff -u $testroot/stdout.expected $testroot/stdout
1201 return 1
1204 readlink $wtpath/nonexistent.link > $testroot/stdout
1205 echo "nonexistent" > $testroot/stdout.expected
1206 cmp -s $testroot/stdout.expected $testroot/stdout
1207 ret=$?
1208 if [ $ret -ne 0 ]; then
1209 diff -u $testroot/stdout.expected $testroot/stdout
1210 return 1
1213 return 0
1216 test_commit_symlink() {
1217 local testroot=`test_init commit_symlink`
1219 got checkout $testroot/repo $testroot/wt > /dev/null
1220 ret=$?
1221 if [ $ret -ne 0 ]; then
1222 test_done "$testroot" "$ret"
1223 return 1
1226 (cd $testroot/wt && ln -s alpha alpha.link)
1227 (cd $testroot/wt && ln -s epsilon epsilon.link)
1228 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1229 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
1230 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
1231 (cd $testroot/wt && got add alpha.link epsilon.link passwd.link \
1232 epsilon/beta.link nonexistent.link > /dev/null)
1234 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1235 > $testroot/stdout 2> $testroot/stderr)
1236 ret=$?
1237 if [ $ret -eq 0 ]; then
1238 echo "got commit succeeded unexpectedly" >&2
1239 test_done "$testroot" "$ret"
1240 return 1
1242 echo -n "got: $testroot/wt/passwd.link: " > $testroot/stderr.expected
1243 echo "symbolic link points outside of paths under version control" \
1244 >> $testroot/stderr.expected
1245 cmp -s $testroot/stderr.expected $testroot/stderr
1246 ret=$?
1247 if [ $ret -ne 0 ]; then
1248 diff -u $testroot/stderr.expected $testroot/stderr
1249 test_done "$testroot" "$ret"
1250 return 1
1253 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1254 > $testroot/stdout)
1256 local head_rev=`git_show_head $testroot/repo`
1257 echo "A alpha.link" > $testroot/stdout.expected
1258 echo "A epsilon.link" >> $testroot/stdout.expected
1259 echo "A nonexistent.link" >> $testroot/stdout.expected
1260 echo "A passwd.link" >> $testroot/stdout.expected
1261 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1262 echo "Created commit $head_rev" >> $testroot/stdout.expected
1264 cmp -s $testroot/stdout.expected $testroot/stdout
1265 ret=$?
1266 if [ $ret -ne 0 ]; then
1267 diff -u $testroot/stdout.expected $testroot/stdout
1268 test_done "$testroot" "$ret"
1269 return 1
1272 # verify created in-repository tree
1273 got checkout $testroot/repo $testroot/wt2 > /dev/null
1274 ret=$?
1275 if [ $ret -ne 0 ]; then
1276 test_done "$testroot" "$ret"
1277 return 1
1279 check_symlinks $testroot/wt2
1280 ret=$?
1281 if [ $ret -ne 0 ]; then
1282 test_done "$testroot" "$ret"
1283 return 1
1286 if ! [ -h $testroot/wt/passwd.link ]; then
1287 echo 'passwd.link is not a symlink' >&2
1288 test_done "$testroot" 1
1289 return 1
1292 # 'got update' should reinstall passwd.link as a regular file
1293 (cd $testroot/wt && got update > /dev/null)
1294 check_symlinks $testroot/wt
1295 ret=$?
1296 if [ $ret -ne 0 ]; then
1297 test_done "$testroot" "$ret"
1298 return 1
1301 (cd $testroot/wt && ln -sf beta alpha.link)
1302 (cd $testroot/wt && ln -sfT gamma epsilon.link)
1303 rm $testroot/wt/epsilon/beta.link
1304 echo "this is a regular file" > $testroot/wt/epsilon/beta.link
1305 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
1306 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
1307 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
1308 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
1309 (cd $testroot/wt && ln -sf alpha new.link)
1310 (cd $testroot/wt && got add new.link > /dev/null)
1312 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1313 > $testroot/stdout 2> $testroot/stderr)
1314 ret=$?
1315 if [ $ret -eq 0 ]; then
1316 echo "got commit succeeded unexpectedly" >&2
1317 test_done "$testroot" "$ret"
1318 return 1
1320 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
1321 echo "symbolic link points outside of paths under version control" \
1322 >> $testroot/stderr.expected
1323 cmp -s $testroot/stderr.expected $testroot/stderr
1324 ret=$?
1325 if [ $ret -ne 0 ]; then
1326 diff -u $testroot/stderr.expected $testroot/stderr
1327 test_done "$testroot" "$ret"
1328 return 1
1331 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1332 > $testroot/stdout)
1334 local head_rev=`git_show_head $testroot/repo`
1335 echo "A dotgotbar.link" > $testroot/stdout.expected
1336 echo "A new.link" >> $testroot/stdout.expected
1337 echo "M alpha.link" >> $testroot/stdout.expected
1338 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1339 echo "M epsilon.link" >> $testroot/stdout.expected
1340 echo "D nonexistent.link" >> $testroot/stdout.expected
1341 echo "Created commit $head_rev" >> $testroot/stdout.expected
1343 cmp -s $testroot/stdout.expected $testroot/stdout
1344 ret=$?
1345 if [ $ret -ne 0 ]; then
1346 diff -u $testroot/stdout.expected $testroot/stdout
1347 test_done "$testroot" "$ret"
1348 return 1
1351 got tree -r $testroot/repo -c $head_rev -R > $testroot/stdout
1352 cat > $testroot/stdout.expected <<EOF
1353 alpha
1354 alpha.link@ -> beta
1355 beta
1356 dotgotbar.link@ -> .got/bar
1357 epsilon/
1358 epsilon/beta.link
1359 epsilon/zeta
1360 epsilon.link@ -> gamma
1361 gamma/
1362 gamma/delta
1363 new.link@ -> alpha
1364 passwd.link@ -> /etc/passwd
1365 EOF
1366 cmp -s $testroot/stdout.expected $testroot/stdout
1367 ret=$?
1368 if [ $ret -ne 0 ]; then
1369 diff -u $testroot/stdout.expected $testroot/stdout
1371 test_done "$testroot" "$ret"
1374 test_commit_fix_bad_symlink() {
1375 local testroot=`test_init commit_fix_bad_symlink`
1377 got checkout $testroot/repo $testroot/wt > /dev/null
1378 ret=$?
1379 if [ $ret -ne 0 ]; then
1380 echo "got checkout failed unexpectedly" >&2
1381 test_done "$testroot" "$ret"
1382 return 1
1385 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1386 (cd $testroot/wt && got add passwd.link > /dev/null)
1388 (cd $testroot/wt && got commit -S -m 'commit bad symlink' \
1389 > $testroot/stdout)
1391 if ! [ -h $testroot/wt/passwd.link ]; then
1392 echo 'passwd.link is not a symlink' >&2
1393 test_done "$testroot" 1
1394 return 1
1396 (cd $testroot/wt && got update >/dev/null)
1397 if [ -h $testroot/wt/passwd.link ]; then
1398 echo "passwd.link is a symlink but should be a regular file" >&2
1399 test_done "$testroot" "1"
1400 return 1
1403 # create another work tree which will contain the "bad" symlink
1404 got checkout $testroot/repo $testroot/wt2 > /dev/null
1405 ret=$?
1406 if [ $ret -ne 0 ]; then
1407 echo "got checkout failed unexpectedly" >&2
1408 test_done "$testroot" "$ret"
1409 return 1
1412 # change "bad" symlink back into a "good" symlink
1413 (cd $testroot/wt && ln -sfT alpha passwd.link)
1415 (cd $testroot/wt && got commit -m 'fix bad symlink' \
1416 > $testroot/stdout)
1418 local head_rev=`git_show_head $testroot/repo`
1419 echo "M passwd.link" > $testroot/stdout.expected
1420 echo "Created commit $head_rev" >> $testroot/stdout.expected
1422 cmp -s $testroot/stdout.expected $testroot/stdout
1423 ret=$?
1424 if [ $ret -ne 0 ]; then
1425 diff -u $testroot/stdout.expected $testroot/stdout
1426 test_done "$testroot" "$ret"
1427 return 1
1430 if ! [ -h $testroot/wt/passwd.link ]; then
1431 echo 'passwd.link is not a symlink' >&2
1432 test_done "$testroot" 1
1433 return 1
1436 readlink $testroot/wt/passwd.link > $testroot/stdout
1437 echo "alpha" > $testroot/stdout.expected
1438 cmp -s $testroot/stdout.expected $testroot/stdout
1439 ret=$?
1440 if [ $ret -ne 0 ]; then
1441 diff -u $testroot/stdout.expected $testroot/stdout
1442 return 1
1445 # Update the other work tree; the bad symlink should be fixed
1446 (cd $testroot/wt2 && got update > /dev/null)
1447 ret=$?
1448 if [ $ret -ne 0 ]; then
1449 echo "got checkout failed unexpectedly" >&2
1450 test_done "$testroot" "$ret"
1451 return 1
1454 if ! [ -h $testroot/wt2/passwd.link ]; then
1455 echo 'passwd.link is not a symlink' >&2
1456 test_done "$testroot" 1
1457 return 1
1460 readlink $testroot/wt2/passwd.link > $testroot/stdout
1461 echo "alpha" > $testroot/stdout.expected
1462 cmp -s $testroot/stdout.expected $testroot/stdout
1463 ret=$?
1464 if [ $ret -ne 0 ]; then
1465 diff -u $testroot/stdout.expected $testroot/stdout
1466 return 1
1469 test_done "$testroot" "0"
1472 test_commit_prepared_logmsg() {
1473 local testroot=`test_init commit_prepared_logmsg`
1475 got checkout $testroot/repo $testroot/wt > /dev/null
1476 ret=$?
1477 if [ $ret -ne 0 ]; then
1478 test_done "$testroot" "$ret"
1479 return 1
1482 echo "modified alpha" > $testroot/wt/alpha
1483 (cd $testroot/wt && got rm beta >/dev/null)
1484 echo "new file" > $testroot/wt/new
1485 (cd $testroot/wt && got add new >/dev/null)
1487 echo 'test commit_prepared_logmsg' > $testroot/logmsg
1489 cat > $testroot/editor.sh <<EOF
1490 #!/bin/sh
1491 SOPTS='-i ""'
1492 [ "\$OSTYPE" = "linux-gnu" ] && SOPTS="-i"
1493 sed "\$SOPTS" -e 's/foo/bar/' "\$1"
1494 EOF
1495 chmod +x $testroot/editor.sh
1497 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
1498 got commit -F "$testroot/logmsg" > $testroot/stdout)
1500 local head_rev=`git_show_head $testroot/repo`
1501 echo "A new" > $testroot/stdout.expected
1502 echo "M alpha" >> $testroot/stdout.expected
1503 echo "D beta" >> $testroot/stdout.expected
1504 echo "Created commit $head_rev" >> $testroot/stdout.expected
1506 cmp -s $testroot/stdout.expected $testroot/stdout
1507 ret=$?
1508 if [ $ret -ne 0 ]; then
1509 diff -u $testroot/stdout.expected $testroot/stdout
1510 test_done "$testroot" "$ret"
1511 return 1
1514 local author_time=`git_show_author_time $testroot/repo`
1515 local prev_LC_TIME="$LC_TIME"
1516 export LC_TIME=C
1517 d=`date -u -d "@$author_time" +"%a %b %e %X %Y UTC"`
1518 LC_TIME="$prev_LC_TIME"
1519 echo "-----------------------------------------------" > $testroot/stdout.expected
1520 echo "commit $head_rev (master)" >> $testroot/stdout.expected
1521 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
1522 echo "date: $d" >> $testroot/stdout.expected
1523 echo " " >> $testroot/stdout.expected
1524 echo " test commit_prepared_logmsg" >> $testroot/stdout.expected
1525 echo " " >> $testroot/stdout.expected
1527 (cd $testroot/wt && got log -l 1 > $testroot/stdout)
1528 cmp -s $testroot/stdout.expected $testroot/stdout
1529 ret=$?
1530 if [ $ret -ne 0 ]; then
1531 diff -u $testroot/stdout.expected $testroot/stdout
1532 test_done "$testroot" "$ret"
1533 return 1
1536 echo "modified alpha again" > $testroot/wt/alpha
1538 echo 'test commit_prepared_logmsg non-interactive' \
1539 > $testroot/logmsg
1541 (cd $testroot/wt && got commit -N -F "$testroot/logmsg" \
1542 > $testroot/stdout)
1544 local head_rev=`git_show_head $testroot/repo`
1545 echo "M alpha" > $testroot/stdout.expected
1546 echo "Created commit $head_rev" >> $testroot/stdout.expected
1548 cmp -s $testroot/stdout.expected $testroot/stdout
1549 ret=$?
1550 if [ $ret -ne 0 ]; then
1551 diff -u $testroot/stdout.expected $testroot/stdout
1552 test_done "$testroot" "$ret"
1553 return 1
1556 local author_time=`git_show_author_time $testroot/repo`
1557 local prev_LC_TIME="$LC_TIME"
1558 export LC_TIME=C
1559 d=`date -u -d "@$author_time" +"%a %b %e %X %Y UTC"`
1560 LC_TIME="$prev_LC_TIME"
1561 echo "-----------------------------------------------" \
1562 > $testroot/stdout.expected
1563 echo "commit $head_rev (master)" >> $testroot/stdout.expected
1564 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
1565 echo "date: $d" >> $testroot/stdout.expected
1566 echo " " >> $testroot/stdout.expected
1567 echo " test commit_prepared_logmsg non-interactive" \
1568 >> $testroot/stdout.expected
1569 echo " " >> $testroot/stdout.expected
1571 (cd $testroot/wt && got log -l 1 > $testroot/stdout)
1572 cmp -s $testroot/stdout.expected $testroot/stdout
1573 ret=$?
1574 if [ $ret -ne 0 ]; then
1575 diff -u $testroot/stdout.expected $testroot/stdout
1577 test_done "$testroot" "$ret"
1580 test_commit_large_file() {
1581 local testroot=`test_init commit_large_file`
1583 got checkout $testroot/repo $testroot/wt > /dev/null
1584 ret=$?
1585 if [ $ret -ne 0 ]; then
1586 test_done "$testroot" "$ret"
1587 return 1
1590 dd status=none if=/dev/zero of=$testroot/wt/new bs=1M count=64
1591 (cd $testroot/wt && got add new >/dev/null)
1593 (cd $testroot/wt && got commit -m 'test commit_large_file' \
1594 > $testroot/stdout)
1596 local head_rev=`git_show_head $testroot/repo`
1597 echo "A new" > $testroot/stdout.expected
1598 echo "Created commit $head_rev" >> $testroot/stdout.expected
1600 cmp -s $testroot/stdout.expected $testroot/stdout
1601 ret=$?
1602 if [ $ret -ne 0 ]; then
1603 diff -u $testroot/stdout.expected $testroot/stdout
1604 test_done "$testroot" "$ret"
1605 return 1
1608 new_id=`get_blob_id $testroot/repo "" new`
1609 got cat -r $testroot/repo $new_id > $testroot/new
1610 ret=$?
1611 if [ $ret -ne 0 ]; then
1612 echo "commit failed unexpectedly" >&2
1613 test_done "$testroot" "1"
1614 return 1
1617 cmp -s $testroot/new $testroot/wt/new
1618 ret=$?
1619 if [ $ret -ne 0 ]; then
1620 diff -u $testroot/new $testroot/wt/new
1622 test_done "$testroot" "$ret"
1628 test_parseargs "$@"
1629 run_test test_commit_basic
1630 run_test test_commit_new_subdir
1631 run_test test_commit_subdir
1632 run_test test_commit_single_file
1633 run_test test_commit_out_of_date
1634 run_test test_commit_added_subdirs
1635 run_test test_commit_deleted_subdirs
1636 run_test test_commit_rejects_conflicted_file
1637 run_test test_commit_single_file_multiple
1638 run_test test_commit_added_and_modified_in_same_dir
1639 run_test test_commit_path_prefix
1640 run_test test_commit_dir_path
1641 run_test test_commit_selected_paths
1642 run_test test_commit_outside_refs_heads
1643 run_test test_commit_no_email
1644 run_test test_commit_tree_entry_sorting
1645 run_test test_commit_cmdline_author
1646 run_test test_commit_gotconfig_author
1647 run_test test_commit_gotconfig_worktree_author
1648 run_test test_commit_gitconfig_author
1649 run_test test_commit_xbit_change
1650 run_test test_commit_normalizes_filemodes
1651 run_test test_commit_with_unrelated_submodule
1652 run_test test_commit_symlink
1653 run_test test_commit_fix_bad_symlink
1654 run_test test_commit_prepared_logmsg
1655 run_test test_commit_large_file