fetch-pack: avoid repeatedly re-scanning pack directory
[git/jrn.git] / t / t4202-log.sh
blobb3ac6be3b0d2cc47af4559bcf7401ef858dae322
1 #!/bin/sh
3 test_description='git log'
5 . ./test-lib.sh
7 test_expect_success setup '
9 echo one >one &&
10 git add one &&
11 test_tick &&
12 git commit -m initial &&
14 echo ichi >one &&
15 git add one &&
16 test_tick &&
17 git commit -m second &&
19 git mv one ichi &&
20 test_tick &&
21 git commit -m third &&
23 cp ichi ein &&
24 git add ein &&
25 test_tick &&
26 git commit -m fourth &&
28 mkdir a &&
29 echo ni >a/two &&
30 git add a/two &&
31 test_tick &&
32 git commit -m fifth &&
34 git rm a/two &&
35 test_tick &&
36 git commit -m sixth
40 printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial" > expect
41 test_expect_success 'pretty' '
43 git log --pretty="format:%s" > actual &&
44 test_cmp expect actual
47 printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial\n" > expect
48 test_expect_success 'pretty (tformat)' '
50 git log --pretty="tformat:%s" > actual &&
51 test_cmp expect actual
54 test_expect_success 'pretty (shortcut)' '
56 git log --pretty="%s" > actual &&
57 test_cmp expect actual
60 test_expect_success 'format' '
62 git log --format="%s" > actual &&
63 test_cmp expect actual
66 cat > expect << EOF
67 This is
68 the sixth
69 commit.
70 This is
71 the fifth
72 commit.
73 EOF
75 test_expect_success 'format %w(12,1,2)' '
77 git log -2 --format="%w(12,1,2)This is the %s commit." > actual &&
78 test_cmp expect actual
81 test_expect_success 'format %w(,1,2)' '
83 git log -2 --format="%w(,1,2)This is%nthe %s%ncommit." > actual &&
84 test_cmp expect actual
87 cat > expect << EOF
88 804a787 sixth
89 394ef78 fifth
90 5d31159 fourth
91 2fbe8c0 third
92 f7dab8e second
93 3a2fdcb initial
94 EOF
95 test_expect_success 'oneline' '
97 git log --oneline > actual &&
98 test_cmp expect actual
101 test_expect_success 'diff-filter=A' '
103 git log --pretty="format:%s" --diff-filter=A HEAD > actual &&
104 git log --pretty="format:%s" --diff-filter A HEAD > actual-separate &&
105 printf "fifth\nfourth\nthird\ninitial" > expect &&
106 test_cmp expect actual &&
107 test_cmp expect actual-separate
111 test_expect_success 'diff-filter=M' '
113 actual=$(git log --pretty="format:%s" --diff-filter=M HEAD) &&
114 expect=$(echo second) &&
115 test "$actual" = "$expect" || {
116 echo Oops
117 echo "Actual: $actual"
118 false
123 test_expect_success 'diff-filter=D' '
125 actual=$(git log --pretty="format:%s" --diff-filter=D HEAD) &&
126 expect=$(echo sixth ; echo third) &&
127 test "$actual" = "$expect" || {
128 echo Oops
129 echo "Actual: $actual"
130 false
135 test_expect_success 'diff-filter=R' '
137 actual=$(git log -M --pretty="format:%s" --diff-filter=R HEAD) &&
138 expect=$(echo third) &&
139 test "$actual" = "$expect" || {
140 echo Oops
141 echo "Actual: $actual"
142 false
147 test_expect_success 'diff-filter=C' '
149 actual=$(git log -C -C --pretty="format:%s" --diff-filter=C HEAD) &&
150 expect=$(echo fourth) &&
151 test "$actual" = "$expect" || {
152 echo Oops
153 echo "Actual: $actual"
154 false
159 test_expect_success 'git log --follow' '
161 actual=$(git log --follow --pretty="format:%s" ichi) &&
162 expect=$(echo third ; echo second ; echo initial) &&
163 test "$actual" = "$expect" || {
164 echo Oops
165 echo "Actual: $actual"
166 false
171 cat > expect << EOF
172 804a787 sixth
173 394ef78 fifth
174 5d31159 fourth
176 test_expect_success 'git log --no-walk <commits> sorts by commit time' '
177 git log --no-walk --oneline 5d31159 804a787 394ef78 > actual &&
178 test_cmp expect actual
181 test_expect_success 'git log --no-walk=sorted <commits> sorts by commit time' '
182 git log --no-walk=sorted --oneline 5d31159 804a787 394ef78 > actual &&
183 test_cmp expect actual
186 cat > expect << EOF
187 5d31159 fourth
188 804a787 sixth
189 394ef78 fifth
191 test_expect_success 'git log --no-walk=unsorted <commits> leaves list of commits as given' '
192 git log --no-walk=unsorted --oneline 5d31159 804a787 394ef78 > actual &&
193 test_cmp expect actual
196 test_expect_success 'git show <commits> leaves list of commits as given' '
197 git show --oneline -s 5d31159 804a787 394ef78 > actual &&
198 test_cmp expect actual
201 test_expect_success 'setup case sensitivity tests' '
202 echo case >one &&
203 test_tick &&
204 git add one &&
205 git commit -a -m Second
208 test_expect_success 'log --grep' '
209 echo second >expect &&
210 git log -1 --pretty="tformat:%s" --grep=sec >actual &&
211 test_cmp expect actual
214 test_expect_success 'log --grep option parsing' '
215 echo second >expect &&
216 git log -1 --pretty="tformat:%s" --grep sec >actual &&
217 test_cmp expect actual &&
218 test_must_fail git log -1 --pretty="tformat:%s" --grep
221 test_expect_success 'log -i --grep' '
222 echo Second >expect &&
223 git log -1 --pretty="tformat:%s" -i --grep=sec >actual &&
224 test_cmp expect actual
227 test_expect_success 'log --grep -i' '
228 echo Second >expect &&
229 git log -1 --pretty="tformat:%s" --grep=sec -i >actual &&
230 test_cmp expect actual
233 cat > expect <<EOF
234 * Second
235 * sixth
236 * fifth
237 * fourth
238 * third
239 * second
240 * initial
243 test_expect_success 'simple log --graph' '
244 git log --graph --pretty=tformat:%s >actual &&
245 test_cmp expect actual
248 test_expect_success 'set up merge history' '
249 git checkout -b side HEAD~4 &&
250 test_commit side-1 1 1 &&
251 test_commit side-2 2 2 &&
252 git checkout master &&
253 git merge side
256 cat > expect <<\EOF
257 * Merge branch 'side'
259 | * side-2
260 | * side-1
261 * | Second
262 * | sixth
263 * | fifth
264 * | fourth
266 * third
267 * second
268 * initial
271 test_expect_success 'log --graph with merge' '
272 git log --graph --date-order --pretty=tformat:%s |
273 sed "s/ *\$//" >actual &&
274 test_cmp expect actual
277 cat > expect <<\EOF
278 * commit master
279 |\ Merge: A B
280 | | Author: A U Thor <author@example.com>
282 | | Merge branch 'side'
284 | * commit side
285 | | Author: A U Thor <author@example.com>
287 | | side-2
289 | * commit tags/side-1
290 | | Author: A U Thor <author@example.com>
292 | | side-1
294 * | commit master~1
295 | | Author: A U Thor <author@example.com>
297 | | Second
299 * | commit master~2
300 | | Author: A U Thor <author@example.com>
302 | | sixth
304 * | commit master~3
305 | | Author: A U Thor <author@example.com>
307 | | fifth
309 * | commit master~4
310 |/ Author: A U Thor <author@example.com>
312 | fourth
314 * commit tags/side-1~1
315 | Author: A U Thor <author@example.com>
317 | third
319 * commit tags/side-1~2
320 | Author: A U Thor <author@example.com>
322 | second
324 * commit tags/side-1~3
325 Author: A U Thor <author@example.com>
327 initial
330 test_expect_success 'log --graph with full output' '
331 git log --graph --date-order --pretty=short |
332 git name-rev --name-only --stdin |
333 sed "s/Merge:.*/Merge: A B/;s/ *\$//" >actual &&
334 test_cmp expect actual
337 test_expect_success 'set up more tangled history' '
338 git checkout -b tangle HEAD~6 &&
339 test_commit tangle-a tangle-a a &&
340 git merge master~3 &&
341 git merge side~1 &&
342 git checkout master &&
343 git merge tangle &&
344 git checkout -b reach &&
345 test_commit reach &&
346 git checkout master &&
347 git checkout -b octopus-a &&
348 test_commit octopus-a &&
349 git checkout master &&
350 git checkout -b octopus-b &&
351 test_commit octopus-b &&
352 git checkout master &&
353 test_commit seventh &&
354 git merge octopus-a octopus-b &&
355 git merge reach
358 cat > expect <<\EOF
359 * Merge tag 'reach'
363 *-. \ Merge tags 'octopus-a' and 'octopus-b'
364 |\ \ \
365 * | | | seventh
366 | | * | octopus-b
367 | |/ /
368 |/| |
369 | * | octopus-a
370 |/ /
371 | * reach
373 * Merge branch 'tangle'
375 | * Merge branch 'side' (early part) into tangle
376 | |\
377 | * \ Merge branch 'master' (early part) into tangle
378 | |\ \
379 | * | | tangle-a
380 * | | | Merge branch 'side'
381 |\ \ \ \
382 | * | | | side-2
383 | | |_|/
384 | |/| |
385 | * | | side-1
386 * | | | Second
387 * | | | sixth
388 | |_|/
389 |/| |
390 * | | fifth
391 * | | fourth
392 |/ /
393 * | third
395 * second
396 * initial
399 test_expect_success 'log --graph with merge' '
400 git log --graph --date-order --pretty=tformat:%s |
401 sed "s/ *\$//" >actual &&
402 test_cmp expect actual
405 test_expect_success 'log.decorate configuration' '
406 test_might_fail git config --unset-all log.decorate &&
408 git log --oneline >expect.none &&
409 git log --oneline --decorate >expect.short &&
410 git log --oneline --decorate=full >expect.full &&
412 echo "[log] decorate" >>.git/config &&
413 git log --oneline >actual &&
414 test_cmp expect.short actual &&
416 git config --unset-all log.decorate &&
417 git config log.decorate true &&
418 git log --oneline >actual &&
419 test_cmp expect.short actual &&
420 git log --oneline --decorate=full >actual &&
421 test_cmp expect.full actual &&
422 git log --oneline --decorate=no >actual &&
423 test_cmp expect.none actual &&
425 git config --unset-all log.decorate &&
426 git config log.decorate no &&
427 git log --oneline >actual &&
428 test_cmp expect.none actual &&
429 git log --oneline --decorate >actual &&
430 test_cmp expect.short actual &&
431 git log --oneline --decorate=full >actual &&
432 test_cmp expect.full actual &&
434 git config --unset-all log.decorate &&
435 git config log.decorate 1 &&
436 git log --oneline >actual &&
437 test_cmp expect.short actual &&
438 git log --oneline --decorate=full >actual &&
439 test_cmp expect.full actual &&
440 git log --oneline --decorate=no >actual &&
441 test_cmp expect.none actual &&
443 git config --unset-all log.decorate &&
444 git config log.decorate short &&
445 git log --oneline >actual &&
446 test_cmp expect.short actual &&
447 git log --oneline --no-decorate >actual &&
448 test_cmp expect.none actual &&
449 git log --oneline --decorate=full >actual &&
450 test_cmp expect.full actual &&
452 git config --unset-all log.decorate &&
453 git config log.decorate full &&
454 git log --oneline >actual &&
455 test_cmp expect.full actual &&
456 git log --oneline --no-decorate >actual &&
457 test_cmp expect.none actual &&
458 git log --oneline --decorate >actual &&
459 test_cmp expect.short actual
461 git config --unset-all log.decorate &&
462 git log --pretty=raw >expect.raw &&
463 git config log.decorate full &&
464 git log --pretty=raw >actual &&
465 test_cmp expect.raw actual
469 test_expect_success 'reflog is expected format' '
470 test_might_fail git config --remove-section log &&
471 git log -g --abbrev-commit --pretty=oneline >expect &&
472 git reflog >actual &&
473 test_cmp expect actual
476 test_expect_success 'whatchanged is expected format' '
477 git log --no-merges --raw >expect &&
478 git whatchanged >actual &&
479 test_cmp expect actual
482 test_expect_success 'log.abbrevCommit configuration' '
483 test_when_finished "git config --unset log.abbrevCommit" &&
485 test_might_fail git config --unset log.abbrevCommit &&
487 git log --abbrev-commit >expect.log.abbrev &&
488 git log --no-abbrev-commit >expect.log.full &&
489 git log --pretty=raw >expect.log.raw &&
490 git reflog --abbrev-commit >expect.reflog.abbrev &&
491 git reflog --no-abbrev-commit >expect.reflog.full &&
492 git whatchanged --abbrev-commit >expect.whatchanged.abbrev &&
493 git whatchanged --no-abbrev-commit >expect.whatchanged.full &&
495 git config log.abbrevCommit true &&
497 git log >actual &&
498 test_cmp expect.log.abbrev actual &&
499 git log --no-abbrev-commit >actual &&
500 test_cmp expect.log.full actual &&
502 git log --pretty=raw >actual &&
503 test_cmp expect.log.raw actual &&
505 git reflog >actual &&
506 test_cmp expect.reflog.abbrev actual &&
507 git reflog --no-abbrev-commit >actual &&
508 test_cmp expect.reflog.full actual &&
510 git whatchanged >actual &&
511 test_cmp expect.whatchanged.abbrev actual &&
512 git whatchanged --no-abbrev-commit >actual &&
513 test_cmp expect.whatchanged.full actual
516 test_expect_success 'show added path under "--follow -M"' '
517 # This tests for a regression introduced in v1.7.2-rc0~103^2~2
518 test_create_repo regression &&
520 cd regression &&
521 test_commit needs-another-commit &&
522 test_commit foo.bar &&
523 git log -M --follow -p foo.bar.t &&
524 git log -M --follow --stat foo.bar.t &&
525 git log -M --follow --name-only foo.bar.t
529 cat >expect <<\EOF
530 * commit COMMIT_OBJECT_NAME
531 |\ Merge: MERGE_PARENTS
532 | | Author: A U Thor <author@example.com>
534 | | Merge HEADS DESCRIPTION
536 | * commit COMMIT_OBJECT_NAME
537 | | Author: A U Thor <author@example.com>
539 | | reach
540 | | ---
541 | | reach.t | 1 +
542 | | 1 file changed, 1 insertion(+)
544 | | diff --git a/reach.t b/reach.t
545 | | new file mode 100644
546 | | index 0000000..10c9591
547 | | --- /dev/null
548 | | +++ b/reach.t
549 | | @@ -0,0 +1 @@
550 | | +reach
553 *-. \ commit COMMIT_OBJECT_NAME
554 |\ \ \ Merge: MERGE_PARENTS
555 | | | | Author: A U Thor <author@example.com>
556 | | | |
557 | | | | Merge HEADS DESCRIPTION
558 | | | |
559 | | * | commit COMMIT_OBJECT_NAME
560 | | |/ Author: A U Thor <author@example.com>
561 | | |
562 | | | octopus-b
563 | | | ---
564 | | | octopus-b.t | 1 +
565 | | | 1 file changed, 1 insertion(+)
566 | | |
567 | | | diff --git a/octopus-b.t b/octopus-b.t
568 | | | new file mode 100644
569 | | | index 0000000..d5fcad0
570 | | | --- /dev/null
571 | | | +++ b/octopus-b.t
572 | | | @@ -0,0 +1 @@
573 | | | +octopus-b
574 | | |
575 | * | commit COMMIT_OBJECT_NAME
576 | |/ Author: A U Thor <author@example.com>
578 | | octopus-a
579 | | ---
580 | | octopus-a.t | 1 +
581 | | 1 file changed, 1 insertion(+)
583 | | diff --git a/octopus-a.t b/octopus-a.t
584 | | new file mode 100644
585 | | index 0000000..11ee015
586 | | --- /dev/null
587 | | +++ b/octopus-a.t
588 | | @@ -0,0 +1 @@
589 | | +octopus-a
591 * | commit COMMIT_OBJECT_NAME
592 |/ Author: A U Thor <author@example.com>
594 | seventh
595 | ---
596 | seventh.t | 1 +
597 | 1 file changed, 1 insertion(+)
599 | diff --git a/seventh.t b/seventh.t
600 | new file mode 100644
601 | index 0000000..9744ffc
602 | --- /dev/null
603 | +++ b/seventh.t
604 | @@ -0,0 +1 @@
605 | +seventh
607 * commit COMMIT_OBJECT_NAME
608 |\ Merge: MERGE_PARENTS
609 | | Author: A U Thor <author@example.com>
611 | | Merge branch 'tangle'
613 | * commit COMMIT_OBJECT_NAME
614 | |\ Merge: MERGE_PARENTS
615 | | | Author: A U Thor <author@example.com>
616 | | |
617 | | | Merge branch 'side' (early part) into tangle
618 | | |
619 | * | commit COMMIT_OBJECT_NAME
620 | |\ \ Merge: MERGE_PARENTS
621 | | | | Author: A U Thor <author@example.com>
622 | | | |
623 | | | | Merge branch 'master' (early part) into tangle
624 | | | |
625 | * | | commit COMMIT_OBJECT_NAME
626 | | | | Author: A U Thor <author@example.com>
627 | | | |
628 | | | | tangle-a
629 | | | | ---
630 | | | | tangle-a | 1 +
631 | | | | 1 file changed, 1 insertion(+)
632 | | | |
633 | | | | diff --git a/tangle-a b/tangle-a
634 | | | | new file mode 100644
635 | | | | index 0000000..7898192
636 | | | | --- /dev/null
637 | | | | +++ b/tangle-a
638 | | | | @@ -0,0 +1 @@
639 | | | | +a
640 | | | |
641 * | | | commit COMMIT_OBJECT_NAME
642 |\ \ \ \ Merge: MERGE_PARENTS
643 | | | | | Author: A U Thor <author@example.com>
644 | | | | |
645 | | | | | Merge branch 'side'
646 | | | | |
647 | * | | | commit COMMIT_OBJECT_NAME
648 | | |_|/ Author: A U Thor <author@example.com>
649 | |/| |
650 | | | | side-2
651 | | | | ---
652 | | | | 2 | 1 +
653 | | | | 1 file changed, 1 insertion(+)
654 | | | |
655 | | | | diff --git a/2 b/2
656 | | | | new file mode 100644
657 | | | | index 0000000..0cfbf08
658 | | | | --- /dev/null
659 | | | | +++ b/2
660 | | | | @@ -0,0 +1 @@
661 | | | | +2
662 | | | |
663 | * | | commit COMMIT_OBJECT_NAME
664 | | | | Author: A U Thor <author@example.com>
665 | | | |
666 | | | | side-1
667 | | | | ---
668 | | | | 1 | 1 +
669 | | | | 1 file changed, 1 insertion(+)
670 | | | |
671 | | | | diff --git a/1 b/1
672 | | | | new file mode 100644
673 | | | | index 0000000..d00491f
674 | | | | --- /dev/null
675 | | | | +++ b/1
676 | | | | @@ -0,0 +1 @@
677 | | | | +1
678 | | | |
679 * | | | commit COMMIT_OBJECT_NAME
680 | | | | Author: A U Thor <author@example.com>
681 | | | |
682 | | | | Second
683 | | | | ---
684 | | | | one | 1 +
685 | | | | 1 file changed, 1 insertion(+)
686 | | | |
687 | | | | diff --git a/one b/one
688 | | | | new file mode 100644
689 | | | | index 0000000..9a33383
690 | | | | --- /dev/null
691 | | | | +++ b/one
692 | | | | @@ -0,0 +1 @@
693 | | | | +case
694 | | | |
695 * | | | commit COMMIT_OBJECT_NAME
696 | |_|/ Author: A U Thor <author@example.com>
697 |/| |
698 | | | sixth
699 | | | ---
700 | | | a/two | 1 -
701 | | | 1 file changed, 1 deletion(-)
702 | | |
703 | | | diff --git a/a/two b/a/two
704 | | | deleted file mode 100644
705 | | | index 9245af5..0000000
706 | | | --- a/a/two
707 | | | +++ /dev/null
708 | | | @@ -1 +0,0 @@
709 | | | -ni
710 | | |
711 * | | commit COMMIT_OBJECT_NAME
712 | | | Author: A U Thor <author@example.com>
713 | | |
714 | | | fifth
715 | | | ---
716 | | | a/two | 1 +
717 | | | 1 file changed, 1 insertion(+)
718 | | |
719 | | | diff --git a/a/two b/a/two
720 | | | new file mode 100644
721 | | | index 0000000..9245af5
722 | | | --- /dev/null
723 | | | +++ b/a/two
724 | | | @@ -0,0 +1 @@
725 | | | +ni
726 | | |
727 * | | commit COMMIT_OBJECT_NAME
728 |/ / Author: A U Thor <author@example.com>
730 | | fourth
731 | | ---
732 | | ein | 1 +
733 | | 1 file changed, 1 insertion(+)
735 | | diff --git a/ein b/ein
736 | | new file mode 100644
737 | | index 0000000..9d7e69f
738 | | --- /dev/null
739 | | +++ b/ein
740 | | @@ -0,0 +1 @@
741 | | +ichi
743 * | commit COMMIT_OBJECT_NAME
744 |/ Author: A U Thor <author@example.com>
746 | third
747 | ---
748 | ichi | 1 +
749 | one | 1 -
750 | 2 files changed, 1 insertion(+), 1 deletion(-)
752 | diff --git a/ichi b/ichi
753 | new file mode 100644
754 | index 0000000..9d7e69f
755 | --- /dev/null
756 | +++ b/ichi
757 | @@ -0,0 +1 @@
758 | +ichi
759 | diff --git a/one b/one
760 | deleted file mode 100644
761 | index 9d7e69f..0000000
762 | --- a/one
763 | +++ /dev/null
764 | @@ -1 +0,0 @@
765 | -ichi
767 * commit COMMIT_OBJECT_NAME
768 | Author: A U Thor <author@example.com>
770 | second
771 | ---
772 | one | 2 +-
773 | 1 file changed, 1 insertion(+), 1 deletion(-)
775 | diff --git a/one b/one
776 | index 5626abf..9d7e69f 100644
777 | --- a/one
778 | +++ b/one
779 | @@ -1 +1 @@
780 | -one
781 | +ichi
783 * commit COMMIT_OBJECT_NAME
784 Author: A U Thor <author@example.com>
786 initial
788 one | 1 +
789 1 file changed, 1 insertion(+)
791 diff --git a/one b/one
792 new file mode 100644
793 index 0000000..5626abf
794 --- /dev/null
795 +++ b/one
796 @@ -0,0 +1 @@
797 +one
800 sanitize_output () {
801 sed -e 's/ *$//' \
802 -e 's/commit [0-9a-f]*$/commit COMMIT_OBJECT_NAME/' \
803 -e 's/Merge: [ 0-9a-f]*$/Merge: MERGE_PARENTS/' \
804 -e 's/Merge tag.*/Merge HEADS DESCRIPTION/' \
805 -e 's/Merge commit.*/Merge HEADS DESCRIPTION/' \
806 -e 's/, 0 deletions(-)//' \
807 -e 's/, 0 insertions(+)//' \
808 -e 's/ 1 files changed, / 1 file changed, /' \
809 -e 's/, 1 deletions(-)/, 1 deletion(-)/' \
810 -e 's/, 1 insertions(+)/, 1 insertion(+)/'
813 test_expect_success 'log --graph with diff and stats' '
814 git log --graph --pretty=short --stat -p >actual &&
815 sanitize_output >actual.sanitized <actual &&
816 test_cmp expect actual.sanitized
819 test_expect_success 'dotdot is a parent directory' '
820 mkdir -p a/b &&
821 ( echo sixth && echo fifth ) >expect &&
822 ( cd a/b && git log --format=%s .. ) >actual &&
823 test_cmp expect actual
826 test_done