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
905 # unset in a subshell to avoid affecting our environment
906 (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
907 got commit -m 'test gitconfig author' > /dev/null)
908 ret=$?
909 if [ $ret -ne 0 ]; then
910 test_done "$testroot" "$ret"
911 return 1
912 fi
914 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
915 ret=$?
916 if [ $ret -ne 0 ]; then
917 test_done "$testroot" "$ret"
918 return 1
919 fi
921 echo "from: Flan Luck <flan_luck@openbsd.org>" \
922 > $testroot/stdout.expected
923 cmp -s $testroot/stdout.expected $testroot/stdout
924 ret=$?
925 if [ $ret -ne 0 ]; then
926 diff -u $testroot/stdout.expected $testroot/stdout
927 fi
928 test_done "$testroot" "$ret"
931 test_commit_xbit_change() {
932 local testroot=`test_init commit_xbit_change`
934 got checkout $testroot/repo $testroot/wt > /dev/null
935 ret=$?
936 if [ $ret -ne 0 ]; then
937 test_done "$testroot" "$ret"
938 return 1
939 fi
941 chmod +x $testroot/wt/alpha
943 echo 'm alpha' > $testroot/stdout.expected
944 (cd $testroot/wt && got status > $testroot/stdout)
946 cmp -s $testroot/stdout.expected $testroot/stdout
947 ret=$?
948 if [ $ret -ne 0 ]; then
949 diff -u $testroot/stdout.expected $testroot/stdout
950 test_done "$testroot" "$ret"
951 return 1
952 fi
954 (cd $testroot/wt && got commit -mx > $testroot/stdout)
955 ret=$?
956 if [ $ret -ne 0 ]; then
957 echo "got commit failed unexpectedly"
958 test_done "$testroot" "$ret"
959 return 1
960 fi
962 local commit_id=`git_show_head $testroot/repo`
963 echo 'm alpha' > $testroot/stdout.expected
964 echo "Created commit $commit_id" >> $testroot/stdout.expected
965 cmp -s $testroot/stdout.expected $testroot/stdout
966 ret=$?
967 if [ $ret -ne 0 ]; then
968 diff -u $testroot/stdout.expected $testroot/stdout
969 test_done "$testroot" "$ret"
970 return 1
971 fi
973 (cd $testroot/wt && got status > $testroot/stdout)
975 echo -n > $testroot/stdout.expected
976 cmp -s $testroot/stdout.expected $testroot/stdout
977 ret=$?
978 if [ $ret -ne 0 ]; then
979 diff -u $testroot/stdout.expected $testroot/stdout
980 test_done "$testroot" "$ret"
981 return 1
982 fi
984 chmod -x $testroot/wt/alpha
986 echo 'm alpha' > $testroot/stdout.expected
987 (cd $testroot/wt && got status > $testroot/stdout)
989 cmp -s $testroot/stdout.expected $testroot/stdout
990 ret=$?
991 if [ $ret -ne 0 ]; then
992 diff -u $testroot/stdout.expected $testroot/stdout
993 test_done "$testroot" "$ret"
994 return 1
995 fi
997 (cd $testroot/wt && got commit -mx > $testroot/stdout)
998 ret=$?
999 if [ $ret -ne 0 ]; then
1000 echo "got commit failed unexpectedly"
1001 test_done "$testroot" "$ret"
1002 return 1
1005 local commit_id=`git_show_head $testroot/repo`
1006 echo 'm alpha' > $testroot/stdout.expected
1007 echo "Created commit $commit_id" >> $testroot/stdout.expected
1008 cmp -s $testroot/stdout.expected $testroot/stdout
1009 ret=$?
1010 if [ $ret -ne 0 ]; then
1011 diff -u $testroot/stdout.expected $testroot/stdout
1012 test_done "$testroot" "$ret"
1013 return 1
1016 chmod +x $testroot/wt/alpha
1018 echo 'm alpha' > $testroot/stdout.expected
1019 (cd $testroot/wt && got status > $testroot/stdout)
1021 cmp -s $testroot/stdout.expected $testroot/stdout
1022 ret=$?
1023 if [ $ret -ne 0 ]; then
1024 diff -u $testroot/stdout.expected $testroot/stdout
1026 test_done "$testroot" "$ret"
1029 commit_check_mode() {
1030 local mode="$1"
1031 local expected_mode="$2"
1033 chmod 644 $testroot/wt/alpha
1034 echo a >> $testroot/wt/alpha
1035 chmod $mode $testroot/wt/alpha
1037 (cd $testroot/wt && got commit -mm > $testroot/stdout)
1038 ret=$?
1039 if [ $ret -ne 0 ]; then
1040 echo "got commit failed unexpectedly"
1041 test_done "$testroot" "$ret"
1042 return 1
1045 local commit_id=`git_show_head $testroot/repo`
1046 echo 'M alpha' > $testroot/stdout.expected
1047 echo "Created commit $commit_id" >> $testroot/stdout.expected
1048 cmp -s $testroot/stdout.expected $testroot/stdout
1049 ret=$?
1050 if [ $ret -ne 0 ]; then
1051 diff -u $testroot/stdout.expected $testroot/stdout
1052 test_done "$testroot" "$ret"
1053 return 1
1056 local tree_id=$(got cat -r $testroot/repo $commit_id | \
1057 grep ^tree | cut -d' ' -f2)
1058 local alpha_id=$(got cat -r $testroot/repo $tree_id | \
1059 grep 'alpha$' | cut -d' ' -f1)
1060 echo "$alpha_id $expected_mode alpha" > $testroot/stdout.expected
1061 got cat -r $testroot/repo $tree_id | grep 'alpha$' > $testroot/stdout
1062 cmp -s $testroot/stdout.expected $testroot/stdout
1063 ret=$?
1064 if [ $ret -ne 0 ]; then
1065 diff -u $testroot/stdout.expected $testroot/stdout
1067 return $ret
1070 test_commit_normalizes_filemodes() {
1071 local testroot=`test_init commit_normalizes_filemodes`
1073 got checkout $testroot/repo $testroot/wt > /dev/null
1074 ret=$?
1075 if [ $ret -ne 0 ]; then
1076 test_done "$testroot" "$ret"
1077 return 1
1080 modes="600 400 460 640 440 660 444 666"
1081 for m in $modes; do
1082 commit_check_mode "$m" "0100644"
1083 ret=$?
1084 if [ $ret -ne 0 ]; then
1085 break
1087 done
1088 if [ $ret -ne 0 ]; then
1089 test_done "$testroot" "$ret"
1090 return 1
1092 modes="700 500 570 750 550 770 555 777"
1093 for m in $modes; do
1094 commit_check_mode "$m" "0100755"
1095 ret=$?
1096 if [ $ret -ne 0 ]; then
1097 break
1099 done
1100 if [ $ret -ne 0 ]; then
1101 test_done "$testroot" "$ret"
1102 return 1
1104 test_done "$testroot" "$ret"
1107 test_commit_with_unrelated_submodule() {
1108 local testroot=`test_init commit_with_unrelated_submodule`
1110 make_single_file_repo $testroot/repo2 foo
1112 (cd $testroot/repo && git submodule -q add ../repo2)
1113 (cd $testroot/repo && git commit -q -m 'adding submodule')
1115 got checkout $testroot/repo $testroot/wt > /dev/null
1116 ret=$?
1117 if [ $ret -ne 0 ]; then
1118 echo "checkout failed unexpectedly" >&2
1119 test_done "$testroot" "$ret"
1120 return 1
1123 echo "modified alpha" > $testroot/wt/alpha
1125 echo "" > $testroot/stdout.expected
1127 (cd $testroot/wt && got commit -m 'modify alpha' > $testroot/stdout)
1128 ret=$?
1129 if [ $ret -ne 0 ]; then
1130 echo "commit failed unexpectedly" >&2
1131 test_done "$testroot" "$ret"
1132 return 1
1135 local head_rev=`git_show_head $testroot/repo`
1136 echo "M alpha" > $testroot/stdout.expected
1137 echo "Created commit $head_rev" >> $testroot/stdout.expected
1139 cmp -s $testroot/stdout.expected $testroot/stdout
1140 ret=$?
1141 if [ $ret -ne 0 ]; then
1142 diff -u $testroot/stdout.expected $testroot/stdout
1144 test_done "$testroot" "$ret"
1147 check_symlinks() {
1148 local wtpath="$1"
1149 if ! [ -h $wtpath/alpha.link ]; then
1150 echo "alpha.link is not a symlink"
1151 return 1
1154 readlink $wtpath/alpha.link > $testroot/stdout
1155 echo "alpha" > $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 return 1
1163 if ! [ -h $wtpath/epsilon.link ]; then
1164 echo "epsilon.link is not a symlink"
1165 return 1
1168 readlink $wtpath/epsilon.link > $testroot/stdout
1169 echo "epsilon" > $testroot/stdout.expected
1170 cmp -s $testroot/stdout.expected $testroot/stdout
1171 ret=$?
1172 if [ $ret -ne 0 ]; then
1173 diff -u $testroot/stdout.expected $testroot/stdout
1174 return 1
1177 if [ -h $wtpath/passwd.link ]; then
1178 echo -n "passwd.link is a symlink and points outside of work tree: " >&2
1179 readlink $wtpath/passwd.link >&2
1180 return 1
1183 echo -n "/etc/passwd" > $testroot/content.expected
1184 cp $wtpath/passwd.link $testroot/content
1185 ret=$?
1186 if [ $ret -ne 0 ]; then
1187 echo "cp command failed unexpectedly" >&2
1188 return 1
1191 cmp -s $testroot/content.expected $testroot/content
1192 ret=$?
1193 if [ $ret -ne 0 ]; then
1194 diff -u $testroot/content.expected $testroot/content
1195 return 1
1198 readlink $wtpath/epsilon/beta.link > $testroot/stdout
1199 echo "../beta" > $testroot/stdout.expected
1200 cmp -s $testroot/stdout.expected $testroot/stdout
1201 ret=$?
1202 if [ $ret -ne 0 ]; then
1203 diff -u $testroot/stdout.expected $testroot/stdout
1204 return 1
1207 readlink $wtpath/nonexistent.link > $testroot/stdout
1208 echo "nonexistent" > $testroot/stdout.expected
1209 cmp -s $testroot/stdout.expected $testroot/stdout
1210 ret=$?
1211 if [ $ret -ne 0 ]; then
1212 diff -u $testroot/stdout.expected $testroot/stdout
1213 return 1
1216 return 0
1219 test_commit_symlink() {
1220 local testroot=`test_init commit_symlink`
1222 got checkout $testroot/repo $testroot/wt > /dev/null
1223 ret=$?
1224 if [ $ret -ne 0 ]; then
1225 test_done "$testroot" "$ret"
1226 return 1
1229 (cd $testroot/wt && ln -s alpha alpha.link)
1230 (cd $testroot/wt && ln -s epsilon epsilon.link)
1231 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1232 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
1233 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
1234 (cd $testroot/wt && got add alpha.link epsilon.link passwd.link \
1235 epsilon/beta.link nonexistent.link > /dev/null)
1237 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1238 > $testroot/stdout 2> $testroot/stderr)
1239 ret=$?
1240 if [ $ret -eq 0 ]; then
1241 echo "got commit succeeded unexpectedly" >&2
1242 test_done "$testroot" "$ret"
1243 return 1
1245 echo -n "got: $testroot/wt/passwd.link: " > $testroot/stderr.expected
1246 echo "symbolic link points outside of paths under version control" \
1247 >> $testroot/stderr.expected
1248 cmp -s $testroot/stderr.expected $testroot/stderr
1249 ret=$?
1250 if [ $ret -ne 0 ]; then
1251 diff -u $testroot/stderr.expected $testroot/stderr
1252 test_done "$testroot" "$ret"
1253 return 1
1256 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1257 > $testroot/stdout)
1259 local head_rev=`git_show_head $testroot/repo`
1260 echo "A alpha.link" > $testroot/stdout.expected
1261 echo "A epsilon.link" >> $testroot/stdout.expected
1262 echo "A nonexistent.link" >> $testroot/stdout.expected
1263 echo "A passwd.link" >> $testroot/stdout.expected
1264 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1265 echo "Created commit $head_rev" >> $testroot/stdout.expected
1267 cmp -s $testroot/stdout.expected $testroot/stdout
1268 ret=$?
1269 if [ $ret -ne 0 ]; then
1270 diff -u $testroot/stdout.expected $testroot/stdout
1271 test_done "$testroot" "$ret"
1272 return 1
1275 # verify created in-repository tree
1276 got checkout $testroot/repo $testroot/wt2 > /dev/null
1277 ret=$?
1278 if [ $ret -ne 0 ]; then
1279 test_done "$testroot" "$ret"
1280 return 1
1282 check_symlinks $testroot/wt2
1283 ret=$?
1284 if [ $ret -ne 0 ]; then
1285 test_done "$testroot" "$ret"
1286 return 1
1289 if ! [ -h $testroot/wt/passwd.link ]; then
1290 echo 'passwd.link is not a symlink' >&2
1291 test_done "$testroot" 1
1292 return 1
1295 # 'got update' should reinstall passwd.link as a regular file
1296 (cd $testroot/wt && got update > /dev/null)
1297 check_symlinks $testroot/wt
1298 ret=$?
1299 if [ $ret -ne 0 ]; then
1300 test_done "$testroot" "$ret"
1301 return 1
1304 (cd $testroot/wt && ln -sf beta alpha.link)
1305 (cd $testroot/wt && ln -sfh gamma epsilon.link)
1306 rm $testroot/wt/epsilon/beta.link
1307 echo "this is a regular file" > $testroot/wt/epsilon/beta.link
1308 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
1309 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
1310 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
1311 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
1312 (cd $testroot/wt && ln -sf alpha new.link)
1313 (cd $testroot/wt && got add new.link > /dev/null)
1315 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1316 > $testroot/stdout 2> $testroot/stderr)
1317 ret=$?
1318 if [ $ret -eq 0 ]; then
1319 echo "got commit succeeded unexpectedly" >&2
1320 test_done "$testroot" "$ret"
1321 return 1
1323 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
1324 echo "symbolic link points outside of paths under version control" \
1325 >> $testroot/stderr.expected
1326 cmp -s $testroot/stderr.expected $testroot/stderr
1327 ret=$?
1328 if [ $ret -ne 0 ]; then
1329 diff -u $testroot/stderr.expected $testroot/stderr
1330 test_done "$testroot" "$ret"
1331 return 1
1334 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1335 > $testroot/stdout)
1337 local head_rev=`git_show_head $testroot/repo`
1338 echo "A dotgotbar.link" > $testroot/stdout.expected
1339 echo "A new.link" >> $testroot/stdout.expected
1340 echo "M alpha.link" >> $testroot/stdout.expected
1341 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1342 echo "M epsilon.link" >> $testroot/stdout.expected
1343 echo "D nonexistent.link" >> $testroot/stdout.expected
1344 echo "Created commit $head_rev" >> $testroot/stdout.expected
1346 cmp -s $testroot/stdout.expected $testroot/stdout
1347 ret=$?
1348 if [ $ret -ne 0 ]; then
1349 diff -u $testroot/stdout.expected $testroot/stdout
1350 test_done "$testroot" "$ret"
1351 return 1
1354 got tree -r $testroot/repo -c $head_rev -R > $testroot/stdout
1355 cat > $testroot/stdout.expected <<EOF
1356 alpha
1357 alpha.link@ -> beta
1358 beta
1359 dotgotbar.link@ -> .got/bar
1360 epsilon/
1361 epsilon/beta.link
1362 epsilon/zeta
1363 epsilon.link@ -> gamma
1364 gamma/
1365 gamma/delta
1366 new.link@ -> alpha
1367 passwd.link@ -> /etc/passwd
1368 EOF
1369 cmp -s $testroot/stdout.expected $testroot/stdout
1370 ret=$?
1371 if [ $ret -ne 0 ]; then
1372 diff -u $testroot/stdout.expected $testroot/stdout
1374 test_done "$testroot" "$ret"
1377 test_commit_fix_bad_symlink() {
1378 local testroot=`test_init commit_fix_bad_symlink`
1380 got checkout $testroot/repo $testroot/wt > /dev/null
1381 ret=$?
1382 if [ $ret -ne 0 ]; then
1383 echo "got checkout failed unexpectedly" >&2
1384 test_done "$testroot" "$ret"
1385 return 1
1388 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1389 (cd $testroot/wt && got add passwd.link > /dev/null)
1391 (cd $testroot/wt && got commit -S -m 'commit bad symlink' \
1392 > $testroot/stdout)
1394 if ! [ -h $testroot/wt/passwd.link ]; then
1395 echo 'passwd.link is not a symlink' >&2
1396 test_done "$testroot" 1
1397 return 1
1399 (cd $testroot/wt && got update >/dev/null)
1400 if [ -h $testroot/wt/passwd.link ]; then
1401 echo "passwd.link is a symlink but should be a regular file" >&2
1402 test_done "$testroot" "1"
1403 return 1
1406 # create another work tree which will contain the "bad" symlink
1407 got checkout $testroot/repo $testroot/wt2 > /dev/null
1408 ret=$?
1409 if [ $ret -ne 0 ]; then
1410 echo "got checkout failed unexpectedly" >&2
1411 test_done "$testroot" "$ret"
1412 return 1
1415 # change "bad" symlink back into a "good" symlink
1416 (cd $testroot/wt && ln -sfh alpha passwd.link)
1418 (cd $testroot/wt && got commit -m 'fix bad symlink' \
1419 > $testroot/stdout)
1421 local head_rev=`git_show_head $testroot/repo`
1422 echo "M passwd.link" > $testroot/stdout.expected
1423 echo "Created commit $head_rev" >> $testroot/stdout.expected
1425 cmp -s $testroot/stdout.expected $testroot/stdout
1426 ret=$?
1427 if [ $ret -ne 0 ]; then
1428 diff -u $testroot/stdout.expected $testroot/stdout
1429 test_done "$testroot" "$ret"
1430 return 1
1433 if ! [ -h $testroot/wt/passwd.link ]; then
1434 echo 'passwd.link is not a symlink' >&2
1435 test_done "$testroot" 1
1436 return 1
1439 readlink $testroot/wt/passwd.link > $testroot/stdout
1440 echo "alpha" > $testroot/stdout.expected
1441 cmp -s $testroot/stdout.expected $testroot/stdout
1442 ret=$?
1443 if [ $ret -ne 0 ]; then
1444 diff -u $testroot/stdout.expected $testroot/stdout
1445 return 1
1448 # Update the other work tree; the bad symlink should be fixed
1449 (cd $testroot/wt2 && got update > /dev/null)
1450 ret=$?
1451 if [ $ret -ne 0 ]; then
1452 echo "got checkout failed unexpectedly" >&2
1453 test_done "$testroot" "$ret"
1454 return 1
1457 if ! [ -h $testroot/wt2/passwd.link ]; then
1458 echo 'passwd.link is not a symlink' >&2
1459 test_done "$testroot" 1
1460 return 1
1463 readlink $testroot/wt2/passwd.link > $testroot/stdout
1464 echo "alpha" > $testroot/stdout.expected
1465 cmp -s $testroot/stdout.expected $testroot/stdout
1466 ret=$?
1467 if [ $ret -ne 0 ]; then
1468 diff -u $testroot/stdout.expected $testroot/stdout
1469 return 1
1472 test_done "$testroot" "0"
1475 test_commit_prepared_logmsg() {
1476 local testroot=`test_init commit_prepared_logmsg`
1478 got checkout $testroot/repo $testroot/wt > /dev/null
1479 ret=$?
1480 if [ $ret -ne 0 ]; then
1481 test_done "$testroot" "$ret"
1482 return 1
1485 echo "modified alpha" > $testroot/wt/alpha
1486 (cd $testroot/wt && got rm beta >/dev/null)
1487 echo "new file" > $testroot/wt/new
1488 (cd $testroot/wt && got add new >/dev/null)
1490 echo 'test commit_prepared_logmsg' > $testroot/logmsg
1492 cat > $testroot/editor.sh <<EOF
1493 #!/bin/sh
1494 sed -i 's/foo/bar/' "\$1"
1495 EOF
1496 chmod +x $testroot/editor.sh
1498 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
1499 got commit -F "$testroot/logmsg" > $testroot/stdout)
1501 local head_rev=`git_show_head $testroot/repo`
1502 echo "A new" > $testroot/stdout.expected
1503 echo "M alpha" >> $testroot/stdout.expected
1504 echo "D beta" >> $testroot/stdout.expected
1505 echo "Created commit $head_rev" >> $testroot/stdout.expected
1507 cmp -s $testroot/stdout.expected $testroot/stdout
1508 ret=$?
1509 if [ $ret -ne 0 ]; then
1510 diff -u $testroot/stdout.expected $testroot/stdout
1511 test_done "$testroot" "$ret"
1512 return 1
1515 local author_time=`git_show_author_time $testroot/repo`
1516 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
1517 echo "-----------------------------------------------" > $testroot/stdout.expected
1518 echo "commit $head_rev (master)" >> $testroot/stdout.expected
1519 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
1520 echo "date: $d" >> $testroot/stdout.expected
1521 echo " " >> $testroot/stdout.expected
1522 echo " test commit_prepared_logmsg" >> $testroot/stdout.expected
1523 echo " " >> $testroot/stdout.expected
1525 (cd $testroot/wt && got log -l 1 > $testroot/stdout)
1526 cmp -s $testroot/stdout.expected $testroot/stdout
1527 ret=$?
1528 if [ $ret -ne 0 ]; then
1529 diff -u $testroot/stdout.expected $testroot/stdout
1530 test_done "$testroot" "$ret"
1531 return 1
1534 echo "modified alpha again" > $testroot/wt/alpha
1536 echo 'test commit_prepared_logmsg non-interactive' \
1537 > $testroot/logmsg
1539 (cd $testroot/wt && got commit -N -F "$testroot/logmsg" \
1540 > $testroot/stdout)
1542 local head_rev=`git_show_head $testroot/repo`
1543 echo "M alpha" > $testroot/stdout.expected
1544 echo "Created commit $head_rev" >> $testroot/stdout.expected
1546 cmp -s $testroot/stdout.expected $testroot/stdout
1547 ret=$?
1548 if [ $ret -ne 0 ]; then
1549 diff -u $testroot/stdout.expected $testroot/stdout
1550 test_done "$testroot" "$ret"
1551 return 1
1554 local author_time=`git_show_author_time $testroot/repo`
1555 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
1556 echo "-----------------------------------------------" \
1557 > $testroot/stdout.expected
1558 echo "commit $head_rev (master)" >> $testroot/stdout.expected
1559 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
1560 echo "date: $d" >> $testroot/stdout.expected
1561 echo " " >> $testroot/stdout.expected
1562 echo " test commit_prepared_logmsg non-interactive" \
1563 >> $testroot/stdout.expected
1564 echo " " >> $testroot/stdout.expected
1566 (cd $testroot/wt && got log -l 1 > $testroot/stdout)
1567 cmp -s $testroot/stdout.expected $testroot/stdout
1568 ret=$?
1569 if [ $ret -ne 0 ]; then
1570 diff -u $testroot/stdout.expected $testroot/stdout
1572 test_done "$testroot" "$ret"
1575 test_commit_large_file() {
1576 local testroot=`test_init commit_large_file`
1578 got checkout $testroot/repo $testroot/wt > /dev/null
1579 ret=$?
1580 if [ $ret -ne 0 ]; then
1581 test_done "$testroot" "$ret"
1582 return 1
1585 dd status=none if=/dev/zero of=$testroot/wt/new bs=1M count=64
1586 (cd $testroot/wt && got add new >/dev/null)
1588 (cd $testroot/wt && got commit -m 'test commit_large_file' \
1589 > $testroot/stdout)
1591 local head_rev=`git_show_head $testroot/repo`
1592 echo "A new" > $testroot/stdout.expected
1593 echo "Created commit $head_rev" >> $testroot/stdout.expected
1595 cmp -s $testroot/stdout.expected $testroot/stdout
1596 ret=$?
1597 if [ $ret -ne 0 ]; then
1598 diff -u $testroot/stdout.expected $testroot/stdout
1599 test_done "$testroot" "$ret"
1600 return 1
1603 new_id=`get_blob_id $testroot/repo "" new`
1604 got cat -r $testroot/repo $new_id > $testroot/new
1605 ret=$?
1606 if [ $ret -ne 0 ]; then
1607 echo "commit failed unexpectedly" >&2
1608 test_done "$testroot" "1"
1609 return 1
1612 cmp -s $testroot/new $testroot/wt/new
1613 ret=$?
1614 if [ $ret -ne 0 ]; then
1615 diff -u $testroot/new $testroot/wt/new
1617 test_done "$testroot" "$ret"
1622 test_commit_gitignore() {
1623 local testroot=`test_init commit_gitignores`
1625 got checkout $testroot/repo $testroot/wt > /dev/null
1626 ret=$?
1627 if [ $ret -ne 0 ]; then
1628 test_done "$testroot" "$ret"
1629 return 1
1632 mkdir -p $testroot/wt/tree1/foo
1633 mkdir -p $testroot/wt/tree2/foo
1634 echo "tree1/**" > $testroot/wt/.gitignore
1635 echo "tree2/**" >> $testroot/wt/.gitignore
1636 echo -n > $testroot/wt/tree1/bar
1637 echo -n > $testroot/wt/tree1/foo/baz
1638 echo -n > $testroot/wt/tree2/bar
1639 echo -n > $testroot/wt/tree2/foo/baz
1640 echo -n > $testroot/wt/epsilon/zeta1
1641 echo -n > $testroot/wt/epsilon/zeta2
1643 (cd $testroot/wt && got add -I -R tree1 > /dev/null)
1644 (cd $testroot/wt && got add -I tree2/foo/baz > /dev/null)
1645 (cd $testroot/wt && got commit -m "gitignore add" > /dev/null)
1646 (cd $testroot/wt && got log -P -l 1 | egrep '^ .' > $testroot/stdout)
1648 echo ' gitignore add' > $testroot/stdout.expected
1649 echo ' A tree1/bar' >> $testroot/stdout.expected
1650 echo ' A tree1/foo/baz' >> $testroot/stdout.expected
1651 echo ' A tree2/foo/baz' >> $testroot/stdout.expected
1653 cmp -s $testroot/stdout.expected $testroot/stdout
1654 ret=$?
1655 if [ $ret -ne 0 ]; then
1656 diff -u $testroot/stdout.expected $testroot/stdout
1657 test_done "$testroot" "$ret"
1658 return 1
1661 echo touch > $testroot/wt/tree1/bar
1662 echo touch > $testroot/wt/tree1/foo/baz
1663 echo touch > $testroot/wt/epsilon/zeta1
1665 (cd $testroot/wt && got commit -m "gitignore change" > /dev/null)
1666 (cd $testroot/wt && got log -P -l 1 | egrep '^ .' > $testroot/stdout)
1668 echo ' gitignore change' > $testroot/stdout.expected
1669 echo ' M tree1/bar' >> $testroot/stdout.expected
1670 echo ' M tree1/foo/baz' >> $testroot/stdout.expected
1672 cmp -s $testroot/stdout.expected $testroot/stdout
1673 ret=$?
1674 if [ $ret -ne 0 ]; then
1675 diff -u $testroot/stdout.expected $testroot/stdout
1676 test_done "$testroot" "$ret"
1677 return 1
1680 test_done "$testroot" "$ret"
1684 test_parseargs "$@"
1685 run_test test_commit_basic
1686 run_test test_commit_new_subdir
1687 run_test test_commit_subdir
1688 run_test test_commit_single_file
1689 run_test test_commit_out_of_date
1690 run_test test_commit_added_subdirs
1691 run_test test_commit_deleted_subdirs
1692 run_test test_commit_rejects_conflicted_file
1693 run_test test_commit_single_file_multiple
1694 run_test test_commit_added_and_modified_in_same_dir
1695 run_test test_commit_path_prefix
1696 run_test test_commit_dir_path
1697 run_test test_commit_selected_paths
1698 run_test test_commit_outside_refs_heads
1699 run_test test_commit_no_email
1700 run_test test_commit_tree_entry_sorting
1701 run_test test_commit_cmdline_author
1702 run_test test_commit_gotconfig_author
1703 run_test test_commit_gotconfig_worktree_author
1704 run_test test_commit_gitconfig_author
1705 run_test test_commit_xbit_change
1706 run_test test_commit_normalizes_filemodes
1707 run_test test_commit_with_unrelated_submodule
1708 run_test test_commit_symlink
1709 run_test test_commit_fix_bad_symlink
1710 run_test test_commit_prepared_logmsg
1711 run_test test_commit_large_file
1712 run_test test_commit_gitignore