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 function test_commit_basic {
20 local testroot=`test_init commit_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret="$?"
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
29 echo "modified alpha" > $testroot/wt/alpha
30 (cd $testroot/wt && got rm beta >/dev/null)
31 echo "new file" > $testroot/wt/new
32 (cd $testroot/wt && got add new >/dev/null)
34 (cd $testroot/wt && got commit -m 'test commit_basic' > $testroot/stdout)
36 local head_rev=`git_show_head $testroot/repo`
37 echo "A new" > $testroot/stdout.expected
38 echo "M alpha" >> $testroot/stdout.expected
39 echo "D beta" >> $testroot/stdout.expected
40 echo "Created commit $head_rev" >> $testroot/stdout.expected
42 cmp -s $testroot/stdout.expected $testroot/stdout
43 ret="$?"
44 if [ "$ret" != "0" ]; then
45 diff -u $testroot/stdout.expected $testroot/stdout
46 fi
47 test_done "$testroot" "$ret"
48 }
50 function test_commit_new_subdir {
51 local testroot=`test_init commit_new_subdir`
53 got checkout $testroot/repo $testroot/wt > /dev/null
54 ret="$?"
55 if [ "$ret" != "0" ]; then
56 test_done "$testroot" "$ret"
57 return 1
58 fi
60 mkdir -p $testroot/wt/d
61 echo "new file" > $testroot/wt/d/new
62 echo "another new file" > $testroot/wt/d/new2
63 (cd $testroot/wt && got add d/new >/dev/null)
64 (cd $testroot/wt && got add d/new2 >/dev/null)
66 (cd $testroot/wt && \
67 got commit -m 'test commit_new_subdir' > $testroot/stdout)
69 local head_rev=`git_show_head $testroot/repo`
70 echo "A d/new" > $testroot/stdout.expected
71 echo "A d/new2" >> $testroot/stdout.expected
72 echo "Created commit $head_rev" >> $testroot/stdout.expected
74 cmp -s $testroot/stdout.expected $testroot/stdout
75 ret="$?"
76 if [ "$ret" != "0" ]; then
77 diff -u $testroot/stdout.expected $testroot/stdout
78 fi
79 test_done "$testroot" "$ret"
80 }
82 function test_commit_subdir {
83 local testroot=`test_init commit_subdir`
85 got checkout $testroot/repo $testroot/wt > /dev/null
86 ret="$?"
87 if [ "$ret" != "0" ]; then
88 test_done "$testroot" "$ret"
89 return 1
90 fi
92 echo "modified alpha" > $testroot/wt/alpha
93 echo "modified zeta" > $testroot/wt/epsilon/zeta
95 (cd $testroot/wt && \
96 got commit -m 'test commit_subdir' epsilon > $testroot/stdout)
98 local head_rev=`git_show_head $testroot/repo`
99 echo "M epsilon/zeta" >> $testroot/stdout.expected
100 echo "Created commit $head_rev" >> $testroot/stdout.expected
102 cmp -s $testroot/stdout.expected $testroot/stdout
103 ret="$?"
104 if [ "$ret" != "0" ]; then
105 diff -u $testroot/stdout.expected $testroot/stdout
106 fi
107 test_done "$testroot" "$ret"
110 function test_commit_single_file {
111 local testroot=`test_init commit_single_file`
113 got checkout $testroot/repo $testroot/wt > /dev/null
114 ret="$?"
115 if [ "$ret" != "0" ]; then
116 test_done "$testroot" "$ret"
117 return 1
118 fi
120 echo "modified alpha" > $testroot/wt/alpha
121 echo "modified zeta" > $testroot/wt/epsilon/zeta
123 (cd $testroot/wt && got commit -m 'changed zeta' epsilon/zeta \
124 > $testroot/stdout)
126 local head_rev=`git_show_head $testroot/repo`
127 echo "M epsilon/zeta" >> $testroot/stdout.expected
128 echo "Created commit $head_rev" >> $testroot/stdout.expected
130 cmp -s $testroot/stdout.expected $testroot/stdout
131 ret="$?"
132 if [ "$ret" != "0" ]; then
133 diff -u $testroot/stdout.expected $testroot/stdout
134 fi
135 test_done "$testroot" "$ret"
138 function test_commit_out_of_date {
139 local testroot=`test_init commit_out_of_date`
140 local first_commit=`git_show_head $testroot/repo`
142 got checkout $testroot/repo $testroot/wt > /dev/null
143 ret="$?"
144 if [ "$ret" != "0" ]; then
145 test_done "$testroot" "$ret"
146 return 1
147 fi
149 echo "modified alpha" > $testroot/repo/alpha
150 git_commit $testroot/repo -m "modified alpha"
152 echo "modified alpha" > $testroot/wt/alpha
154 (cd $testroot/wt && got commit -m 'test commit_out_of_date' \
155 > $testroot/stdout 2> $testroot/stderr)
157 echo -n > $testroot/stdout.expected
158 echo "got: work tree must be updated before these" \
159 "changes can be committed" > $testroot/stderr.expected
161 cmp -s $testroot/stdout.expected $testroot/stdout
162 ret="$?"
163 if [ "$ret" != "0" ]; then
164 diff -u $testroot/stdout.expected $testroot/stdout
165 test_done "$testroot" "$ret"
166 return 1
167 fi
169 cmp -s $testroot/stderr.expected $testroot/stderr
170 ret="$?"
171 if [ "$ret" != "0" ]; then
172 diff -u $testroot/stderr.expected $testroot/stderr
173 test_done "$testroot" "$ret"
174 return 1
175 fi
177 echo "alpha" > $testroot/repo/alpha
178 git_commit $testroot/repo -m "reset alpha contents"
179 (cd $testroot/wt && got update -c $first_commit > /dev/null)
181 echo "modified alpha" > $testroot/wt/alpha
183 (cd $testroot/wt && got commit -m 'changed alpha ' > $testroot/stdout)
184 ret="$?"
185 if [ "$ret" != "0" ]; then
186 echo "commit failed unexpectedly" >&2
187 test_done "$testroot" "1"
188 return 1
189 fi
191 local head_rev=`git_show_head $testroot/repo`
192 echo "M alpha" > $testroot/stdout.expected
193 echo "Created commit $head_rev" >> $testroot/stdout.expected
194 cmp -s $testroot/stdout.expected $testroot/stdout
195 ret="$?"
196 if [ "$ret" != "0" ]; then
197 diff -u $testroot/stdout.expected $testroot/stdout
198 fi
199 test_done "$testroot" "$ret"
202 function test_commit_added_subdirs {
203 local testroot=`test_init commit_added_subdirs`
205 got checkout $testroot/repo $testroot/wt > /dev/null
206 ret="$?"
207 if [ "$ret" != "0" ]; then
208 test_done "$testroot" "$ret"
209 return 1
210 fi
212 mkdir -p $testroot/wt/d
213 echo "new file" > $testroot/wt/d/new
214 echo "new file 2" > $testroot/wt/d/new2
215 mkdir -p $testroot/wt/d/f
216 echo "new file 3" > $testroot/wt/d/f/new3
217 mkdir -p $testroot/wt/d/f/g
218 echo "new file 4" > $testroot/wt/d/f/g/new4
220 (cd $testroot/wt && got add $testroot/wt/*/new* \
221 $testroot/wt/*/*/new* $testroot/wt/*/*/*/new* > /dev/null)
223 (cd $testroot/wt && got commit -m 'test commit_added_subdirs' \
224 > $testroot/stdout 2> $testroot/stderr)
226 local head_rev=`git_show_head $testroot/repo`
227 echo "A d/f/g/new4" > $testroot/stdout.expected
228 echo "A d/f/new3" >> $testroot/stdout.expected
229 echo "A d/new" >> $testroot/stdout.expected
230 echo "A d/new2" >> $testroot/stdout.expected
231 echo "Created commit $head_rev" >> $testroot/stdout.expected
233 cmp -s $testroot/stdout.expected $testroot/stdout
234 ret="$?"
235 if [ "$ret" != "0" ]; then
236 diff -u $testroot/stdout.expected $testroot/stdout
237 fi
238 test_done "$testroot" "$ret"
241 function test_commit_deleted_subdirs {
242 local testroot=`test_init commit_deleted_subdirs`
244 got checkout $testroot/repo $testroot/wt > /dev/null
245 ret="$?"
246 if [ "$ret" != "0" ]; then
247 test_done "$testroot" "$ret"
248 return 1
249 fi
251 (cd $testroot/wt && got rm -R $testroot/wt/{epsilon,gamma} >/dev/null)
253 (cd $testroot/wt && got commit -m 'test commit_deleted_subdirs' \
254 > $testroot/stdout 2> $testroot/stderr)
256 local head_rev=`git_show_head $testroot/repo`
257 echo "D epsilon/zeta" > $testroot/stdout.expected
258 echo "D gamma/delta" >> $testroot/stdout.expected
259 echo "Created commit $head_rev" >> $testroot/stdout.expected
261 cmp -s $testroot/stdout.expected $testroot/stdout
262 ret="$?"
263 if [ "$ret" != "0" ]; then
264 diff -u $testroot/stdout.expected $testroot/stdout
265 test_done "$testroot" "$ret"
266 return 1
267 fi
269 got tree -r $testroot/repo > $testroot/stdout
271 echo "alpha" > $testroot/stdout.expected
272 echo "beta" >> $testroot/stdout.expected
274 cmp -s $testroot/stdout.expected $testroot/stdout
275 ret="$?"
276 if [ "$ret" != "0" ]; then
277 diff -u $testroot/stdout.expected $testroot/stdout
278 fi
279 test_done "$testroot" "$ret"
282 function test_commit_rejects_conflicted_file {
283 local testroot=`test_init commit_rejects_conflicted_file`
285 local initial_rev=`git_show_head $testroot/repo`
287 got checkout $testroot/repo $testroot/wt > /dev/null
288 ret="$?"
289 if [ "$ret" != "0" ]; then
290 test_done "$testroot" "$ret"
291 return 1
292 fi
294 echo "modified alpha" > $testroot/wt/alpha
295 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
297 (cd $testroot/wt && got update -c $initial_rev > /dev/null)
299 echo "modified alpha, too" > $testroot/wt/alpha
301 echo "C alpha" > $testroot/stdout.expected
302 echo -n "Updated to commit " >> $testroot/stdout.expected
303 git_show_head $testroot/repo >> $testroot/stdout.expected
304 echo >> $testroot/stdout.expected
305 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
307 (cd $testroot/wt && got update > $testroot/stdout)
309 cmp -s $testroot/stdout.expected $testroot/stdout
310 ret="$?"
311 if [ "$ret" != "0" ]; then
312 diff -u $testroot/stdout.expected $testroot/stdout
313 test_done "$testroot" "$ret"
314 return 1
315 fi
317 (cd $testroot/wt && got commit -m 'commit it' > $testroot/stdout \
318 2> $testroot/stderr)
320 echo -n > $testroot/stdout.expected
321 echo "got: cannot commit file in conflicted status" \
322 > $testroot/stderr.expected
324 cmp -s $testroot/stdout.expected $testroot/stdout
325 ret="$?"
326 if [ "$ret" != "0" ]; then
327 diff -u $testroot/stdout.expected $testroot/stdout
328 test_done "$testroot" "$ret"
329 return 1
330 fi
331 cmp -s $testroot/stderr.expected $testroot/stderr
332 ret="$?"
333 if [ "$ret" != "0" ]; then
334 diff -u $testroot/stderr.expected $testroot/stderr
335 fi
336 test_done "$testroot" "$ret"
339 function test_commit_single_file_multiple {
340 local testroot=`test_init commit_single_file_multiple`
342 got checkout $testroot/repo $testroot/wt > /dev/null
343 ret="$?"
344 if [ "$ret" != "0" ]; then
345 test_done "$testroot" "$ret"
346 return 1
347 fi
349 for i in 1 2 3 4; do
350 echo "modified alpha" >> $testroot/wt/alpha
352 (cd $testroot/wt && \
353 got commit -m "changed alpha" > $testroot/stdout)
355 local head_rev=`git_show_head $testroot/repo`
356 echo "M alpha" > $testroot/stdout.expected
357 echo "Created commit $head_rev" >> $testroot/stdout.expected
359 cmp -s $testroot/stdout.expected $testroot/stdout
360 ret="$?"
361 if [ "$ret" != "0" ]; then
362 diff -u $testroot/stdout.expected $testroot/stdout
363 test_done "$testroot" "$ret"
364 return 1
365 fi
366 done
368 test_done "$testroot" "0"
371 function test_commit_added_and_modified_in_same_dir {
372 local testroot=`test_init commit_added_and_modified_in_same_dir`
374 got checkout $testroot/repo $testroot/wt > /dev/null
375 ret="$?"
376 if [ "$ret" != "0" ]; then
377 test_done "$testroot" "$ret"
378 return 1
379 fi
381 echo "modified zeta" > $testroot/wt/epsilon/zeta
382 echo "new file" > $testroot/wt/epsilon/new
383 (cd $testroot/wt && got add epsilon/new >/dev/null)
385 (cd $testroot/wt && got commit \
386 -m 'added and modified in same dir' > $testroot/stdout \
387 2> $testroot/stderr)
389 local head_rev=`git_show_head $testroot/repo`
390 echo "A epsilon/new" > $testroot/stdout.expected
391 echo "M epsilon/zeta" >> $testroot/stdout.expected
392 echo "Created commit $head_rev" >> $testroot/stdout.expected
394 cmp -s $testroot/stdout.expected $testroot/stdout
395 ret="$?"
396 if [ "$ret" != "0" ]; then
397 diff -u $testroot/stdout.expected $testroot/stdout
398 fi
399 test_done "$testroot" "$ret"
402 function test_commit_path_prefix {
403 local testroot=`test_init commit_path_prefix`
404 local commit1=`git_show_head $testroot/repo`
406 got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
407 ret="$?"
408 if [ "$ret" != "0" ]; then
409 test_done "$testroot" "$ret"
410 return 1
411 fi
413 echo "modified delta" > $testroot/wt/delta
415 (cd $testroot/wt && got commit -m 'changed gamma/delta' > $testroot/stdout)
417 local commit2=`git_show_head $testroot/repo`
418 echo "M delta" > $testroot/stdout.expected
419 echo "Created commit $commit2" >> $testroot/stdout.expected
421 cmp -s $testroot/stdout.expected $testroot/stdout
422 ret="$?"
423 if [ "$ret" != "0" ]; then
424 diff -u $testroot/stdout.expected $testroot/stdout
425 test_done "$testroot" "$ret"
426 return 1
427 fi
429 echo "diff $commit1 $commit2" > $testroot/stdout.expected
430 echo -n 'blob - ' >> $testroot/stdout.expected
431 got tree -r $testroot/repo -c $commit1 -i gamma | grep 'delta$' \
432 | cut -d' ' -f 1 >> $testroot/stdout.expected
433 echo -n 'blob + ' >> $testroot/stdout.expected
434 got tree -r $testroot/repo -c $commit2 -i gamma | grep 'delta$' | \
435 cut -d' ' -f 1 >> $testroot/stdout.expected
436 echo '--- gamma/delta' >> $testroot/stdout.expected
437 echo '+++ gamma/delta' >> $testroot/stdout.expected
438 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
439 echo '-delta' >> $testroot/stdout.expected
440 echo '+modified delta' >> $testroot/stdout.expected
442 got diff -r $testroot/repo $commit1 $commit2 > $testroot/stdout
443 cmp -s $testroot/stdout.expected $testroot/stdout
444 ret="$?"
445 if [ "$ret" != "0" ]; then
446 diff -u $testroot/stdout.expected $testroot/stdout
447 fi
448 test_done "$testroot" "$ret"
451 function test_commit_dir_path {
452 local testroot=`test_init commit_dir_path`
454 got checkout $testroot/repo $testroot/wt > /dev/null
455 ret="$?"
456 if [ "$ret" != "0" ]; then
457 test_done "$testroot" "$ret"
458 return 1
459 fi
461 echo "modified alpha" > $testroot/wt/alpha
462 echo "modified zeta" > $testroot/wt/epsilon/zeta
464 (cd $testroot/wt && got commit -m 'changed zeta' epsilon \
465 > $testroot/stdout)
467 local head_rev=`git_show_head $testroot/repo`
468 echo "M epsilon/zeta" >> $testroot/stdout.expected
469 echo "Created commit $head_rev" >> $testroot/stdout.expected
471 cmp -s $testroot/stdout.expected $testroot/stdout
472 ret="$?"
473 if [ "$ret" != "0" ]; then
474 diff -u $testroot/stdout.expected $testroot/stdout
475 test_done "$testroot" "$ret"
476 return 1
477 fi
479 echo "M alpha" > $testroot/stdout.expected
480 (cd $testroot/wt && got status > $testroot/stdout)
481 cmp -s $testroot/stdout.expected $testroot/stdout
482 ret="$?"
483 if [ "$ret" != "0" ]; then
484 diff -u $testroot/stdout.expected $testroot/stdout
485 fi
486 test_done "$testroot" "$ret"
489 function test_commit_selected_paths {
490 local testroot=`test_init commit_selected_paths`
492 got checkout $testroot/repo $testroot/wt > /dev/null
493 ret="$?"
494 if [ "$ret" != "0" ]; then
495 test_done "$testroot" "$ret"
496 return 1
497 fi
499 echo "modified alpha" > $testroot/wt/alpha
500 echo "modified delta" > $testroot/wt/gamma/delta
501 echo "modified zeta" > $testroot/wt/epsilon/zeta
502 (cd $testroot/wt && got rm beta >/dev/null)
503 echo "new file" > $testroot/wt/new
504 (cd $testroot/wt && got add new >/dev/null)
506 (cd $testroot/wt && got commit -m 'many paths' nonexistent alpha \
507 > $testroot/stdout 2> $testroot/stderr)
508 ret="$?"
509 if [ "$ret" == "0" ]; then
510 echo "commit succeeded unexpectedly" >&2
511 test_done "$testroot" "1"
512 return 1
513 fi
514 echo "got: nonexistent: bad path" > $testroot/stderr.expected
516 cmp -s $testroot/stderr.expected $testroot/stderr
517 ret="$?"
518 if [ "$ret" != "0" ]; then
519 diff -u $testroot/stderr.expected $testroot/stderr
520 test_done "$testroot" "$ret"
521 return 1
522 fi
524 (cd $testroot/wt && got commit -m 'many paths' \
525 beta new gamma > $testroot/stdout)
527 local head_rev=`git_show_head $testroot/repo`
528 echo "A new" > $testroot/stdout.expected
529 echo "D beta" >> $testroot/stdout.expected
530 echo "M gamma/delta" >> $testroot/stdout.expected
531 echo "Created commit $head_rev" >> $testroot/stdout.expected
533 cmp -s $testroot/stdout.expected $testroot/stdout
534 ret="$?"
535 if [ "$ret" != "0" ]; then
536 diff -u $testroot/stdout.expected $testroot/stdout
537 fi
538 test_done "$testroot" "$ret"
541 function test_commit_outside_refs_heads {
542 local testroot=`test_init commit_outside_refs_heads`
544 got ref -r $testroot/repo -c master refs/remotes/origin/master
546 got checkout -b refs/remotes/origin/master \
547 $testroot/repo $testroot/wt > /dev/null
548 ret="$?"
549 if [ "$ret" != "0" ]; then
550 test_done "$testroot" "$ret"
551 return 1
552 fi
554 echo "modified alpha" > $testroot/wt/alpha
556 (cd $testroot/wt && got commit -m 'change alpha' \
557 > $testroot/stdout 2> $testroot/stderr)
558 ret="$?"
559 if [ "$ret" == "0" ]; then
560 echo "commit succeeded unexpectedly" >&2
561 test_done "$testroot" "1"
562 return 1
563 fi
565 echo -n > $testroot/stdout.expected
566 cmp -s $testroot/stdout.expected $testroot/stdout
567 ret="$?"
568 if [ "$ret" != "0" ]; then
569 diff -u $testroot/stdout.expected $testroot/stdout
570 test_done "$testroot" "$ret"
571 return 1
572 fi
574 echo -n "got: will not commit to a branch outside the " \
575 > $testroot/stderr.expected
576 echo '"refs/heads/" reference namespace' \
577 >> $testroot/stderr.expected
578 cmp -s $testroot/stderr.expected $testroot/stderr
579 ret="$?"
580 if [ "$ret" != "0" ]; then
581 diff -u $testroot/stderr.expected $testroot/stderr
582 fi
583 test_done "$testroot" "$ret"
586 function test_commit_no_email {
587 local testroot=`test_init commit_no_email`
589 got checkout $testroot/repo $testroot/wt > /dev/null
590 ret="$?"
591 if [ "$ret" != "0" ]; then
592 test_done "$testroot" "$ret"
593 return 1
594 fi
596 echo "modified alpha" > $testroot/wt/alpha
597 (cd $testroot/wt && env GOT_AUTHOR=":flan_hacker:" \
598 got commit -m 'test no email' > $testroot/stdout \
599 2> $testroot/stderr)
601 echo -n "got: GOT_AUTHOR environment variable contains no email " \
602 > $testroot/stderr.expected
603 echo -n "address; an email address is required for compatibility "\
604 >> $testroot/stderr.expected
605 echo "with Git" >> $testroot/stderr.expected
606 cmp -s $testroot/stderr.expected $testroot/stderr
607 ret="$?"
608 if [ "$ret" != "0" ]; then
609 diff -u $testroot/stderr.expected $testroot/stderr
610 test_done "$testroot" "$ret"
611 return 1
612 fi
614 echo -n > $testroot/stdout.expected
615 cmp -s $testroot/stdout.expected $testroot/stdout
616 ret="$?"
617 if [ "$ret" != "0" ]; then
618 diff -u $testroot/stdout.expected $testroot/stdout
619 fi
620 test_done "$testroot" "$ret"
623 function test_commit_tree_entry_sorting {
624 local testroot=`test_init commit_tree_entry_sorting`
626 got checkout $testroot/repo $testroot/wt > /dev/null
627 ret="$?"
628 if [ "$ret" != "0" ]; then
629 test_done "$testroot" "$ret"
630 return 1
631 fi
633 # Git's index gets corrupted when tree entries are written in the
634 # order defined by got_path_cmp() rather than Git's own ordering.
635 # Create a new tree where a directory "got" and a file "got-version"
636 # would sort in the wrong order according to Git's opinion.
637 mkdir $testroot/wt/got
638 touch $testroot/wt/got/foo
639 echo foo > $testroot/wt/got-version
640 echo zzz > $testroot/wt/zzz
641 (cd $testroot/wt && got add got-version got/foo zzz > /dev/null)
643 (cd $testroot/wt && got commit -m 'test' > /dev/null)
645 # Let git-fsck verify the newly written tree to make sure Git is happy
646 (cd $testroot/repo && git fsck --strict \
647 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
648 ret="$?"
649 test_done "$testroot" "$ret"
652 function test_commit_gitconfig_author {
653 local testroot=`test_init commit_gitconfig_author`
655 got checkout $testroot/repo $testroot/wt > /dev/null
656 ret="$?"
657 if [ "$ret" != "0" ]; then
658 test_done "$testroot" "$ret"
659 return 1
660 fi
662 (cd $testroot/repo && git config user.name 'Flan Luck')
663 (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
665 echo "modified alpha" > $testroot/wt/alpha
666 (cd $testroot/wt && got commit -m 'test gitconfig author' > /dev/null)
667 ret="$?"
668 if [ "$ret" != "0" ]; then
669 test_done "$testroot" "$ret"
670 return 1
671 fi
673 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
674 ret="$?"
675 if [ "$ret" != "0" ]; then
676 test_done "$testroot" "$ret"
677 return 1
678 fi
680 echo "from: Flan Luck <flan_luck@openbsd.org>" \
681 > $testroot/stdout.expected
682 cmp -s $testroot/stdout.expected $testroot/stdout
683 ret="$?"
684 if [ "$ret" != "0" ]; then
685 diff -u $testroot/stdout.expected $testroot/stdout
686 fi
687 test_done "$testroot" "$ret"
690 function test_commit_xbit_change {
691 local testroot=`test_init commit_xbit_change`
693 got checkout $testroot/repo $testroot/wt > /dev/null
694 ret="$?"
695 if [ "$ret" != "0" ]; then
696 test_done "$testroot" "$ret"
697 return 1
698 fi
700 chmod +x $testroot/wt/alpha
702 echo 'm alpha' > $testroot/stdout.expected
703 (cd $testroot/wt && got status > $testroot/stdout)
705 cmp -s $testroot/stdout.expected $testroot/stdout
706 ret="$?"
707 if [ "$ret" != "0" ]; then
708 diff -u $testroot/stdout.expected $testroot/stdout
709 test_done "$testroot" "$ret"
710 return 1
711 fi
713 (cd $testroot/wt && got commit -mx > $testroot/stdout)
714 ret="$?"
715 if [ "$ret" != "0" ]; then
716 echo "got commit failed unexpectedly"
717 test_done "$testroot" "$ret"
718 return 1
719 fi
721 local commit_id=`git_show_head $testroot/repo`
722 echo 'm alpha' > $testroot/stdout.expected
723 echo "Created commit $commit_id" >> $testroot/stdout.expected
724 cmp -s $testroot/stdout.expected $testroot/stdout
725 ret="$?"
726 if [ "$ret" != "0" ]; then
727 diff -u $testroot/stdout.expected $testroot/stdout
728 test_done "$testroot" "$ret"
729 return 1
730 fi
732 (cd $testroot/wt && got status > $testroot/stdout)
734 echo -n > $testroot/stdout.expected
735 cmp -s $testroot/stdout.expected $testroot/stdout
736 ret="$?"
737 if [ "$ret" != "0" ]; then
738 diff -u $testroot/stdout.expected $testroot/stdout
739 test_done "$testroot" "$ret"
740 return 1
741 fi
743 chmod -x $testroot/wt/alpha
745 echo 'm alpha' > $testroot/stdout.expected
746 (cd $testroot/wt && got status > $testroot/stdout)
748 cmp -s $testroot/stdout.expected $testroot/stdout
749 ret="$?"
750 if [ "$ret" != "0" ]; then
751 diff -u $testroot/stdout.expected $testroot/stdout
752 test_done "$testroot" "$ret"
753 return 1
754 fi
756 (cd $testroot/wt && got commit -mx > $testroot/stdout)
757 ret="$?"
758 if [ "$ret" != "0" ]; then
759 echo "got commit failed unexpectedly"
760 test_done "$testroot" "$ret"
761 return 1
762 fi
764 local commit_id=`git_show_head $testroot/repo`
765 echo 'm alpha' > $testroot/stdout.expected
766 echo "Created commit $commit_id" >> $testroot/stdout.expected
767 cmp -s $testroot/stdout.expected $testroot/stdout
768 ret="$?"
769 if [ "$ret" != "0" ]; then
770 diff -u $testroot/stdout.expected $testroot/stdout
771 test_done "$testroot" "$ret"
772 return 1
773 fi
775 chmod +x $testroot/wt/alpha
777 echo 'm alpha' > $testroot/stdout.expected
778 (cd $testroot/wt && got status > $testroot/stdout)
780 cmp -s $testroot/stdout.expected $testroot/stdout
781 ret="$?"
782 if [ "$ret" != "0" ]; then
783 diff -u $testroot/stdout.expected $testroot/stdout
784 fi
785 test_done "$testroot" "$ret"
788 function commit_check_mode {
789 local mode="$1"
790 local expected_mode="$2"
792 chmod 644 $testroot/wt/alpha
793 echo a >> $testroot/wt/alpha
794 chmod $mode $testroot/wt/alpha
796 (cd $testroot/wt && got commit -mm > $testroot/stdout)
797 ret="$?"
798 if [ "$ret" != "0" ]; then
799 echo "got commit failed unexpectedly"
800 test_done "$testroot" "$ret"
801 return 1
802 fi
804 local commit_id=`git_show_head $testroot/repo`
805 echo 'M alpha' > $testroot/stdout.expected
806 echo "Created commit $commit_id" >> $testroot/stdout.expected
807 cmp -s $testroot/stdout.expected $testroot/stdout
808 ret="$?"
809 if [ "$ret" != "0" ]; then
810 diff -u $testroot/stdout.expected $testroot/stdout
811 test_done "$testroot" "$ret"
812 fi
814 local tree_id=$(got cat -r $testroot/repo $commit_id | \
815 grep ^tree | cut -d' ' -f2)
816 local alpha_id=$(got cat -r $testroot/repo $tree_id | \
817 grep 'alpha$' | cut -d' ' -f1)
818 echo "$alpha_id $expected_mode alpha" > $testroot/stdout.expected
819 got cat -r $testroot/repo $tree_id | grep 'alpha$' > $testroot/stdout
820 cmp -s $testroot/stdout.expected $testroot/stdout
821 ret="$?"
822 if [ "$ret" != "0" ]; then
823 diff -u $testroot/stdout.expected $testroot/stdout
824 fi
825 return $ret
828 function test_commit_normalizes_filemodes {
829 local testroot=`test_init commit_normalizes_filemodes`
831 got checkout $testroot/repo $testroot/wt > /dev/null
832 ret="$?"
833 if [ "$ret" != "0" ]; then
834 test_done "$testroot" "$ret"
835 return 1
836 fi
838 modes="600 400 460 640 440 660 444 666"
839 for m in $modes; do
840 commit_check_mode "$m" "0100644"
841 ret="$?"
842 if [ "$ret" != "0" ]; then
843 break
844 fi
845 done
846 if [ "$ret" != "0" ]; then
847 test_done "$testroot" "$ret"
848 return 1
849 fi
850 modes="700 500 570 750 550 770 555 777"
851 for m in $modes; do
852 commit_check_mode "$m" "0100755"
853 ret="$?"
854 if [ "$ret" != "0" ]; then
855 break
856 fi
857 done
858 if [ "$ret" != "0" ]; then
859 test_done "$testroot" "$ret"
860 return 1
861 fi
862 test_done "$testroot" "$ret"
865 function test_commit_with_unrelated_submodule {
866 local testroot=`test_init commit_with_unrelated_submodule`
868 make_single_file_repo $testroot/repo2 foo
870 (cd $testroot/repo && git submodule -q add ../repo2)
871 (cd $testroot/repo && git commit -q -m 'adding submodule')
873 got checkout $testroot/repo $testroot/wt > /dev/null
874 ret="$?"
875 if [ "$ret" != "0" ]; then
876 echo "checkout failed unexpectedly" >&2
877 test_done "$testroot" "$ret"
878 return 1
879 fi
881 echo "modified alpha" > $testroot/wt/alpha
883 echo "" > $testroot/stdout.expected
885 (cd $testroot/wt && got commit -m 'modify alpha' > $testroot/stdout)
886 ret="$?"
887 if [ "$ret" != "0" ]; then
888 echo "commit failed unexpectedly" >&2
889 test_done "$testroot" "$ret"
890 return 1
891 fi
893 local head_rev=`git_show_head $testroot/repo`
894 echo "M alpha" > $testroot/stdout.expected
895 echo "Created commit $head_rev" >> $testroot/stdout.expected
897 cmp -s $testroot/stdout.expected $testroot/stdout
898 ret="$?"
899 if [ "$ret" != "0" ]; then
900 diff -u $testroot/stdout.expected $testroot/stdout
901 fi
902 test_done "$testroot" "$ret"
905 run_test test_commit_basic
906 run_test test_commit_new_subdir
907 run_test test_commit_subdir
908 run_test test_commit_single_file
909 run_test test_commit_out_of_date
910 run_test test_commit_added_subdirs
911 run_test test_commit_deleted_subdirs
912 run_test test_commit_rejects_conflicted_file
913 run_test test_commit_single_file_multiple
914 run_test test_commit_added_and_modified_in_same_dir
915 run_test test_commit_path_prefix
916 run_test test_commit_dir_path
917 run_test test_commit_selected_paths
918 run_test test_commit_outside_refs_heads
919 run_test test_commit_no_email
920 run_test test_commit_tree_entry_sorting
921 run_test test_commit_gitconfig_author
922 run_test test_commit_xbit_change
923 run_test test_commit_normalizes_filemodes
924 run_test test_commit_with_unrelated_submodule