Merge branch 'bw/test-fix-grep-gnuism' into maint
[git/jrn.git] / t / t4202-log.sh
blob32cf0bd218ea081e3e1d73400943b30a946f9dd5
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 cat > expect << EOF
182 5d31159 fourth
183 804a787 sixth
184 394ef78 fifth
186 test_expect_success 'git show <commits> leaves list of commits as given' '
187 git show --oneline -s 5d31159 804a787 394ef78 > actual &&
188 test_cmp expect actual
191 test_expect_success 'setup case sensitivity tests' '
192 echo case >one &&
193 test_tick &&
194 git add one &&
195 git commit -a -m Second
198 test_expect_success 'log --grep' '
199 echo second >expect &&
200 git log -1 --pretty="tformat:%s" --grep=sec >actual &&
201 test_cmp expect actual
204 test_expect_success 'log --grep option parsing' '
205 echo second >expect &&
206 git log -1 --pretty="tformat:%s" --grep sec >actual &&
207 test_cmp expect actual &&
208 test_must_fail git log -1 --pretty="tformat:%s" --grep
211 test_expect_success 'log -i --grep' '
212 echo Second >expect &&
213 git log -1 --pretty="tformat:%s" -i --grep=sec >actual &&
214 test_cmp expect actual
217 test_expect_success 'log --grep -i' '
218 echo Second >expect &&
219 git log -1 --pretty="tformat:%s" --grep=sec -i >actual &&
220 test_cmp expect actual
223 cat > expect <<EOF
224 * Second
225 * sixth
226 * fifth
227 * fourth
228 * third
229 * second
230 * initial
233 test_expect_success 'simple log --graph' '
234 git log --graph --pretty=tformat:%s >actual &&
235 test_cmp expect actual
238 test_expect_success 'set up merge history' '
239 git checkout -b side HEAD~4 &&
240 test_commit side-1 1 1 &&
241 test_commit side-2 2 2 &&
242 git checkout master &&
243 git merge side
246 cat > expect <<\EOF
247 * Merge branch 'side'
249 | * side-2
250 | * side-1
251 * | Second
252 * | sixth
253 * | fifth
254 * | fourth
256 * third
257 * second
258 * initial
261 test_expect_success 'log --graph with merge' '
262 git log --graph --date-order --pretty=tformat:%s |
263 sed "s/ *\$//" >actual &&
264 test_cmp expect actual
267 cat > expect <<\EOF
268 * commit master
269 |\ Merge: A B
270 | | Author: A U Thor <author@example.com>
272 | | Merge branch 'side'
274 | * commit side
275 | | Author: A U Thor <author@example.com>
277 | | side-2
279 | * commit tags/side-1
280 | | Author: A U Thor <author@example.com>
282 | | side-1
284 * | commit master~1
285 | | Author: A U Thor <author@example.com>
287 | | Second
289 * | commit master~2
290 | | Author: A U Thor <author@example.com>
292 | | sixth
294 * | commit master~3
295 | | Author: A U Thor <author@example.com>
297 | | fifth
299 * | commit master~4
300 |/ Author: A U Thor <author@example.com>
302 | fourth
304 * commit tags/side-1~1
305 | Author: A U Thor <author@example.com>
307 | third
309 * commit tags/side-1~2
310 | Author: A U Thor <author@example.com>
312 | second
314 * commit tags/side-1~3
315 Author: A U Thor <author@example.com>
317 initial
320 test_expect_success 'log --graph with full output' '
321 git log --graph --date-order --pretty=short |
322 git name-rev --name-only --stdin |
323 sed "s/Merge:.*/Merge: A B/;s/ *\$//" >actual &&
324 test_cmp expect actual
327 test_expect_success 'set up more tangled history' '
328 git checkout -b tangle HEAD~6 &&
329 test_commit tangle-a tangle-a a &&
330 git merge master~3 &&
331 git merge side~1 &&
332 git checkout master &&
333 git merge tangle &&
334 git checkout -b reach &&
335 test_commit reach &&
336 git checkout master &&
337 git checkout -b octopus-a &&
338 test_commit octopus-a &&
339 git checkout master &&
340 git checkout -b octopus-b &&
341 test_commit octopus-b &&
342 git checkout master &&
343 test_commit seventh &&
344 git merge octopus-a octopus-b &&
345 git merge reach
348 cat > expect <<\EOF
349 * Merge tag 'reach'
353 *-. \ Merge tags 'octopus-a' and 'octopus-b'
354 |\ \ \
355 * | | | seventh
356 | | * | octopus-b
357 | |/ /
358 |/| |
359 | * | octopus-a
360 |/ /
361 | * reach
363 * Merge branch 'tangle'
365 | * Merge branch 'side' (early part) into tangle
366 | |\
367 | * \ Merge branch 'master' (early part) into tangle
368 | |\ \
369 | * | | tangle-a
370 * | | | Merge branch 'side'
371 |\ \ \ \
372 | * | | | side-2
373 | | |_|/
374 | |/| |
375 | * | | side-1
376 * | | | Second
377 * | | | sixth
378 | |_|/
379 |/| |
380 * | | fifth
381 * | | fourth
382 |/ /
383 * | third
385 * second
386 * initial
389 test_expect_success 'log --graph with merge' '
390 git log --graph --date-order --pretty=tformat:%s |
391 sed "s/ *\$//" >actual &&
392 test_cmp expect actual
395 test_expect_success 'log.decorate configuration' '
396 test_might_fail git config --unset-all log.decorate &&
398 git log --oneline >expect.none &&
399 git log --oneline --decorate >expect.short &&
400 git log --oneline --decorate=full >expect.full &&
402 echo "[log] decorate" >>.git/config &&
403 git log --oneline >actual &&
404 test_cmp expect.short actual &&
406 git config --unset-all log.decorate &&
407 git config log.decorate true &&
408 git log --oneline >actual &&
409 test_cmp expect.short actual &&
410 git log --oneline --decorate=full >actual &&
411 test_cmp expect.full actual &&
412 git log --oneline --decorate=no >actual &&
413 test_cmp expect.none actual &&
415 git config --unset-all log.decorate &&
416 git config log.decorate no &&
417 git log --oneline >actual &&
418 test_cmp expect.none actual &&
419 git log --oneline --decorate >actual &&
420 test_cmp expect.short actual &&
421 git log --oneline --decorate=full >actual &&
422 test_cmp expect.full actual &&
424 git config --unset-all log.decorate &&
425 git config log.decorate 1 &&
426 git log --oneline >actual &&
427 test_cmp expect.short actual &&
428 git log --oneline --decorate=full >actual &&
429 test_cmp expect.full actual &&
430 git log --oneline --decorate=no >actual &&
431 test_cmp expect.none actual &&
433 git config --unset-all log.decorate &&
434 git config log.decorate short &&
435 git log --oneline >actual &&
436 test_cmp expect.short actual &&
437 git log --oneline --no-decorate >actual &&
438 test_cmp expect.none actual &&
439 git log --oneline --decorate=full >actual &&
440 test_cmp expect.full actual &&
442 git config --unset-all log.decorate &&
443 git config log.decorate full &&
444 git log --oneline >actual &&
445 test_cmp expect.full actual &&
446 git log --oneline --no-decorate >actual &&
447 test_cmp expect.none actual &&
448 git log --oneline --decorate >actual &&
449 test_cmp expect.short actual
451 git config --unset-all log.decorate &&
452 git log --pretty=raw >expect.raw &&
453 git config log.decorate full &&
454 git log --pretty=raw >actual &&
455 test_cmp expect.raw actual
459 test_expect_success 'reflog is expected format' '
460 test_might_fail git config --remove-section log &&
461 git log -g --abbrev-commit --pretty=oneline >expect &&
462 git reflog >actual &&
463 test_cmp expect actual
466 test_expect_success 'whatchanged is expected format' '
467 git log --no-merges --raw >expect &&
468 git whatchanged >actual &&
469 test_cmp expect actual
472 test_expect_success 'log.abbrevCommit configuration' '
473 test_when_finished "git config --unset log.abbrevCommit" &&
475 test_might_fail git config --unset log.abbrevCommit &&
477 git log --abbrev-commit >expect.log.abbrev &&
478 git log --no-abbrev-commit >expect.log.full &&
479 git log --pretty=raw >expect.log.raw &&
480 git reflog --abbrev-commit >expect.reflog.abbrev &&
481 git reflog --no-abbrev-commit >expect.reflog.full &&
482 git whatchanged --abbrev-commit >expect.whatchanged.abbrev &&
483 git whatchanged --no-abbrev-commit >expect.whatchanged.full &&
485 git config log.abbrevCommit true &&
487 git log >actual &&
488 test_cmp expect.log.abbrev actual &&
489 git log --no-abbrev-commit >actual &&
490 test_cmp expect.log.full actual &&
492 git log --pretty=raw >actual &&
493 test_cmp expect.log.raw actual &&
495 git reflog >actual &&
496 test_cmp expect.reflog.abbrev actual &&
497 git reflog --no-abbrev-commit >actual &&
498 test_cmp expect.reflog.full actual &&
500 git whatchanged >actual &&
501 test_cmp expect.whatchanged.abbrev actual &&
502 git whatchanged --no-abbrev-commit >actual &&
503 test_cmp expect.whatchanged.full actual
506 test_expect_success 'show added path under "--follow -M"' '
507 # This tests for a regression introduced in v1.7.2-rc0~103^2~2
508 test_create_repo regression &&
510 cd regression &&
511 test_commit needs-another-commit &&
512 test_commit foo.bar &&
513 git log -M --follow -p foo.bar.t &&
514 git log -M --follow --stat foo.bar.t &&
515 git log -M --follow --name-only foo.bar.t
519 cat >expect <<\EOF
520 * commit COMMIT_OBJECT_NAME
521 |\ Merge: MERGE_PARENTS
522 | | Author: A U Thor <author@example.com>
524 | | Merge HEADS DESCRIPTION
526 | * commit COMMIT_OBJECT_NAME
527 | | Author: A U Thor <author@example.com>
529 | | reach
530 | | ---
531 | | reach.t | 1 +
532 | | 1 file changed, 1 insertion(+)
534 | | diff --git a/reach.t b/reach.t
535 | | new file mode 100644
536 | | index 0000000..10c9591
537 | | --- /dev/null
538 | | +++ b/reach.t
539 | | @@ -0,0 +1 @@
540 | | +reach
543 *-. \ commit COMMIT_OBJECT_NAME
544 |\ \ \ Merge: MERGE_PARENTS
545 | | | | Author: A U Thor <author@example.com>
546 | | | |
547 | | | | Merge HEADS DESCRIPTION
548 | | | |
549 | | * | commit COMMIT_OBJECT_NAME
550 | | |/ Author: A U Thor <author@example.com>
551 | | |
552 | | | octopus-b
553 | | | ---
554 | | | octopus-b.t | 1 +
555 | | | 1 file changed, 1 insertion(+)
556 | | |
557 | | | diff --git a/octopus-b.t b/octopus-b.t
558 | | | new file mode 100644
559 | | | index 0000000..d5fcad0
560 | | | --- /dev/null
561 | | | +++ b/octopus-b.t
562 | | | @@ -0,0 +1 @@
563 | | | +octopus-b
564 | | |
565 | * | commit COMMIT_OBJECT_NAME
566 | |/ Author: A U Thor <author@example.com>
568 | | octopus-a
569 | | ---
570 | | octopus-a.t | 1 +
571 | | 1 file changed, 1 insertion(+)
573 | | diff --git a/octopus-a.t b/octopus-a.t
574 | | new file mode 100644
575 | | index 0000000..11ee015
576 | | --- /dev/null
577 | | +++ b/octopus-a.t
578 | | @@ -0,0 +1 @@
579 | | +octopus-a
581 * | commit COMMIT_OBJECT_NAME
582 |/ Author: A U Thor <author@example.com>
584 | seventh
585 | ---
586 | seventh.t | 1 +
587 | 1 file changed, 1 insertion(+)
589 | diff --git a/seventh.t b/seventh.t
590 | new file mode 100644
591 | index 0000000..9744ffc
592 | --- /dev/null
593 | +++ b/seventh.t
594 | @@ -0,0 +1 @@
595 | +seventh
597 * commit COMMIT_OBJECT_NAME
598 |\ Merge: MERGE_PARENTS
599 | | Author: A U Thor <author@example.com>
601 | | Merge branch 'tangle'
603 | * commit COMMIT_OBJECT_NAME
604 | |\ Merge: MERGE_PARENTS
605 | | | Author: A U Thor <author@example.com>
606 | | |
607 | | | Merge branch 'side' (early part) into tangle
608 | | |
609 | * | commit COMMIT_OBJECT_NAME
610 | |\ \ Merge: MERGE_PARENTS
611 | | | | Author: A U Thor <author@example.com>
612 | | | |
613 | | | | Merge branch 'master' (early part) into tangle
614 | | | |
615 | * | | commit COMMIT_OBJECT_NAME
616 | | | | Author: A U Thor <author@example.com>
617 | | | |
618 | | | | tangle-a
619 | | | | ---
620 | | | | tangle-a | 1 +
621 | | | | 1 file changed, 1 insertion(+)
622 | | | |
623 | | | | diff --git a/tangle-a b/tangle-a
624 | | | | new file mode 100644
625 | | | | index 0000000..7898192
626 | | | | --- /dev/null
627 | | | | +++ b/tangle-a
628 | | | | @@ -0,0 +1 @@
629 | | | | +a
630 | | | |
631 * | | | commit COMMIT_OBJECT_NAME
632 |\ \ \ \ Merge: MERGE_PARENTS
633 | | | | | Author: A U Thor <author@example.com>
634 | | | | |
635 | | | | | Merge branch 'side'
636 | | | | |
637 | * | | | commit COMMIT_OBJECT_NAME
638 | | |_|/ Author: A U Thor <author@example.com>
639 | |/| |
640 | | | | side-2
641 | | | | ---
642 | | | | 2 | 1 +
643 | | | | 1 file changed, 1 insertion(+)
644 | | | |
645 | | | | diff --git a/2 b/2
646 | | | | new file mode 100644
647 | | | | index 0000000..0cfbf08
648 | | | | --- /dev/null
649 | | | | +++ b/2
650 | | | | @@ -0,0 +1 @@
651 | | | | +2
652 | | | |
653 | * | | commit COMMIT_OBJECT_NAME
654 | | | | Author: A U Thor <author@example.com>
655 | | | |
656 | | | | side-1
657 | | | | ---
658 | | | | 1 | 1 +
659 | | | | 1 file changed, 1 insertion(+)
660 | | | |
661 | | | | diff --git a/1 b/1
662 | | | | new file mode 100644
663 | | | | index 0000000..d00491f
664 | | | | --- /dev/null
665 | | | | +++ b/1
666 | | | | @@ -0,0 +1 @@
667 | | | | +1
668 | | | |
669 * | | | commit COMMIT_OBJECT_NAME
670 | | | | Author: A U Thor <author@example.com>
671 | | | |
672 | | | | Second
673 | | | | ---
674 | | | | one | 1 +
675 | | | | 1 file changed, 1 insertion(+)
676 | | | |
677 | | | | diff --git a/one b/one
678 | | | | new file mode 100644
679 | | | | index 0000000..9a33383
680 | | | | --- /dev/null
681 | | | | +++ b/one
682 | | | | @@ -0,0 +1 @@
683 | | | | +case
684 | | | |
685 * | | | commit COMMIT_OBJECT_NAME
686 | |_|/ Author: A U Thor <author@example.com>
687 |/| |
688 | | | sixth
689 | | | ---
690 | | | a/two | 1 -
691 | | | 1 file changed, 1 deletion(-)
692 | | |
693 | | | diff --git a/a/two b/a/two
694 | | | deleted file mode 100644
695 | | | index 9245af5..0000000
696 | | | --- a/a/two
697 | | | +++ /dev/null
698 | | | @@ -1 +0,0 @@
699 | | | -ni
700 | | |
701 * | | commit COMMIT_OBJECT_NAME
702 | | | Author: A U Thor <author@example.com>
703 | | |
704 | | | fifth
705 | | | ---
706 | | | a/two | 1 +
707 | | | 1 file changed, 1 insertion(+)
708 | | |
709 | | | diff --git a/a/two b/a/two
710 | | | new file mode 100644
711 | | | index 0000000..9245af5
712 | | | --- /dev/null
713 | | | +++ b/a/two
714 | | | @@ -0,0 +1 @@
715 | | | +ni
716 | | |
717 * | | commit COMMIT_OBJECT_NAME
718 |/ / Author: A U Thor <author@example.com>
720 | | fourth
721 | | ---
722 | | ein | 1 +
723 | | 1 file changed, 1 insertion(+)
725 | | diff --git a/ein b/ein
726 | | new file mode 100644
727 | | index 0000000..9d7e69f
728 | | --- /dev/null
729 | | +++ b/ein
730 | | @@ -0,0 +1 @@
731 | | +ichi
733 * | commit COMMIT_OBJECT_NAME
734 |/ Author: A U Thor <author@example.com>
736 | third
737 | ---
738 | ichi | 1 +
739 | one | 1 -
740 | 2 files changed, 1 insertion(+), 1 deletion(-)
742 | diff --git a/ichi b/ichi
743 | new file mode 100644
744 | index 0000000..9d7e69f
745 | --- /dev/null
746 | +++ b/ichi
747 | @@ -0,0 +1 @@
748 | +ichi
749 | diff --git a/one b/one
750 | deleted file mode 100644
751 | index 9d7e69f..0000000
752 | --- a/one
753 | +++ /dev/null
754 | @@ -1 +0,0 @@
755 | -ichi
757 * commit COMMIT_OBJECT_NAME
758 | Author: A U Thor <author@example.com>
760 | second
761 | ---
762 | one | 2 +-
763 | 1 file changed, 1 insertion(+), 1 deletion(-)
765 | diff --git a/one b/one
766 | index 5626abf..9d7e69f 100644
767 | --- a/one
768 | +++ b/one
769 | @@ -1 +1 @@
770 | -one
771 | +ichi
773 * commit COMMIT_OBJECT_NAME
774 Author: A U Thor <author@example.com>
776 initial
778 one | 1 +
779 1 file changed, 1 insertion(+)
781 diff --git a/one b/one
782 new file mode 100644
783 index 0000000..5626abf
784 --- /dev/null
785 +++ b/one
786 @@ -0,0 +1 @@
787 +one
790 sanitize_output () {
791 sed -e 's/ *$//' \
792 -e 's/commit [0-9a-f]*$/commit COMMIT_OBJECT_NAME/' \
793 -e 's/Merge: [ 0-9a-f]*$/Merge: MERGE_PARENTS/' \
794 -e 's/Merge tag.*/Merge HEADS DESCRIPTION/' \
795 -e 's/Merge commit.*/Merge HEADS DESCRIPTION/' \
796 -e 's/, 0 deletions(-)//' \
797 -e 's/, 0 insertions(+)//' \
798 -e 's/ 1 files changed, / 1 file changed, /' \
799 -e 's/, 1 deletions(-)/, 1 deletion(-)/' \
800 -e 's/, 1 insertions(+)/, 1 insertion(+)/'
803 test_expect_success 'log --graph with diff and stats' '
804 git log --graph --pretty=short --stat -p >actual &&
805 sanitize_output >actual.sanitized <actual &&
806 test_cmp expect actual.sanitized
809 test_done