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 test_done "$testroot" "$ret"
448 return 1
449 fi
451 (cd $testroot/wt && got rm delta > /dev/null)
452 echo new > $testroot/wt/new
453 (cd $testroot/wt && got add new > /dev/null)
455 (cd $testroot/wt && got commit -m 'remove gamma/delta; add gamma/new' \
456 > $testroot/stdout)
458 local commit3=`git_show_head $testroot/repo`
459 echo "A new" > $testroot/stdout.expected
460 echo "D delta" >> $testroot/stdout.expected
461 echo "Created commit $commit3" >> $testroot/stdout.expected
463 cmp -s $testroot/stdout.expected $testroot/stdout
464 ret="$?"
465 if [ "$ret" != "0" ]; then
466 diff -u $testroot/stdout.expected $testroot/stdout
467 test_done "$testroot" "$ret"
468 return 1
469 fi
471 echo "diff $commit2 $commit3" > $testroot/stdout.expected
472 echo -n 'blob - ' >> $testroot/stdout.expected
473 got tree -r $testroot/repo -c $commit2 -i gamma | grep 'delta$' \
474 | cut -d' ' -f 1 | sed -e 's/$/ (mode 644)/' \
475 >> $testroot/stdout.expected
476 echo 'blob + /dev/null' >> $testroot/stdout.expected
477 echo '--- gamma/delta' >> $testroot/stdout.expected
478 echo '+++ /dev/null' >> $testroot/stdout.expected
479 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
480 echo '-modified delta' >> $testroot/stdout.expected
481 echo 'blob - /dev/null' >> $testroot/stdout.expected
482 echo -n 'blob + ' >> $testroot/stdout.expected
483 got tree -r $testroot/repo -c $commit3 -i gamma | grep 'new$' | \
484 cut -d' ' -f 1 | sed -e 's/$/ (mode 644)/' \
485 >> $testroot/stdout.expected
486 echo '--- /dev/null' >> $testroot/stdout.expected
487 echo '+++ gamma/new' >> $testroot/stdout.expected
488 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
489 echo '+new' >> $testroot/stdout.expected
491 got diff -r $testroot/repo $commit2 $commit3 > $testroot/stdout
492 cmp -s $testroot/stdout.expected $testroot/stdout
493 ret="$?"
494 if [ "$ret" != "0" ]; then
495 diff -u $testroot/stdout.expected $testroot/stdout
496 fi
497 test_done "$testroot" "$ret"
498 return "$ret"
501 function test_commit_dir_path {
502 local testroot=`test_init commit_dir_path`
504 got checkout $testroot/repo $testroot/wt > /dev/null
505 ret="$?"
506 if [ "$ret" != "0" ]; then
507 test_done "$testroot" "$ret"
508 return 1
509 fi
511 echo "modified alpha" > $testroot/wt/alpha
512 echo "modified zeta" > $testroot/wt/epsilon/zeta
514 (cd $testroot/wt && got commit -m 'changed zeta' epsilon \
515 > $testroot/stdout)
517 local head_rev=`git_show_head $testroot/repo`
518 echo "M epsilon/zeta" >> $testroot/stdout.expected
519 echo "Created commit $head_rev" >> $testroot/stdout.expected
521 cmp -s $testroot/stdout.expected $testroot/stdout
522 ret="$?"
523 if [ "$ret" != "0" ]; then
524 diff -u $testroot/stdout.expected $testroot/stdout
525 test_done "$testroot" "$ret"
526 return 1
527 fi
529 echo "M alpha" > $testroot/stdout.expected
530 (cd $testroot/wt && got status > $testroot/stdout)
531 cmp -s $testroot/stdout.expected $testroot/stdout
532 ret="$?"
533 if [ "$ret" != "0" ]; then
534 diff -u $testroot/stdout.expected $testroot/stdout
535 fi
536 test_done "$testroot" "$ret"
539 function test_commit_selected_paths {
540 local testroot=`test_init commit_selected_paths`
542 got checkout $testroot/repo $testroot/wt > /dev/null
543 ret="$?"
544 if [ "$ret" != "0" ]; then
545 test_done "$testroot" "$ret"
546 return 1
547 fi
549 echo "modified alpha" > $testroot/wt/alpha
550 echo "modified delta" > $testroot/wt/gamma/delta
551 echo "modified zeta" > $testroot/wt/epsilon/zeta
552 (cd $testroot/wt && got rm beta >/dev/null)
553 echo "new file" > $testroot/wt/new
554 (cd $testroot/wt && got add new >/dev/null)
556 (cd $testroot/wt && got commit -m 'many paths' nonexistent 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
564 echo "got: nonexistent: bad path" > $testroot/stderr.expected
566 cmp -s $testroot/stderr.expected $testroot/stderr
567 ret="$?"
568 if [ "$ret" != "0" ]; then
569 diff -u $testroot/stderr.expected $testroot/stderr
570 test_done "$testroot" "$ret"
571 return 1
572 fi
574 (cd $testroot/wt && got commit -m 'many paths' \
575 beta new gamma > $testroot/stdout)
577 local head_rev=`git_show_head $testroot/repo`
578 echo "A new" > $testroot/stdout.expected
579 echo "D beta" >> $testroot/stdout.expected
580 echo "M gamma/delta" >> $testroot/stdout.expected
581 echo "Created commit $head_rev" >> $testroot/stdout.expected
583 cmp -s $testroot/stdout.expected $testroot/stdout
584 ret="$?"
585 if [ "$ret" != "0" ]; then
586 diff -u $testroot/stdout.expected $testroot/stdout
587 fi
588 test_done "$testroot" "$ret"
591 function test_commit_outside_refs_heads {
592 local testroot=`test_init commit_outside_refs_heads`
594 got ref -r $testroot/repo -c master refs/remotes/origin/master
596 got checkout -b refs/remotes/origin/master \
597 $testroot/repo $testroot/wt > /dev/null
598 ret="$?"
599 if [ "$ret" != "0" ]; then
600 test_done "$testroot" "$ret"
601 return 1
602 fi
604 echo "modified alpha" > $testroot/wt/alpha
606 (cd $testroot/wt && got commit -m 'change alpha' \
607 > $testroot/stdout 2> $testroot/stderr)
608 ret="$?"
609 if [ "$ret" == "0" ]; then
610 echo "commit succeeded unexpectedly" >&2
611 test_done "$testroot" "1"
612 return 1
613 fi
615 echo -n > $testroot/stdout.expected
616 cmp -s $testroot/stdout.expected $testroot/stdout
617 ret="$?"
618 if [ "$ret" != "0" ]; then
619 diff -u $testroot/stdout.expected $testroot/stdout
620 test_done "$testroot" "$ret"
621 return 1
622 fi
624 echo -n "got: will not commit to a branch outside the " \
625 > $testroot/stderr.expected
626 echo '"refs/heads/" reference namespace' \
627 >> $testroot/stderr.expected
628 cmp -s $testroot/stderr.expected $testroot/stderr
629 ret="$?"
630 if [ "$ret" != "0" ]; then
631 diff -u $testroot/stderr.expected $testroot/stderr
632 fi
633 test_done "$testroot" "$ret"
636 function test_commit_no_email {
637 local testroot=`test_init commit_no_email`
639 got checkout $testroot/repo $testroot/wt > /dev/null
640 ret="$?"
641 if [ "$ret" != "0" ]; then
642 test_done "$testroot" "$ret"
643 return 1
644 fi
646 echo "modified alpha" > $testroot/wt/alpha
647 (cd $testroot/wt && env GOT_AUTHOR=":flan_hacker:" \
648 got commit -m 'test no email' > $testroot/stdout \
649 2> $testroot/stderr)
651 echo -n "got: GOT_AUTHOR environment variable contains no email " \
652 > $testroot/stderr.expected
653 echo -n "address; an email address is required for compatibility "\
654 >> $testroot/stderr.expected
655 echo "with Git" >> $testroot/stderr.expected
656 cmp -s $testroot/stderr.expected $testroot/stderr
657 ret="$?"
658 if [ "$ret" != "0" ]; then
659 diff -u $testroot/stderr.expected $testroot/stderr
660 test_done "$testroot" "$ret"
661 return 1
662 fi
664 echo -n > $testroot/stdout.expected
665 cmp -s $testroot/stdout.expected $testroot/stdout
666 ret="$?"
667 if [ "$ret" != "0" ]; then
668 diff -u $testroot/stdout.expected $testroot/stdout
669 fi
670 test_done "$testroot" "$ret"
673 function test_commit_tree_entry_sorting {
674 local testroot=`test_init commit_tree_entry_sorting`
676 got checkout $testroot/repo $testroot/wt > /dev/null
677 ret="$?"
678 if [ "$ret" != "0" ]; then
679 test_done "$testroot" "$ret"
680 return 1
681 fi
683 # Git's index gets corrupted when tree entries are written in the
684 # order defined by got_path_cmp() rather than Git's own ordering.
685 # Create a new tree where a directory "got" and a file "got-version"
686 # would sort in the wrong order according to Git's opinion.
687 mkdir $testroot/wt/got
688 touch $testroot/wt/got/foo
689 echo foo > $testroot/wt/got-version
690 echo zzz > $testroot/wt/zzz
691 (cd $testroot/wt && got add got-version got/foo zzz > /dev/null)
693 (cd $testroot/wt && got commit -m 'test' > /dev/null)
695 # Let git-fsck verify the newly written tree to make sure Git is happy
696 (cd $testroot/repo && git fsck --strict \
697 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
698 ret="$?"
699 test_done "$testroot" "$ret"
702 function test_commit_gitconfig_author {
703 local testroot=`test_init commit_gitconfig_author`
705 got checkout $testroot/repo $testroot/wt > /dev/null
706 ret="$?"
707 if [ "$ret" != "0" ]; then
708 test_done "$testroot" "$ret"
709 return 1
710 fi
712 (cd $testroot/repo && git config user.name 'Flan Luck')
713 (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
715 echo "modified alpha" > $testroot/wt/alpha
716 (cd $testroot/wt && got commit -m 'test gitconfig author' > /dev/null)
717 ret="$?"
718 if [ "$ret" != "0" ]; then
719 test_done "$testroot" "$ret"
720 return 1
721 fi
723 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
724 ret="$?"
725 if [ "$ret" != "0" ]; then
726 test_done "$testroot" "$ret"
727 return 1
728 fi
730 echo "from: Flan Luck <flan_luck@openbsd.org>" \
731 > $testroot/stdout.expected
732 cmp -s $testroot/stdout.expected $testroot/stdout
733 ret="$?"
734 if [ "$ret" != "0" ]; then
735 diff -u $testroot/stdout.expected $testroot/stdout
736 fi
737 test_done "$testroot" "$ret"
740 function test_commit_xbit_change {
741 local testroot=`test_init commit_xbit_change`
743 got checkout $testroot/repo $testroot/wt > /dev/null
744 ret="$?"
745 if [ "$ret" != "0" ]; then
746 test_done "$testroot" "$ret"
747 return 1
748 fi
750 chmod +x $testroot/wt/alpha
752 echo 'm alpha' > $testroot/stdout.expected
753 (cd $testroot/wt && got status > $testroot/stdout)
755 cmp -s $testroot/stdout.expected $testroot/stdout
756 ret="$?"
757 if [ "$ret" != "0" ]; then
758 diff -u $testroot/stdout.expected $testroot/stdout
759 test_done "$testroot" "$ret"
760 return 1
761 fi
763 (cd $testroot/wt && got commit -mx > $testroot/stdout)
764 ret="$?"
765 if [ "$ret" != "0" ]; then
766 echo "got commit failed unexpectedly"
767 test_done "$testroot" "$ret"
768 return 1
769 fi
771 local commit_id=`git_show_head $testroot/repo`
772 echo 'm alpha' > $testroot/stdout.expected
773 echo "Created commit $commit_id" >> $testroot/stdout.expected
774 cmp -s $testroot/stdout.expected $testroot/stdout
775 ret="$?"
776 if [ "$ret" != "0" ]; then
777 diff -u $testroot/stdout.expected $testroot/stdout
778 test_done "$testroot" "$ret"
779 return 1
780 fi
782 (cd $testroot/wt && got status > $testroot/stdout)
784 echo -n > $testroot/stdout.expected
785 cmp -s $testroot/stdout.expected $testroot/stdout
786 ret="$?"
787 if [ "$ret" != "0" ]; then
788 diff -u $testroot/stdout.expected $testroot/stdout
789 test_done "$testroot" "$ret"
790 return 1
791 fi
793 chmod -x $testroot/wt/alpha
795 echo 'm alpha' > $testroot/stdout.expected
796 (cd $testroot/wt && got status > $testroot/stdout)
798 cmp -s $testroot/stdout.expected $testroot/stdout
799 ret="$?"
800 if [ "$ret" != "0" ]; then
801 diff -u $testroot/stdout.expected $testroot/stdout
802 test_done "$testroot" "$ret"
803 return 1
804 fi
806 (cd $testroot/wt && got commit -mx > $testroot/stdout)
807 ret="$?"
808 if [ "$ret" != "0" ]; then
809 echo "got commit failed unexpectedly"
810 test_done "$testroot" "$ret"
811 return 1
812 fi
814 local commit_id=`git_show_head $testroot/repo`
815 echo 'm alpha' > $testroot/stdout.expected
816 echo "Created commit $commit_id" >> $testroot/stdout.expected
817 cmp -s $testroot/stdout.expected $testroot/stdout
818 ret="$?"
819 if [ "$ret" != "0" ]; then
820 diff -u $testroot/stdout.expected $testroot/stdout
821 test_done "$testroot" "$ret"
822 return 1
823 fi
825 chmod +x $testroot/wt/alpha
827 echo 'm alpha' > $testroot/stdout.expected
828 (cd $testroot/wt && got status > $testroot/stdout)
830 cmp -s $testroot/stdout.expected $testroot/stdout
831 ret="$?"
832 if [ "$ret" != "0" ]; then
833 diff -u $testroot/stdout.expected $testroot/stdout
834 fi
835 test_done "$testroot" "$ret"
838 function commit_check_mode {
839 local mode="$1"
840 local expected_mode="$2"
842 chmod 644 $testroot/wt/alpha
843 echo a >> $testroot/wt/alpha
844 chmod $mode $testroot/wt/alpha
846 (cd $testroot/wt && got commit -mm > $testroot/stdout)
847 ret="$?"
848 if [ "$ret" != "0" ]; then
849 echo "got commit failed unexpectedly"
850 test_done "$testroot" "$ret"
851 return 1
852 fi
854 local commit_id=`git_show_head $testroot/repo`
855 echo 'M alpha' > $testroot/stdout.expected
856 echo "Created commit $commit_id" >> $testroot/stdout.expected
857 cmp -s $testroot/stdout.expected $testroot/stdout
858 ret="$?"
859 if [ "$ret" != "0" ]; then
860 diff -u $testroot/stdout.expected $testroot/stdout
861 test_done "$testroot" "$ret"
862 fi
864 local tree_id=$(got cat -r $testroot/repo $commit_id | \
865 grep ^tree | cut -d' ' -f2)
866 local alpha_id=$(got cat -r $testroot/repo $tree_id | \
867 grep 'alpha$' | cut -d' ' -f1)
868 echo "$alpha_id $expected_mode alpha" > $testroot/stdout.expected
869 got cat -r $testroot/repo $tree_id | grep 'alpha$' > $testroot/stdout
870 cmp -s $testroot/stdout.expected $testroot/stdout
871 ret="$?"
872 if [ "$ret" != "0" ]; then
873 diff -u $testroot/stdout.expected $testroot/stdout
874 fi
875 return $ret
878 function test_commit_normalizes_filemodes {
879 local testroot=`test_init commit_normalizes_filemodes`
881 got checkout $testroot/repo $testroot/wt > /dev/null
882 ret="$?"
883 if [ "$ret" != "0" ]; then
884 test_done "$testroot" "$ret"
885 return 1
886 fi
888 modes="600 400 460 640 440 660 444 666"
889 for m in $modes; do
890 commit_check_mode "$m" "0100644"
891 ret="$?"
892 if [ "$ret" != "0" ]; then
893 break
894 fi
895 done
896 if [ "$ret" != "0" ]; then
897 test_done "$testroot" "$ret"
898 return 1
899 fi
900 modes="700 500 570 750 550 770 555 777"
901 for m in $modes; do
902 commit_check_mode "$m" "0100755"
903 ret="$?"
904 if [ "$ret" != "0" ]; then
905 break
906 fi
907 done
908 if [ "$ret" != "0" ]; then
909 test_done "$testroot" "$ret"
910 return 1
911 fi
912 test_done "$testroot" "$ret"
915 function test_commit_with_unrelated_submodule {
916 local testroot=`test_init commit_with_unrelated_submodule`
918 make_single_file_repo $testroot/repo2 foo
920 (cd $testroot/repo && git submodule -q add ../repo2)
921 (cd $testroot/repo && git commit -q -m 'adding submodule')
923 got checkout $testroot/repo $testroot/wt > /dev/null
924 ret="$?"
925 if [ "$ret" != "0" ]; then
926 echo "checkout failed unexpectedly" >&2
927 test_done "$testroot" "$ret"
928 return 1
929 fi
931 echo "modified alpha" > $testroot/wt/alpha
933 echo "" > $testroot/stdout.expected
935 (cd $testroot/wt && got commit -m 'modify alpha' > $testroot/stdout)
936 ret="$?"
937 if [ "$ret" != "0" ]; then
938 echo "commit failed unexpectedly" >&2
939 test_done "$testroot" "$ret"
940 return 1
941 fi
943 local head_rev=`git_show_head $testroot/repo`
944 echo "M alpha" > $testroot/stdout.expected
945 echo "Created commit $head_rev" >> $testroot/stdout.expected
947 cmp -s $testroot/stdout.expected $testroot/stdout
948 ret="$?"
949 if [ "$ret" != "0" ]; then
950 diff -u $testroot/stdout.expected $testroot/stdout
951 fi
952 test_done "$testroot" "$ret"
955 function check_symlinks {
956 local wtpath="$1"
957 if ! [ -h $wtpath/alpha.link ]; then
958 echo "alpha.link is not a symlink"
959 return 1
960 fi
962 readlink $wtpath/alpha.link > $testroot/stdout
963 echo "alpha" > $testroot/stdout.expected
964 cmp -s $testroot/stdout.expected $testroot/stdout
965 ret="$?"
966 if [ "$ret" != "0" ]; then
967 diff -u $testroot/stdout.expected $testroot/stdout
968 return 1
969 fi
971 if ! [ -h $wtpath/epsilon.link ]; then
972 echo "epsilon.link is not a symlink"
973 return 1
974 fi
976 readlink $wtpath/epsilon.link > $testroot/stdout
977 echo "epsilon" > $testroot/stdout.expected
978 cmp -s $testroot/stdout.expected $testroot/stdout
979 ret="$?"
980 if [ "$ret" != "0" ]; then
981 diff -u $testroot/stdout.expected $testroot/stdout
982 return 1
983 fi
985 if [ -h $wtpath/passwd.link ]; then
986 echo -n "passwd.link is a symlink and points outside of work tree: " >&2
987 readlink $wtpath/passwd.link >&2
988 return 1
989 fi
991 echo -n "/etc/passwd" > $testroot/content.expected
992 cp $wtpath/passwd.link $testroot/content
993 ret="$?"
994 if [ "$ret" != "0" ]; then
995 echo "cp command failed unexpectedly" >&2
996 return 1
997 fi
999 cmp -s $testroot/content.expected $testroot/content
1000 ret="$?"
1001 if [ "$ret" != "0" ]; then
1002 diff -u $testroot/content.expected $testroot/content
1003 return 1
1006 readlink $wtpath/epsilon/beta.link > $testroot/stdout
1007 echo "../beta" > $testroot/stdout.expected
1008 cmp -s $testroot/stdout.expected $testroot/stdout
1009 ret="$?"
1010 if [ "$ret" != "0" ]; then
1011 diff -u $testroot/stdout.expected $testroot/stdout
1012 return 1
1015 readlink $wtpath/nonexistent.link > $testroot/stdout
1016 echo "nonexistent" > $testroot/stdout.expected
1017 cmp -s $testroot/stdout.expected $testroot/stdout
1018 ret="$?"
1019 if [ "$ret" != "0" ]; then
1020 diff -u $testroot/stdout.expected $testroot/stdout
1021 return 1
1024 return 0
1027 function test_commit_symlink {
1028 local testroot=`test_init commit_symlink`
1030 got checkout $testroot/repo $testroot/wt > /dev/null
1031 ret="$?"
1032 if [ "$ret" != "0" ]; then
1033 test_done "$testroot" "$ret"
1034 return 1
1037 (cd $testroot/wt && ln -s alpha alpha.link)
1038 (cd $testroot/wt && ln -s epsilon epsilon.link)
1039 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1040 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
1041 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
1042 (cd $testroot/wt && got add alpha.link epsilon.link passwd.link \
1043 epsilon/beta.link nonexistent.link > /dev/null)
1045 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1046 > $testroot/stdout 2> $testroot/stderr)
1047 ret="$?"
1048 if [ "$ret" == "0" ]; then
1049 echo "got commit succeeded unexpectedly" >&2
1050 test_done "$testroot" "$ret"
1051 return 1
1053 echo -n "got: $testroot/wt/passwd.link: " > $testroot/stderr.expected
1054 echo "symbolic link points outside of paths under version control" \
1055 >> $testroot/stderr.expected
1056 cmp -s $testroot/stderr.expected $testroot/stderr
1057 ret="$?"
1058 if [ "$ret" != "0" ]; then
1059 diff -u $testroot/stderr.expected $testroot/stderr
1060 test_done "$testroot" "$ret"
1061 return 1
1064 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1065 > $testroot/stdout)
1067 local head_rev=`git_show_head $testroot/repo`
1068 echo "A alpha.link" > $testroot/stdout.expected
1069 echo "A epsilon.link" >> $testroot/stdout.expected
1070 echo "A nonexistent.link" >> $testroot/stdout.expected
1071 echo "A passwd.link" >> $testroot/stdout.expected
1072 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1073 echo "Created commit $head_rev" >> $testroot/stdout.expected
1075 cmp -s $testroot/stdout.expected $testroot/stdout
1076 ret="$?"
1077 if [ "$ret" != "0" ]; then
1078 diff -u $testroot/stdout.expected $testroot/stdout
1079 test_done "$testroot" "$ret"
1080 return 1
1083 # verify created in-repository tree
1084 got checkout $testroot/repo $testroot/wt2 > /dev/null
1085 ret="$?"
1086 if [ "$ret" != "0" ]; then
1087 test_done "$testroot" "$ret"
1088 return 1
1090 check_symlinks $testroot/wt2
1091 ret="$?"
1092 if [ "$ret" != "0" ]; then
1093 test_done "$testroot" "$ret"
1094 return 1
1097 if ! [ -h $testroot/wt/passwd.link ]; then
1098 echo 'passwd.link is not a symlink' >&2
1099 test_done "$testroot" 1
1100 return 1
1103 # 'got update' should reinstall passwd.link as a regular file
1104 (cd $testroot/wt && got update > /dev/null)
1105 check_symlinks $testroot/wt
1106 ret="$?"
1107 if [ "$ret" != "0" ]; then
1108 test_done "$testroot" "$ret"
1109 return 1
1112 (cd $testroot/wt && ln -sf beta alpha.link)
1113 (cd $testroot/wt && ln -sfh gamma epsilon.link)
1114 rm $testroot/wt/epsilon/beta.link
1115 echo "this is a regular file" > $testroot/wt/epsilon/beta.link
1116 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
1117 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
1118 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
1119 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
1120 (cd $testroot/wt && ln -sf alpha new.link)
1121 (cd $testroot/wt && got add new.link > /dev/null)
1123 (cd $testroot/wt && got commit -m 'test commit_symlink' \
1124 > $testroot/stdout 2> $testroot/stderr)
1125 ret="$?"
1126 if [ "$ret" == "0" ]; then
1127 echo "got commit succeeded unexpectedly" >&2
1128 test_done "$testroot" "$ret"
1129 return 1
1131 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
1132 echo "symbolic link points outside of paths under version control" \
1133 >> $testroot/stderr.expected
1134 cmp -s $testroot/stderr.expected $testroot/stderr
1135 ret="$?"
1136 if [ "$ret" != "0" ]; then
1137 diff -u $testroot/stderr.expected $testroot/stderr
1138 test_done "$testroot" "$ret"
1139 return 1
1142 (cd $testroot/wt && got commit -S -m 'test commit_symlink' \
1143 > $testroot/stdout)
1145 local head_rev=`git_show_head $testroot/repo`
1146 echo "A dotgotbar.link" > $testroot/stdout.expected
1147 echo "A new.link" >> $testroot/stdout.expected
1148 echo "M alpha.link" >> $testroot/stdout.expected
1149 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1150 echo "M epsilon.link" >> $testroot/stdout.expected
1151 echo "D nonexistent.link" >> $testroot/stdout.expected
1152 echo "Created commit $head_rev" >> $testroot/stdout.expected
1154 cmp -s $testroot/stdout.expected $testroot/stdout
1155 ret="$?"
1156 if [ "$ret" != "0" ]; then
1157 diff -u $testroot/stdout.expected $testroot/stdout
1158 test_done "$testroot" "$ret"
1159 return 1
1162 got tree -r $testroot/repo -c $head_rev -R > $testroot/stdout
1163 cat > $testroot/stdout.expected <<EOF
1164 alpha
1165 alpha.link@ -> beta
1166 beta
1167 dotgotbar.link@ -> .got/bar
1168 epsilon/
1169 epsilon/beta.link
1170 epsilon/zeta
1171 epsilon.link@ -> gamma
1172 gamma/
1173 gamma/delta
1174 new.link@ -> alpha
1175 passwd.link@ -> /etc/passwd
1176 EOF
1177 cmp -s $testroot/stdout.expected $testroot/stdout
1178 ret="$?"
1179 if [ "$ret" != "0" ]; then
1180 diff -u $testroot/stdout.expected $testroot/stdout
1182 test_done "$testroot" "$ret"
1185 function test_commit_fix_bad_symlink {
1186 local testroot=`test_init commit_fix_bad_symlink`
1188 got checkout $testroot/repo $testroot/wt > /dev/null
1189 ret="$?"
1190 if [ "$ret" != "0" ]; then
1191 echo "got checkout failed unexpectedly" >&2
1192 test_done "$testroot" "$ret"
1193 return 1
1196 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
1197 (cd $testroot/wt && got add passwd.link > /dev/null)
1199 (cd $testroot/wt && got commit -S -m 'commit bad symlink' \
1200 > $testroot/stdout)
1202 if ! [ -h $testroot/wt/passwd.link ]; then
1203 echo 'passwd.link is not a symlink' >&2
1204 test_done "$testroot" 1
1205 return 1
1207 (cd $testroot/wt && got update >/dev/null)
1208 if [ -h $testroot/wt/passwd.link ]; then
1209 echo "passwd.link is a symlink but should be a regular file" >&2
1210 test_done "$testroot" "1"
1211 return 1
1214 # create another work tree which will contain the "bad" symlink
1215 got checkout $testroot/repo $testroot/wt2 > /dev/null
1216 ret="$?"
1217 if [ "$ret" != "0" ]; then
1218 echo "got checkout failed unexpectedly" >&2
1219 test_done "$testroot" "$ret"
1220 return 1
1223 # change "bad" symlink back into a "good" symlink
1224 (cd $testroot/wt && ln -sfh alpha passwd.link)
1226 (cd $testroot/wt && got commit -m 'fix bad symlink' \
1227 > $testroot/stdout)
1229 local head_rev=`git_show_head $testroot/repo`
1230 echo "M passwd.link" > $testroot/stdout.expected
1231 echo "Created commit $head_rev" >> $testroot/stdout.expected
1233 cmp -s $testroot/stdout.expected $testroot/stdout
1234 ret="$?"
1235 if [ "$ret" != "0" ]; then
1236 diff -u $testroot/stdout.expected $testroot/stdout
1237 test_done "$testroot" "$ret"
1238 return 1
1241 if ! [ -h $testroot/wt/passwd.link ]; then
1242 echo 'passwd.link is not a symlink' >&2
1243 test_done "$testroot" 1
1244 return 1
1247 readlink $testroot/wt/passwd.link > $testroot/stdout
1248 echo "alpha" > $testroot/stdout.expected
1249 cmp -s $testroot/stdout.expected $testroot/stdout
1250 ret="$?"
1251 if [ "$ret" != "0" ]; then
1252 diff -u $testroot/stdout.expected $testroot/stdout
1253 return 1
1256 # Update the other work tree; the bad symlink should be fixed
1257 (cd $testroot/wt2 && got update > /dev/null)
1258 ret="$?"
1259 if [ "$ret" != "0" ]; then
1260 echo "got checkout failed unexpectedly" >&2
1261 test_done "$testroot" "$ret"
1262 return 1
1265 if ! [ -h $testroot/wt2/passwd.link ]; then
1266 echo 'passwd.link is not a symlink' >&2
1267 test_done "$testroot" 1
1268 return 1
1271 readlink $testroot/wt2/passwd.link > $testroot/stdout
1272 echo "alpha" > $testroot/stdout.expected
1273 cmp -s $testroot/stdout.expected $testroot/stdout
1274 ret="$?"
1275 if [ "$ret" != "0" ]; then
1276 diff -u $testroot/stdout.expected $testroot/stdout
1277 return 1
1280 test_done "$testroot" "0"
1283 test_parseargs "$@"
1284 run_test test_commit_basic
1285 run_test test_commit_new_subdir
1286 run_test test_commit_subdir
1287 run_test test_commit_single_file
1288 run_test test_commit_out_of_date
1289 run_test test_commit_added_subdirs
1290 run_test test_commit_deleted_subdirs
1291 run_test test_commit_rejects_conflicted_file
1292 run_test test_commit_single_file_multiple
1293 run_test test_commit_added_and_modified_in_same_dir
1294 run_test test_commit_path_prefix
1295 run_test test_commit_dir_path
1296 run_test test_commit_selected_paths
1297 run_test test_commit_outside_refs_heads
1298 run_test test_commit_no_email
1299 run_test test_commit_tree_entry_sorting
1300 run_test test_commit_gitconfig_author
1301 run_test test_commit_xbit_change
1302 run_test test_commit_normalizes_filemodes
1303 run_test test_commit_with_unrelated_submodule
1304 run_test test_commit_symlink
1305 run_test test_commit_fix_bad_symlink