3 # Copyright (c) 2019, 2020 Stefan Sperling <stsp@openbsd.org>
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.
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.
20 local testroot=`test_init log_in_repo`
21 local head_rev=`git_show_head $testroot/repo`
23 echo "commit $head_rev (master)" > $testroot/stdout.expected
25 for p in "" "." alpha epsilon epsilon/zeta; do
26 (cd $testroot/repo && got log $p | \
27 grep ^commit > $testroot/stdout)
28 cmp -s $testroot/stdout.expected $testroot/stdout
30 if [ $ret -ne 0 ]; then
31 diff -u $testroot/stdout.expected $testroot/stdout
32 test_done "$testroot" "$ret"
37 for p in "" "." zeta; do
38 (cd $testroot/repo/epsilon && got log $p | \
39 grep ^commit > $testroot/stdout)
40 cmp -s $testroot/stdout.expected $testroot/stdout
42 if [ $ret -ne 0 ]; then
43 diff -u $testroot/stdout.expected $testroot/stdout
44 test_done "$testroot" "$ret"
49 test_done "$testroot" "0"
52 test_log_in_bare_repo() {
53 local testroot=`test_init log_in_bare_repo`
54 local head_rev=`git_show_head $testroot/repo`
56 echo "commit $head_rev (master)" > $testroot/stdout.expected
58 for p in "" "." alpha epsilon epsilon/zeta; do
59 (cd $testroot/repo/.git && got log $p | \
60 grep ^commit > $testroot/stdout)
61 cmp -s $testroot/stdout.expected $testroot/stdout
63 if [ $ret -ne 0 ]; then
64 diff -u $testroot/stdout.expected $testroot/stdout
65 test_done "$testroot" "$ret"
70 test_done "$testroot" "0"
73 test_log_in_worktree() {
74 local testroot=`test_init log_in_worktree 1`
76 make_test_tree $testroot/repo
77 mkdir -p $testroot/repo/epsilon/d
78 echo foo > $testroot/repo/epsilon/d/foo
79 (cd $testroot/repo && git add .)
80 git_commit $testroot/repo -m "adding the test tree"
81 local head_commit=`git_show_head $testroot/repo`
83 got checkout $testroot/repo $testroot/wt > /dev/null
85 if [ $ret -ne 0 ]; then
86 test_done "$testroot" "$ret"
90 echo "commit $head_commit (master)" > $testroot/stdout.expected
92 for p in "" "." alpha epsilon; do
93 (cd $testroot/wt && got log $p | \
94 grep ^commit > $testroot/stdout)
95 cmp -s $testroot/stdout.expected $testroot/stdout
97 if [ $ret -ne 0 ]; then
98 diff -u $testroot/stdout.expected $testroot/stdout
99 test_done "$testroot" "$ret"
104 for p in "" "." zeta; do
105 (cd $testroot/wt/epsilon && got log $p | \
106 grep ^commit > $testroot/stdout)
107 cmp -s $testroot/stdout.expected $testroot/stdout
109 if [ $ret -ne 0 ]; then
110 diff -u $testroot/stdout.expected $testroot/stdout
111 test_done "$testroot" "$ret"
116 for p in "" "." foo; do
117 (cd $testroot/wt/epsilon && got log d/$p | \
118 grep ^commit > $testroot/stdout)
119 cmp -s $testroot/stdout.expected $testroot/stdout
121 if [ $ret -ne 0 ]; then
122 diff -u $testroot/stdout.expected $testroot/stdout
123 test_done "$testroot" "$ret"
128 test_done "$testroot" "0"
131 test_log_in_worktree_with_path_prefix() {
132 local testroot=`test_init log_in_prefixed_worktree`
133 local head_rev=`git_show_head $testroot/repo`
135 echo "modified zeta" > $testroot/repo/epsilon/zeta
136 git_commit $testroot/repo -m "modified zeta"
137 local zeta_rev=`git_show_head $testroot/repo`
139 echo "modified delta" > $testroot/repo/gamma/delta
140 git_commit $testroot/repo -m "modified delta"
141 local delta_rev=`git_show_head $testroot/repo`
143 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
145 if [ $ret -ne 0 ]; then
146 test_done "$testroot" "$ret"
150 echo "commit $delta_rev (master)" > $testroot/stdout.expected
151 echo "commit $zeta_rev" >> $testroot/stdout.expected
152 echo "commit $head_rev" >> $testroot/stdout.expected
154 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
155 cmp -s $testroot/stdout.expected $testroot/stdout
157 if [ $ret -ne 0 ]; then
158 diff -u $testroot/stdout.expected $testroot/stdout
159 test_done "$testroot" "$ret"
163 echo "commit $zeta_rev" > $testroot/stdout.expected
164 echo "commit $head_rev" >> $testroot/stdout.expected
166 for p in "." zeta; do
167 (cd $testroot/wt && got log $p | \
168 grep ^commit > $testroot/stdout)
169 cmp -s $testroot/stdout.expected $testroot/stdout
171 if [ $ret -ne 0 ]; then
172 diff -u $testroot/stdout.expected $testroot/stdout
173 test_done "$testroot" "$ret"
178 test_done "$testroot" "0"
182 local testroot=`test_init log_tag`
183 local commit_id=`git_show_head $testroot/repo`
187 got checkout $testroot/repo $testroot/wt > /dev/null
189 if [ $ret -ne 0 ]; then
190 test_done "$testroot" "$ret"
194 (cd $testroot/repo && git tag -a -m "test" $tag)
196 echo "commit $commit_id (master, tags/$tag)" > $testroot/stdout.expected
197 (cd $testroot/wt && got log -l1 -c $tag | grep ^commit \
199 cmp -s $testroot/stdout.expected $testroot/stdout
201 if [ $ret -ne 0 ]; then
202 diff -u $testroot/stdout.expected $testroot/stdout
203 test_done "$testroot" "$ret"
207 # test a "lightweight" tag
208 (cd $testroot/repo && git tag $tag2)
210 echo "commit $commit_id (master, tags/$tag, tags/$tag2)" \
211 > $testroot/stdout.expected
212 (cd $testroot/wt && got log -l1 -c $tag2 | grep ^commit \
214 cmp -s $testroot/stdout.expected $testroot/stdout
216 if [ $ret -ne 0 ]; then
217 diff -u $testroot/stdout.expected $testroot/stdout
219 test_done "$testroot" "$ret"
223 local testroot=`test_init log_limit`
224 local commit_id0=`git_show_head $testroot/repo`
226 got checkout $testroot/repo $testroot/wt > /dev/null
228 if [ $ret -ne 0 ]; then
229 test_done "$testroot" "$ret"
233 echo "modified alpha" > $testroot/wt/alpha
234 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
235 local commit_id1=`git_show_head $testroot/repo`
237 (cd $testroot/wt && got rm beta >/dev/null)
238 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
239 local commit_id2=`git_show_head $testroot/repo`
241 echo "new file" > $testroot/wt/new
242 (cd $testroot/wt && got add new >/dev/null)
243 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
244 local commit_id3=`git_show_head $testroot/repo`
246 # -l1 should print the first commit only
247 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
248 (cd $testroot/wt && got log -l1 | grep ^commit > $testroot/stdout)
249 cmp -s $testroot/stdout.expected $testroot/stdout
251 if [ $ret -ne 0 ]; then
252 diff -u $testroot/stdout.expected $testroot/stdout
253 test_done "$testroot" "$ret"
257 # env var can be used to set a log limit without -l option
258 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
259 echo "commit $commit_id2" >> $testroot/stdout.expected
260 (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=2 got log | \
261 grep ^commit > $testroot/stdout)
262 cmp -s $testroot/stdout.expected $testroot/stdout
264 if [ $ret -ne 0 ]; then
265 diff -u $testroot/stdout.expected $testroot/stdout
266 test_done "$testroot" "$ret"
270 # non-numeric env var is ignored
271 (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=foobar got log | \
272 grep ^commit > $testroot/stdout)
273 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
274 echo "commit $commit_id2" >> $testroot/stdout.expected
275 echo "commit $commit_id1" >> $testroot/stdout.expected
276 echo "commit $commit_id0" >> $testroot/stdout.expected
277 cmp -s $testroot/stdout.expected $testroot/stdout
279 if [ $ret -ne 0 ]; then
280 diff -u $testroot/stdout.expected $testroot/stdout
281 test_done "$testroot" "$ret"
285 # -l option takes precedence over env var
286 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
287 echo "commit $commit_id2" >> $testroot/stdout.expected
288 echo "commit $commit_id1" >> $testroot/stdout.expected
289 echo "commit $commit_id0" >> $testroot/stdout.expected
290 (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=1 got log -l0 | \
291 grep ^commit > $testroot/stdout)
292 cmp -s $testroot/stdout.expected $testroot/stdout
294 if [ $ret -ne 0 ]; then
295 diff -u $testroot/stdout.expected $testroot/stdout
297 test_done "$testroot" "0"
301 local testroot=`test_init log_oneline`
302 local commit_id0=`git_show_head $testroot/repo`
303 got checkout $testroot/repo $testroot/wt > /dev/null
305 if [ $ret -ne 0 ]; then
306 test_done "$testroot" "$ret"
310 echo "modified alpha" > $testroot/wt/alpha
311 (cd $testroot/wt && got commit -m "test oneline
313 local commit_id1=`git_show_head $testroot/repo`
314 local author_time1=`git_show_author_time $testroot/repo`
316 echo "modified beta" > $testroot/wt/beta
317 (cd $testroot/wt && got commit -m " test oneline
319 local commit_id2=`git_show_head $testroot/repo`
320 local author_time2=`git_show_author_time $testroot/repo`
322 d=`date -u -r $author_time1 +"%G-%m-%d"`
323 printf "$d %-7s test oneline\n" master > $testroot/stdout.expected
324 d=`date -u -r $author_time2 +"%G-%m-%d"`
325 printf "$d %.7s test oneline\n" $commit_id1 >> $testroot/stdout.expected
327 (cd $testroot/repo && got log -s | head -n 2 > $testroot/stdout)
328 cmp -s $testroot/stdout.expected $testroot/stdout
330 if [ $ret -ne 0 ]; then
331 diff -u $testroot/stdout.expected $testroot/stdout
332 test_done "$testroot" "$ret"
335 test_done "$testroot" "0"
338 test_log_patch_added_file() {
339 local testroot=`test_init log_patch_added_file`
340 local commit_id0=`git_show_head $testroot/repo`
342 got checkout $testroot/repo $testroot/wt > /dev/null
344 if [ $ret -ne 0 ]; then
345 test_done "$testroot" "$ret"
349 echo "new file" > $testroot/wt/new
350 (cd $testroot/wt && got add new >/dev/null)
351 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
352 local commit_id1=`git_show_head $testroot/repo`
354 echo "commit $commit_id1 (master)" > $testroot/stdout.expected
355 # This used to fail with 'got: no such entry found in tree'
356 (cd $testroot/wt && got log -l1 -p new > $testroot/stdout.patch)
358 if [ $ret -ne 0 ]; then
359 echo "got log command failed unexpectedly" >&2
360 test_done "$testroot" "$ret"
363 grep ^commit $testroot/stdout.patch > $testroot/stdout
364 cmp -s $testroot/stdout.expected $testroot/stdout
366 if [ $ret -ne 0 ]; then
367 diff -u $testroot/stdout.expected $testroot/stdout
369 test_done "$testroot" "$ret"
372 test_log_nonexistent_path() {
373 local testroot=`test_init log_nonexistent_path`
374 local head_rev=`git_show_head $testroot/repo`
376 echo "commit $head_rev (master)" > $testroot/stdout.expected
378 (cd $testroot/repo && got log this/does/not/exist \
379 > $testroot/stdout 2> $testroot/stderr)
381 if [ $ret -eq 0 ]; then
382 echo "log command succeeded unexpectedly" >&2
383 test_done "$testroot" "1"
387 echo -n > $testroot/stdout.expected
388 cmp -s $testroot/stdout.expected $testroot/stdout
390 if [ $ret -ne 0 ]; then
391 diff -u $testroot/stdout.expected $testroot/stdout
392 test_done "$testroot" "$ret"
396 echo "got: this/does/not/exist: no such entry found in tree" \
397 > $testroot/stderr.expected
398 cmp -s $testroot/stderr.expected $testroot/stderr
400 if [ $ret -ne 0 ]; then
401 diff -u $testroot/stderr.expected $testroot/stderr
403 test_done "$testroot" "$ret"
406 test_log_end_at_commit() {
407 local testroot=`test_init log_end_at_commit`
408 local commit_id0=`git_show_head $testroot/repo`
410 got checkout $testroot/repo $testroot/wt > /dev/null
412 if [ $ret -ne 0 ]; then
413 test_done "$testroot" "$ret"
417 echo "modified alpha" > $testroot/wt/alpha
418 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
419 local commit_id1=`git_show_head $testroot/repo`
421 (cd $testroot/wt && got rm beta >/dev/null)
422 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
423 local commit_id2=`git_show_head $testroot/repo`
425 echo "new file" > $testroot/wt/new
426 (cd $testroot/wt && got add new >/dev/null)
427 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
428 local commit_id3=`git_show_head $testroot/repo`
430 # Print commit 3 only
431 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
432 (cd $testroot/wt && got log -x $commit_id3 | grep ^commit \
434 cmp -s $testroot/stdout.expected $testroot/stdout
436 if [ $ret -ne 0 ]; then
437 diff -u $testroot/stdout.expected $testroot/stdout
438 test_done "$testroot" "$ret"
442 # Print commit 3 up to commit 1 inclusive
443 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
444 echo "commit $commit_id2" >> $testroot/stdout.expected
445 echo "commit $commit_id1" >> $testroot/stdout.expected
446 (cd $testroot/wt && got log -c $commit_id3 -x $commit_id1 | \
447 grep ^commit > $testroot/stdout)
448 cmp -s $testroot/stdout.expected $testroot/stdout
450 if [ $ret -ne 0 ]; then
451 diff -u $testroot/stdout.expected $testroot/stdout
452 test_done "$testroot" "$ret"
456 # Create commits on an unrelated branch
457 (cd $testroot/wt && got br foo > /dev/null)
458 echo bar >> $testroot/wt/alpha
459 (cd $testroot/wt && got commit -m "change on branch foo" >/dev/null)
460 local commit_id4=`git_show_branch_head $testroot/repo foo`
462 # Print commit 4 only (in work tree)
463 echo "commit $commit_id4 (foo)" > $testroot/stdout.expected
464 (cd $testroot/wt && got log -x foo | grep ^commit \
466 cmp -s $testroot/stdout.expected $testroot/stdout
468 if [ $ret -ne 0 ]; then
469 diff -u $testroot/stdout.expected $testroot/stdout
470 test_done "$testroot" "$ret"
474 # Print commit 4 only (in repository)
475 echo "commit $commit_id4 (foo)" > $testroot/stdout.expected
476 (cd $testroot/repo && got log -c foo -x foo | grep ^commit \
478 cmp -s $testroot/stdout.expected $testroot/stdout
480 if [ $ret -ne 0 ]; then
481 diff -u $testroot/stdout.expected $testroot/stdout
482 test_done "$testroot" "$ret"
486 # Repository's HEAD is on master branch so -x foo without an explicit
487 # '-c foo' start commit has no effect there
488 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
489 echo "commit $commit_id2" >> $testroot/stdout.expected
490 echo "commit $commit_id1" >> $testroot/stdout.expected
491 echo "commit $commit_id0" >> $testroot/stdout.expected
492 (cd $testroot/repo && got log -x foo | grep ^commit \
494 cmp -s $testroot/stdout.expected $testroot/stdout
496 if [ $ret -ne 0 ]; then
497 diff -u $testroot/stdout.expected $testroot/stdout
498 test_done "$testroot" "$ret"
502 # got will refuse -x with a non-existent commit
503 (cd $testroot/wt && got log -x nonexistent \
504 > $testroot/stdout 2> $testroot/stderr)
506 if [ $ret -eq 0 ]; then
507 echo "log command succeeded unexpectedly" >&2
508 test_done "$testroot" "1"
511 echo -n > $testroot/stdout.expected
512 echo "got: reference nonexistent not found" \
513 > $testroot/stderr.expected
514 cmp -s $testroot/stderr.expected $testroot/stderr
516 if [ $ret -ne 0 ]; then
517 diff -u $testroot/stderr.expected $testroot/stderr
518 test_done "$testroot" "$ret"
521 cmp -s $testroot/stdout.expected $testroot/stdout
523 if [ $ret -ne 0 ]; then
524 diff -u $testroot/stdout.expected $testroot/stdout
525 test_done "$testroot" "$ret"
529 # try the same with the hash of an empty string which is very
530 # unlikely to match any object
531 local empty_sha1=da39a3ee5e6b4b0d3255bfef95601890afd80709
532 (cd $testroot/wt && got log -x $empty_sha1 \
533 > $testroot/stdout 2> $testroot/stderr)
535 if [ $ret -eq 0 ]; then
536 echo "log command succeeded unexpectedly" >&2
537 test_done "$testroot" "1"
540 echo -n > $testroot/stdout.expected
541 echo "got: commit $empty_sha1: object not found" \
542 > $testroot/stderr.expected
543 cmp -s $testroot/stderr.expected $testroot/stderr
545 if [ $ret -ne 0 ]; then
546 diff -u $testroot/stderr.expected $testroot/stderr
547 test_done "$testroot" "$ret"
550 cmp -s $testroot/stdout.expected $testroot/stdout
552 if [ $ret -ne 0 ]; then
553 diff -u $testroot/stdout.expected $testroot/stdout
554 test_done "$testroot" "$ret"
558 test_done "$testroot" "0"
561 test_log_reverse_display() {
562 local testroot=`test_init log_reverse_display`
563 local commit_id0=`git_show_head $testroot/repo`
565 got checkout $testroot/repo $testroot/wt > /dev/null
567 if [ $ret -ne 0 ]; then
568 test_done "$testroot" "$ret"
572 echo "modified alpha" > $testroot/wt/alpha
573 (cd $testroot/wt && got commit -m 'commit1' > /dev/null)
574 local commit_id1=`git_show_head $testroot/repo`
576 (cd $testroot/wt && got rm beta >/dev/null)
577 (cd $testroot/wt && got commit -m 'commit2' > /dev/null)
578 local commit_id2=`git_show_head $testroot/repo`
580 echo "new file" > $testroot/wt/new
581 (cd $testroot/wt && got add new >/dev/null)
582 (cd $testroot/wt && got commit -m 'commit3' > /dev/null)
583 local commit_id3=`git_show_head $testroot/repo`
585 # -R alone should display all commits in reverse
586 echo "commit $commit_id0" > $testroot/stdout.expected
587 echo "commit $commit_id1" >> $testroot/stdout.expected
588 echo "commit $commit_id2" >> $testroot/stdout.expected
589 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
590 (cd $testroot/wt && got log -R | grep ^commit > $testroot/stdout)
591 cmp -s $testroot/stdout.expected $testroot/stdout
593 if [ $ret -ne 0 ]; then
594 diff -u $testroot/stdout.expected $testroot/stdout
595 test_done "$testroot" "$ret"
599 # -R takes effect after the -l commit traversal limit
600 echo "commit $commit_id2" > $testroot/stdout.expected
601 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
602 (cd $testroot/wt && got log -R -l2 | grep ^commit > $testroot/stdout)
603 cmp -s $testroot/stdout.expected $testroot/stdout
605 if [ $ret -ne 0 ]; then
606 diff -u $testroot/stdout.expected $testroot/stdout
607 test_done "$testroot" "$ret"
611 # -R works with commit ranges specified via -c and -x
612 echo "commit $commit_id1" > $testroot/stdout.expected
613 echo "commit $commit_id2" >> $testroot/stdout.expected
614 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
615 (cd $testroot/wt && got log -R -c $commit_id3 -x $commit_id1 | \
616 grep ^commit > $testroot/stdout)
617 cmp -s $testroot/stdout.expected $testroot/stdout
619 if [ $ret -ne 0 ]; then
620 diff -u $testroot/stdout.expected $testroot/stdout
621 test_done "$testroot" "$ret"
625 # commit matching with -s applies before -R
626 echo "commit $commit_id1" > $testroot/stdout.expected
627 echo "commit $commit_id2" >> $testroot/stdout.expected
628 (cd $testroot/wt && got log -R -S 'commit[12]' | \
629 grep ^commit > $testroot/stdout)
630 cmp -s $testroot/stdout.expected $testroot/stdout
632 if [ $ret -ne 0 ]; then
633 diff -u $testroot/stdout.expected $testroot/stdout
634 test_done "$testroot" "$ret"
638 # -R works in combination with -P
639 echo "" > $testroot/stdout.expected
640 (cd $testroot/wt && got log -R -P | grep -E '^(commit| [MDmA])' \
642 echo "commit $commit_id0" > $testroot/stdout.expected
643 echo " A alpha" >> $testroot/stdout.expected
644 echo " A beta" >> $testroot/stdout.expected
645 echo " A epsilon/zeta" >> $testroot/stdout.expected
646 echo " A gamma/delta" >> $testroot/stdout.expected
647 echo "commit $commit_id1" >> $testroot/stdout.expected
648 echo " M alpha" >> $testroot/stdout.expected
649 echo "commit $commit_id2" >> $testroot/stdout.expected
650 echo " D beta" >> $testroot/stdout.expected
651 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
652 echo " A new" >> $testroot/stdout.expected
653 cmp -s $testroot/stdout.expected $testroot/stdout
655 if [ $ret -ne 0 ]; then
656 diff -u $testroot/stdout.expected $testroot/stdout
658 test_done "$testroot" "$ret"
661 test_log_in_worktree_different_repo() {
662 local testroot=`test_init log_in_worktree_different_repo 1`
664 make_test_tree $testroot/repo
665 mkdir -p $testroot/repo/epsilon/d
666 echo foo > $testroot/repo/epsilon/d/foo
667 (cd $testroot/repo && git add .)
668 git_commit $testroot/repo -m "adding the test tree"
669 local head_commit=`git_show_head $testroot/repo`
671 got init $testroot/other-repo
672 mkdir -p $testroot/tree
673 make_test_tree $testroot/tree
674 got import -mm -b foo -r $testroot/other-repo $testroot/tree >/dev/null
675 got checkout -b foo $testroot/other-repo $testroot/wt > /dev/null
677 if [ $ret -ne 0 ]; then
678 test_done "$testroot" "$ret"
682 echo "commit $head_commit (master)" > $testroot/stdout.expected
684 # 'got log' used to fail with "reference refs/heads/foo not found"
685 # even though that reference belongs to an unrelated repository
686 # found via a worktree via the current working directory
687 for p in "" alpha epsilon; do
688 (cd $testroot/wt && got log -r $testroot/repo $p | \
689 grep ^commit > $testroot/stdout)
690 cmp -s $testroot/stdout.expected $testroot/stdout
692 if [ $ret -ne 0 ]; then
693 diff -u $testroot/stdout.expected $testroot/stdout
694 test_done "$testroot" "$ret"
699 for p in "" epsilon/zeta; do
700 (cd $testroot/wt/epsilon && got log -r $testroot/repo $p | \
701 grep ^commit > $testroot/stdout)
702 cmp -s $testroot/stdout.expected $testroot/stdout
704 if [ $ret -ne 0 ]; then
705 diff -u $testroot/stdout.expected $testroot/stdout
706 test_done "$testroot" "$ret"
712 (cd $testroot/wt/epsilon && got log -r $testroot/repo epsilon/d/$p | \
713 grep ^commit > $testroot/stdout)
714 cmp -s $testroot/stdout.expected $testroot/stdout
716 if [ $ret -ne 0 ]; then
717 diff -u $testroot/stdout.expected $testroot/stdout
718 test_done "$testroot" "$ret"
723 test_done "$testroot" "0"
726 test_log_changed_paths() {
727 local testroot=`test_init log_changed_paths`
728 local commit_id0=`git_show_head $testroot/repo`
730 got checkout $testroot/repo $testroot/wt > /dev/null
732 if [ $ret -ne 0 ]; then
733 test_done "$testroot" "$ret"
737 echo "modified alpha" > $testroot/wt/alpha
738 (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
739 local commit_id1=`git_show_head $testroot/repo`
741 (cd $testroot/wt && got rm beta >/dev/null)
742 (cd $testroot/wt && chmod +x epsilon/zeta >/dev/null)
743 (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
744 local commit_id2=`git_show_head $testroot/repo`
746 echo "new file" > $testroot/wt/new
747 (cd $testroot/wt && got add new >/dev/null)
748 (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
749 local commit_id3=`git_show_head $testroot/repo`
751 (cd $testroot/wt && got log -P | grep '^ [MDmA]' > $testroot/stdout)
753 echo " A new" > $testroot/stdout.expected
754 echo " D beta" >> $testroot/stdout.expected
755 echo " m epsilon/zeta" >> $testroot/stdout.expected
756 echo " M alpha" >> $testroot/stdout.expected
757 echo " A alpha" >> $testroot/stdout.expected
758 echo " A beta" >> $testroot/stdout.expected
759 echo " A epsilon/zeta" >> $testroot/stdout.expected
760 echo " A gamma/delta" >> $testroot/stdout.expected
762 cmp -s $testroot/stdout.expected $testroot/stdout
764 if [ $ret -ne 0 ]; then
765 diff -u $testroot/stdout.expected $testroot/stdout
767 test_done "$testroot" "$ret"
770 test_log_submodule() {
771 local testroot=`test_init log_submodule`
773 make_single_file_repo $testroot/repo2 foo
775 (cd $testroot/repo && git submodule -q add ../repo2)
776 (cd $testroot/repo && git commit -q -m 'adding submodule')
777 local head_commit=`git_show_head $testroot/repo`
779 echo "commit $head_commit (master)" > $testroot/stdout.expected
781 got log -r $testroot/repo -l1 repo2 | grep ^commit > $testroot/stdout
782 cmp -s $testroot/stdout.expected $testroot/stdout
784 if [ $ret -ne 0 ]; then
785 diff -u $testroot/stdout.expected $testroot/stdout
786 test_done "$testroot" "$ret"
790 echo " A .gitmodules" > $testroot/stdout.expected
792 got log -r $testroot/repo -l1 -P repo2 | grep '^ [MDmA]' \
794 cmp -s $testroot/stdout.expected $testroot/stdout
796 if [ $ret -ne 0 ]; then
797 diff -u $testroot/stdout.expected $testroot/stdout
798 test_done "$testroot" "$ret"
802 got log -p -r $testroot/repo -l1 repo2 \
803 > $testroot/stdout 2> $testroot/stderr
805 if [ $ret -eq 0 ]; then
806 echo "log command succeeded unexpectedly" >&2
807 test_done "$testroot" "1"
810 local submodule_id=$(got tree -r $testroot/repo -i | \
811 grep 'repo2\$$' | cut -d ' ' -f1)
812 echo "got: object $submodule_id not found" > $testroot/stderr.expected
814 cmp -s $testroot/stderr.expected $testroot/stderr
816 if [ $ret -ne 0 ]; then
817 diff -u $testroot/stderr.expected $testroot/stderr
818 test_done "$testroot" "$ret"
822 echo "modified foo" > $testroot/repo2/foo
823 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
825 # Update the repo/repo2 submodule link
826 (cd $testroot/repo && git -C repo2 pull -q)
827 (cd $testroot/repo && git add repo2)
828 git_commit $testroot/repo -m "changed submodule link"
830 # log -P does not show the changed submodule path
831 got log -P -r $testroot/repo -l1 repo2 > $testroot/stdout.full
833 if [ $ret -ne 0 ]; then
834 echo "log command failed unexpectedly" >&2
835 test_done "$testroot" "1"
838 grep '^ [MDmA]' $testroot/stdout.full > $testroot/stdout
840 echo -n > $testroot/stdout.expected
841 cmp -s $testroot/stdout.expected $testroot/stdout
843 if [ $ret -ne 0 ]; then
844 diff -u $testroot/stdout.expected $testroot/stdout
846 test_done "$testroot" "$ret"
850 run_test test_log_in_repo
851 run_test test_log_in_bare_repo
852 run_test test_log_in_worktree
853 run_test test_log_in_worktree_with_path_prefix
854 run_test test_log_tag
855 run_test test_log_limit
856 run_test test_log_oneline
857 run_test test_log_patch_added_file
858 run_test test_log_nonexistent_path
859 run_test test_log_end_at_commit
860 run_test test_log_reverse_display
861 run_test test_log_in_worktree_different_repo
862 run_test test_log_changed_paths
863 run_test test_log_submodule