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`
315 echo "modified beta" > $testroot/wt/beta
316 (cd $testroot/wt && got commit -m " test oneline
318 local commit_id2=`git_show_head $testroot/repo`
320 printf "%.7s test oneline\n" $commit_id2 > $testroot/stdout.expected
321 printf "%.7s test oneline\n" $commit_id1 >> $testroot/stdout.expected
323 (cd $testroot/repo && got log -s | head -n 2 > $testroot/stdout)
324 cmp -s $testroot/stdout.expected $testroot/stdout
326 if [ $ret -ne 0 ]; then
327 diff -u $testroot/stdout.expected $testroot/stdout
328 test_done "$testroot" "$ret"
331 test_done "$testroot" "0"
334 test_log_patch_added_file() {
335 local testroot=`test_init log_patch_added_file`
336 local commit_id0=`git_show_head $testroot/repo`
338 got checkout $testroot/repo $testroot/wt > /dev/null
340 if [ $ret -ne 0 ]; then
341 test_done "$testroot" "$ret"
345 echo "new file" > $testroot/wt/new
346 (cd $testroot/wt && got add new >/dev/null)
347 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
348 local commit_id1=`git_show_head $testroot/repo`
350 echo "commit $commit_id1 (master)" > $testroot/stdout.expected
351 # This used to fail with 'got: no such entry found in tree'
352 (cd $testroot/wt && got log -l1 -p new > $testroot/stdout.patch)
354 if [ $ret -ne 0 ]; then
355 echo "got log command failed unexpectedly" >&2
356 test_done "$testroot" "$ret"
359 grep ^commit $testroot/stdout.patch > $testroot/stdout
360 cmp -s $testroot/stdout.expected $testroot/stdout
362 if [ $ret -ne 0 ]; then
363 diff -u $testroot/stdout.expected $testroot/stdout
365 test_done "$testroot" "$ret"
368 test_log_nonexistent_path() {
369 local testroot=`test_init log_nonexistent_path`
370 local head_rev=`git_show_head $testroot/repo`
372 echo "commit $head_rev (master)" > $testroot/stdout.expected
374 (cd $testroot/repo && got log this/does/not/exist \
375 > $testroot/stdout 2> $testroot/stderr)
377 if [ $ret -eq 0 ]; then
378 echo "log command succeeded unexpectedly" >&2
379 test_done "$testroot" "1"
383 echo -n > $testroot/stdout.expected
384 cmp -s $testroot/stdout.expected $testroot/stdout
386 if [ $ret -ne 0 ]; then
387 diff -u $testroot/stdout.expected $testroot/stdout
388 test_done "$testroot" "$ret"
392 echo "got: this/does/not/exist: no such entry found in tree" \
393 > $testroot/stderr.expected
394 cmp -s $testroot/stderr.expected $testroot/stderr
396 if [ $ret -ne 0 ]; then
397 diff -u $testroot/stderr.expected $testroot/stderr
399 test_done "$testroot" "$ret"
402 test_log_end_at_commit() {
403 local testroot=`test_init log_end_at_commit`
404 local commit_id0=`git_show_head $testroot/repo`
406 got checkout $testroot/repo $testroot/wt > /dev/null
408 if [ $ret -ne 0 ]; then
409 test_done "$testroot" "$ret"
413 echo "modified alpha" > $testroot/wt/alpha
414 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
415 local commit_id1=`git_show_head $testroot/repo`
417 (cd $testroot/wt && got rm beta >/dev/null)
418 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
419 local commit_id2=`git_show_head $testroot/repo`
421 echo "new file" > $testroot/wt/new
422 (cd $testroot/wt && got add new >/dev/null)
423 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
424 local commit_id3=`git_show_head $testroot/repo`
426 # Print commit 3 only
427 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
428 (cd $testroot/wt && got log -x $commit_id3 | grep ^commit \
430 cmp -s $testroot/stdout.expected $testroot/stdout
432 if [ $ret -ne 0 ]; then
433 diff -u $testroot/stdout.expected $testroot/stdout
434 test_done "$testroot" "$ret"
438 # Print commit 3 up to commit 1 inclusive
439 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
440 echo "commit $commit_id2" >> $testroot/stdout.expected
441 echo "commit $commit_id1" >> $testroot/stdout.expected
442 (cd $testroot/wt && got log -c $commit_id3 -x $commit_id1 | \
443 grep ^commit > $testroot/stdout)
444 cmp -s $testroot/stdout.expected $testroot/stdout
446 if [ $ret -ne 0 ]; then
447 diff -u $testroot/stdout.expected $testroot/stdout
448 test_done "$testroot" "$ret"
452 # Create commits on an unrelated branch
453 (cd $testroot/wt && got br foo > /dev/null)
454 echo bar >> $testroot/wt/alpha
455 (cd $testroot/wt && got commit -m "change on branch foo" >/dev/null)
456 local commit_id4=`git_show_branch_head $testroot/repo foo`
458 # Print commit 4 only (in work tree)
459 echo "commit $commit_id4 (foo)" > $testroot/stdout.expected
460 (cd $testroot/wt && got log -x foo | grep ^commit \
462 cmp -s $testroot/stdout.expected $testroot/stdout
464 if [ $ret -ne 0 ]; then
465 diff -u $testroot/stdout.expected $testroot/stdout
466 test_done "$testroot" "$ret"
470 # Print commit 4 only (in repository)
471 echo "commit $commit_id4 (foo)" > $testroot/stdout.expected
472 (cd $testroot/repo && got log -c foo -x foo | grep ^commit \
474 cmp -s $testroot/stdout.expected $testroot/stdout
476 if [ $ret -ne 0 ]; then
477 diff -u $testroot/stdout.expected $testroot/stdout
478 test_done "$testroot" "$ret"
482 # Repository's HEAD is on master branch so -x foo without an explicit
483 # '-c foo' start commit has no effect there
484 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
485 echo "commit $commit_id2" >> $testroot/stdout.expected
486 echo "commit $commit_id1" >> $testroot/stdout.expected
487 echo "commit $commit_id0" >> $testroot/stdout.expected
488 (cd $testroot/repo && got log -x foo | grep ^commit \
490 cmp -s $testroot/stdout.expected $testroot/stdout
492 if [ $ret -ne 0 ]; then
493 diff -u $testroot/stdout.expected $testroot/stdout
494 test_done "$testroot" "$ret"
498 # got will refuse -x with a non-existent commit
499 (cd $testroot/wt && got log -x nonexistent \
500 > $testroot/stdout 2> $testroot/stderr)
502 if [ $ret -eq 0 ]; then
503 echo "log command succeeded unexpectedly" >&2
504 test_done "$testroot" "1"
507 echo -n > $testroot/stdout.expected
508 echo "got: reference nonexistent not found" \
509 > $testroot/stderr.expected
510 cmp -s $testroot/stderr.expected $testroot/stderr
512 if [ $ret -ne 0 ]; then
513 diff -u $testroot/stderr.expected $testroot/stderr
514 test_done "$testroot" "$ret"
517 cmp -s $testroot/stdout.expected $testroot/stdout
519 if [ $ret -ne 0 ]; then
520 diff -u $testroot/stdout.expected $testroot/stdout
521 test_done "$testroot" "$ret"
525 # try the same with the hash of an empty string which is very
526 # unlikely to match any object
527 local empty_sha1=da39a3ee5e6b4b0d3255bfef95601890afd80709
528 (cd $testroot/wt && got log -x $empty_sha1 \
529 > $testroot/stdout 2> $testroot/stderr)
531 if [ $ret -eq 0 ]; then
532 echo "log command succeeded unexpectedly" >&2
533 test_done "$testroot" "1"
536 echo -n > $testroot/stdout.expected
537 echo "got: commit $empty_sha1: object not found" \
538 > $testroot/stderr.expected
539 cmp -s $testroot/stderr.expected $testroot/stderr
541 if [ $ret -ne 0 ]; then
542 diff -u $testroot/stderr.expected $testroot/stderr
543 test_done "$testroot" "$ret"
546 cmp -s $testroot/stdout.expected $testroot/stdout
548 if [ $ret -ne 0 ]; then
549 diff -u $testroot/stdout.expected $testroot/stdout
550 test_done "$testroot" "$ret"
554 test_done "$testroot" "0"
557 test_log_reverse_display() {
558 local testroot=`test_init log_reverse_display`
559 local commit_id0=`git_show_head $testroot/repo`
561 got checkout $testroot/repo $testroot/wt > /dev/null
563 if [ $ret -ne 0 ]; then
564 test_done "$testroot" "$ret"
568 echo "modified alpha" > $testroot/wt/alpha
569 (cd $testroot/wt && got commit -m 'commit1' > /dev/null)
570 local commit_id1=`git_show_head $testroot/repo`
572 (cd $testroot/wt && got rm beta >/dev/null)
573 (cd $testroot/wt && got commit -m 'commit2' > /dev/null)
574 local commit_id2=`git_show_head $testroot/repo`
576 echo "new file" > $testroot/wt/new
577 (cd $testroot/wt && got add new >/dev/null)
578 (cd $testroot/wt && got commit -m 'commit3' > /dev/null)
579 local commit_id3=`git_show_head $testroot/repo`
581 # -R alone should display all commits in reverse
582 echo "commit $commit_id0" > $testroot/stdout.expected
583 echo "commit $commit_id1" >> $testroot/stdout.expected
584 echo "commit $commit_id2" >> $testroot/stdout.expected
585 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
586 (cd $testroot/wt && got log -R | grep ^commit > $testroot/stdout)
587 cmp -s $testroot/stdout.expected $testroot/stdout
589 if [ $ret -ne 0 ]; then
590 diff -u $testroot/stdout.expected $testroot/stdout
591 test_done "$testroot" "$ret"
595 # -R takes effect after the -l commit traversal limit
596 echo "commit $commit_id2" > $testroot/stdout.expected
597 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
598 (cd $testroot/wt && got log -R -l2 | grep ^commit > $testroot/stdout)
599 cmp -s $testroot/stdout.expected $testroot/stdout
601 if [ $ret -ne 0 ]; then
602 diff -u $testroot/stdout.expected $testroot/stdout
603 test_done "$testroot" "$ret"
607 # -R works with commit ranges specified via -c and -x
608 echo "commit $commit_id1" > $testroot/stdout.expected
609 echo "commit $commit_id2" >> $testroot/stdout.expected
610 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
611 (cd $testroot/wt && got log -R -c $commit_id3 -x $commit_id1 | \
612 grep ^commit > $testroot/stdout)
613 cmp -s $testroot/stdout.expected $testroot/stdout
615 if [ $ret -ne 0 ]; then
616 diff -u $testroot/stdout.expected $testroot/stdout
617 test_done "$testroot" "$ret"
621 # commit matching with -s applies before -R
622 echo "commit $commit_id1" > $testroot/stdout.expected
623 echo "commit $commit_id2" >> $testroot/stdout.expected
624 (cd $testroot/wt && got log -R -S 'commit[12]' | \
625 grep ^commit > $testroot/stdout)
626 cmp -s $testroot/stdout.expected $testroot/stdout
628 if [ $ret -ne 0 ]; then
629 diff -u $testroot/stdout.expected $testroot/stdout
630 test_done "$testroot" "$ret"
634 # -R works in combination with -P
635 echo "" > $testroot/stdout.expected
636 (cd $testroot/wt && got log -R -P | grep -E '^(commit| [MDmA])' \
638 echo "commit $commit_id0" > $testroot/stdout.expected
639 echo " A alpha" >> $testroot/stdout.expected
640 echo " A beta" >> $testroot/stdout.expected
641 echo " A epsilon/zeta" >> $testroot/stdout.expected
642 echo " A gamma/delta" >> $testroot/stdout.expected
643 echo "commit $commit_id1" >> $testroot/stdout.expected
644 echo " M alpha" >> $testroot/stdout.expected
645 echo "commit $commit_id2" >> $testroot/stdout.expected
646 echo " D beta" >> $testroot/stdout.expected
647 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
648 echo " A new" >> $testroot/stdout.expected
649 cmp -s $testroot/stdout.expected $testroot/stdout
651 if [ $ret -ne 0 ]; then
652 diff -u $testroot/stdout.expected $testroot/stdout
654 test_done "$testroot" "$ret"
657 test_log_in_worktree_different_repo() {
658 local testroot=`test_init log_in_worktree_different_repo 1`
660 make_test_tree $testroot/repo
661 mkdir -p $testroot/repo/epsilon/d
662 echo foo > $testroot/repo/epsilon/d/foo
663 (cd $testroot/repo && git add .)
664 git_commit $testroot/repo -m "adding the test tree"
665 local head_commit=`git_show_head $testroot/repo`
667 got init $testroot/other-repo
668 mkdir -p $testroot/tree
669 make_test_tree $testroot/tree
670 got import -mm -b foo -r $testroot/other-repo $testroot/tree >/dev/null
671 got checkout -b foo $testroot/other-repo $testroot/wt > /dev/null
673 if [ $ret -ne 0 ]; then
674 test_done "$testroot" "$ret"
678 echo "commit $head_commit (master)" > $testroot/stdout.expected
680 # 'got log' used to fail with "reference refs/heads/foo not found"
681 # even though that reference belongs to an unrelated repository
682 # found via a worktree via the current working directory
683 for p in "" alpha epsilon; do
684 (cd $testroot/wt && got log -r $testroot/repo $p | \
685 grep ^commit > $testroot/stdout)
686 cmp -s $testroot/stdout.expected $testroot/stdout
688 if [ $ret -ne 0 ]; then
689 diff -u $testroot/stdout.expected $testroot/stdout
690 test_done "$testroot" "$ret"
695 for p in "" epsilon/zeta; do
696 (cd $testroot/wt/epsilon && got log -r $testroot/repo $p | \
697 grep ^commit > $testroot/stdout)
698 cmp -s $testroot/stdout.expected $testroot/stdout
700 if [ $ret -ne 0 ]; then
701 diff -u $testroot/stdout.expected $testroot/stdout
702 test_done "$testroot" "$ret"
708 (cd $testroot/wt/epsilon && got log -r $testroot/repo epsilon/d/$p | \
709 grep ^commit > $testroot/stdout)
710 cmp -s $testroot/stdout.expected $testroot/stdout
712 if [ $ret -ne 0 ]; then
713 diff -u $testroot/stdout.expected $testroot/stdout
714 test_done "$testroot" "$ret"
719 test_done "$testroot" "0"
722 test_log_changed_paths() {
723 local testroot=`test_init log_changed_paths`
724 local commit_id0=`git_show_head $testroot/repo`
726 got checkout $testroot/repo $testroot/wt > /dev/null
728 if [ $ret -ne 0 ]; then
729 test_done "$testroot" "$ret"
733 echo "modified alpha" > $testroot/wt/alpha
734 (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
735 local commit_id1=`git_show_head $testroot/repo`
737 (cd $testroot/wt && got rm beta >/dev/null)
738 (cd $testroot/wt && chmod +x epsilon/zeta >/dev/null)
739 (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
740 local commit_id2=`git_show_head $testroot/repo`
742 echo "new file" > $testroot/wt/new
743 (cd $testroot/wt && got add new >/dev/null)
744 (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
745 local commit_id3=`git_show_head $testroot/repo`
747 (cd $testroot/wt && got log -P | grep '^ [MDmA]' > $testroot/stdout)
749 echo " A new" > $testroot/stdout.expected
750 echo " D beta" >> $testroot/stdout.expected
751 echo " m epsilon/zeta" >> $testroot/stdout.expected
752 echo " M alpha" >> $testroot/stdout.expected
753 echo " A alpha" >> $testroot/stdout.expected
754 echo " A beta" >> $testroot/stdout.expected
755 echo " A epsilon/zeta" >> $testroot/stdout.expected
756 echo " A gamma/delta" >> $testroot/stdout.expected
758 cmp -s $testroot/stdout.expected $testroot/stdout
760 if [ $ret -ne 0 ]; then
761 diff -u $testroot/stdout.expected $testroot/stdout
763 test_done "$testroot" "$ret"
766 test_log_submodule() {
767 local testroot=`test_init log_submodule`
769 make_single_file_repo $testroot/repo2 foo
771 (cd $testroot/repo && git submodule -q add ../repo2)
772 (cd $testroot/repo && git commit -q -m 'adding submodule')
773 local head_commit=`git_show_head $testroot/repo`
775 echo "commit $head_commit (master)" > $testroot/stdout.expected
777 got log -r $testroot/repo -l1 repo2 | grep ^commit > $testroot/stdout
778 cmp -s $testroot/stdout.expected $testroot/stdout
780 if [ $ret -ne 0 ]; then
781 diff -u $testroot/stdout.expected $testroot/stdout
782 test_done "$testroot" "$ret"
786 echo " A .gitmodules" > $testroot/stdout.expected
788 got log -r $testroot/repo -l1 -P repo2 | grep '^ [MDmA]' \
790 cmp -s $testroot/stdout.expected $testroot/stdout
792 if [ $ret -ne 0 ]; then
793 diff -u $testroot/stdout.expected $testroot/stdout
794 test_done "$testroot" "$ret"
798 got log -p -r $testroot/repo -l1 repo2 \
799 > $testroot/stdout 2> $testroot/stderr
801 if [ $ret -eq 0 ]; then
802 echo "log command succeeded unexpectedly" >&2
803 test_done "$testroot" "1"
806 local submodule_id=$(got tree -r $testroot/repo -i | \
807 grep 'repo2\$$' | cut -d ' ' -f1)
808 echo "got: object $submodule_id not found" > $testroot/stderr.expected
810 cmp -s $testroot/stderr.expected $testroot/stderr
812 if [ $ret -ne 0 ]; then
813 diff -u $testroot/stderr.expected $testroot/stderr
814 test_done "$testroot" "$ret"
818 echo "modified foo" > $testroot/repo2/foo
819 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
821 # Update the repo/repo2 submodule link
822 (cd $testroot/repo && git -C repo2 pull -q)
823 (cd $testroot/repo && git add repo2)
824 git_commit $testroot/repo -m "changed submodule link"
826 # log -P does not show the changed submodule path
827 got log -P -r $testroot/repo -l1 repo2 > $testroot/stdout.full
829 if [ $ret -ne 0 ]; then
830 echo "log command failed unexpectedly" >&2
831 test_done "$testroot" "1"
834 grep '^ [MDmA]' $testroot/stdout.full > $testroot/stdout
836 echo -n > $testroot/stdout.expected
837 cmp -s $testroot/stdout.expected $testroot/stdout
839 if [ $ret -ne 0 ]; then
840 diff -u $testroot/stdout.expected $testroot/stdout
842 test_done "$testroot" "$ret"
846 run_test test_log_in_repo
847 run_test test_log_in_bare_repo
848 run_test test_log_in_worktree
849 run_test test_log_in_worktree_with_path_prefix
850 run_test test_log_tag
851 run_test test_log_limit
852 run_test test_log_oneline
853 run_test test_log_patch_added_file
854 run_test test_log_nonexistent_path
855 run_test test_log_end_at_commit
856 run_test test_log_reverse_display
857 run_test test_log_in_worktree_different_repo
858 run_test test_log_changed_paths
859 run_test test_log_submodule