3 test_description='git log'
7 test_expect_success setup '
12 git commit -m initial &&
17 git commit -m second &&
21 git commit -m third &&
26 git commit -m fourth &&
32 git commit -m fifth &&
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
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
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" || {
117 echo "Actual: $actual"
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" || {
129 echo "Actual: $actual"
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" || {
141 echo "Actual: $actual"
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" || {
153 echo "Actual: $actual"
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" || {
165 echo "Actual: $actual"
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
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' '
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
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 &&
257 * Merge branch 'side'
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
280 | | Author: A U Thor <author@example.com>
282 | | Merge branch 'side'
285 | | Author: A U Thor <author@example.com>
289 | * commit tags/side-1
290 | | Author: A U Thor <author@example.com>
295 | | Author: A U Thor <author@example.com>
300 | | Author: A U Thor <author@example.com>
305 | | Author: A U Thor <author@example.com>
310 |/ Author: A U Thor <author@example.com>
314 * commit tags/side-1~1
315 | Author: A U Thor <author@example.com>
319 * commit tags/side-1~2
320 | Author: A U Thor <author@example.com>
324 * commit tags/side-1~3
325 Author: A U Thor <author@example.com>
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 &&
342 git checkout master &&
344 git checkout -b 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 &&
363 *-. \ Merge tags 'octopus-a' and 'octopus-b'
373 * Merge branch 'tangle'
375 | * Merge branch 'side' (early part) into tangle
377 | * \ Merge branch 'master' (early part) into tangle
380 * | | | Merge branch 'side'
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 &&
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 &&
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
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>
542 | | 1 file changed, 1 insertion(+)
544 | | diff --git a/reach.t b/reach.t
545 | | new file mode 100644
546 | | index 0000000..10c9591
553 *-. \ commit COMMIT_OBJECT_NAME
554 |\ \ \ Merge: MERGE_PARENTS
555 | | | | Author: A U Thor <author@example.com>
557 | | | | Merge HEADS DESCRIPTION
559 | | * | commit COMMIT_OBJECT_NAME
560 | | |/ Author: A U Thor <author@example.com>
564 | | | octopus-b.t | 1 +
565 | | | 1 file changed, 1 insertion(+)
567 | | | diff --git a/octopus-b.t b/octopus-b.t
568 | | | new file mode 100644
569 | | | index 0000000..d5fcad0
571 | | | +++ b/octopus-b.t
575 | * | commit COMMIT_OBJECT_NAME
576 | |/ Author: A U Thor <author@example.com>
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
587 | | +++ b/octopus-a.t
591 * | commit COMMIT_OBJECT_NAME
592 |/ Author: A U Thor <author@example.com>
597 | 1 file changed, 1 insertion(+)
599 | diff --git a/seventh.t b/seventh.t
600 | new file mode 100644
601 | index 0000000..9744ffc
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>
617 | | | Merge branch 'side' (early part) into tangle
619 | * | commit COMMIT_OBJECT_NAME
620 | |\ \ Merge: MERGE_PARENTS
621 | | | | Author: A U Thor <author@example.com>
623 | | | | Merge branch 'master' (early part) into tangle
625 | * | | commit COMMIT_OBJECT_NAME
626 | | | | Author: A U Thor <author@example.com>
630 | | | | tangle-a | 1 +
631 | | | | 1 file changed, 1 insertion(+)
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 @@
641 * | | | commit COMMIT_OBJECT_NAME
642 |\ \ \ \ Merge: MERGE_PARENTS
643 | | | | | Author: A U Thor <author@example.com>
645 | | | | | Merge branch 'side'
647 | * | | | commit COMMIT_OBJECT_NAME
648 | | |_|/ Author: A U Thor <author@example.com>
653 | | | | 1 file changed, 1 insertion(+)
655 | | | | diff --git a/2 b/2
656 | | | | new file mode 100644
657 | | | | index 0000000..0cfbf08
658 | | | | --- /dev/null
660 | | | | @@ -0,0 +1 @@
663 | * | | commit COMMIT_OBJECT_NAME
664 | | | | Author: A U Thor <author@example.com>
669 | | | | 1 file changed, 1 insertion(+)
671 | | | | diff --git a/1 b/1
672 | | | | new file mode 100644
673 | | | | index 0000000..d00491f
674 | | | | --- /dev/null
676 | | | | @@ -0,0 +1 @@
679 * | | | commit COMMIT_OBJECT_NAME
680 | | | | Author: A U Thor <author@example.com>
685 | | | | 1 file changed, 1 insertion(+)
687 | | | | diff --git a/one b/one
688 | | | | new file mode 100644
689 | | | | index 0000000..9a33383
690 | | | | --- /dev/null
692 | | | | @@ -0,0 +1 @@
695 * | | | commit COMMIT_OBJECT_NAME
696 | |_|/ Author: A U Thor <author@example.com>
701 | | | 1 file changed, 1 deletion(-)
703 | | | diff --git a/a/two b/a/two
704 | | | deleted file mode 100644
705 | | | index 9245af5..0000000
711 * | | commit COMMIT_OBJECT_NAME
712 | | | Author: A U Thor <author@example.com>
717 | | | 1 file changed, 1 insertion(+)
719 | | | diff --git a/a/two b/a/two
720 | | | new file mode 100644
721 | | | index 0000000..9245af5
727 * | | commit COMMIT_OBJECT_NAME
728 |/ / Author: A U Thor <author@example.com>
733 | | 1 file changed, 1 insertion(+)
735 | | diff --git a/ein b/ein
736 | | new file mode 100644
737 | | index 0000000..9d7e69f
743 * | commit COMMIT_OBJECT_NAME
744 |/ Author: A U Thor <author@example.com>
750 | 2 files changed, 1 insertion(+), 1 deletion(-)
752 | diff --git a/ichi b/ichi
753 | new file mode 100644
754 | index 0000000..9d7e69f
759 | diff --git a/one b/one
760 | deleted file mode 100644
761 | index 9d7e69f..0000000
767 * commit COMMIT_OBJECT_NAME
768 | Author: A U Thor <author@example.com>
773 | 1 file changed, 1 insertion(+), 1 deletion(-)
775 | diff --git a/one b/one
776 | index 5626abf..9d7e69f 100644
783 * commit COMMIT_OBJECT_NAME
784 Author: A U Thor <author@example.com>
789 1 file changed, 1 insertion(+)
791 diff --git a/one b/one
793 index 0000000..5626abf
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' '
821 ( echo sixth && echo fifth ) >expect &&
822 ( cd a/b && git log --format=%s .. ) >actual &&
823 test_cmp expect actual