3 test_description
='git log'
6 .
"$TEST_DIRECTORY/lib-gpg.sh"
8 test_expect_success setup
'
13 git commit -m initial &&
18 git commit -m second &&
22 git commit -m third &&
27 git commit -m fourth &&
33 git commit -m fifth &&
41 printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial" > expect
42 test_expect_success
'pretty' '
44 git log --pretty="format:%s" > actual &&
45 test_cmp expect actual
48 printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial\n" > expect
49 test_expect_success
'pretty (tformat)' '
51 git log --pretty="tformat:%s" > actual &&
52 test_cmp expect actual
55 test_expect_success
'pretty (shortcut)' '
57 git log --pretty="%s" > actual &&
58 test_cmp expect actual
61 test_expect_success
'format' '
63 git log --format="%s" > actual &&
64 test_cmp expect actual
76 test_expect_success
'format %w(11,1,2)' '
78 git log -2 --format="%w(11,1,2)This is the %s commit." > actual &&
79 test_cmp expect actual
82 test_expect_success
'format %w(,1,2)' '
84 git log -2 --format="%w(,1,2)This is%nthe %s%ncommit." > actual &&
85 test_cmp expect actual
96 test_expect_success
'oneline' '
98 git log --oneline > actual &&
99 test_cmp expect actual
102 test_expect_success
'diff-filter=A' '
104 git log --no-renames --pretty="format:%s" --diff-filter=A HEAD > actual &&
105 git log --no-renames --pretty="format:%s" --diff-filter A HEAD > actual-separate &&
106 printf "fifth\nfourth\nthird\ninitial" > expect &&
107 test_cmp expect actual &&
108 test_cmp expect actual-separate
112 test_expect_success
'diff-filter=M' '
114 actual=$(git log --pretty="format:%s" --diff-filter=M HEAD) &&
115 expect=$(echo second) &&
116 verbose test "$actual" = "$expect"
120 test_expect_success
'diff-filter=D' '
122 actual=$(git log --no-renames --pretty="format:%s" --diff-filter=D HEAD) &&
123 expect=$(echo sixth ; echo third) &&
124 verbose test "$actual" = "$expect"
128 test_expect_success
'diff-filter=R' '
130 actual=$(git log -M --pretty="format:%s" --diff-filter=R HEAD) &&
131 expect=$(echo third) &&
132 verbose test "$actual" = "$expect"
136 test_expect_success
'diff-filter=C' '
138 actual=$(git log -C -C --pretty="format:%s" --diff-filter=C HEAD) &&
139 expect=$(echo fourth) &&
140 verbose test "$actual" = "$expect"
144 test_expect_success
'git log --follow' '
146 actual=$(git log --follow --pretty="format:%s" ichi) &&
147 expect=$(echo third ; echo second ; echo initial) &&
148 verbose test "$actual" = "$expect"
151 test_expect_success
'git config log.follow works like --follow' '
152 test_config log.follow true &&
153 actual=$(git log --pretty="format:%s" ichi) &&
154 expect=$(echo third ; echo second ; echo initial) &&
155 verbose test "$actual" = "$expect"
158 test_expect_success
'git config log.follow does not die with multiple paths' '
159 test_config log.follow true &&
160 git log --pretty="format:%s" ichi ein
163 test_expect_success
'git config log.follow does not die with no paths' '
164 test_config log.follow true &&
168 test_expect_success
'git config log.follow is overridden by --no-follow' '
169 test_config log.follow true &&
170 actual=$(git log --no-follow --pretty="format:%s" ichi) &&
172 verbose test "$actual" = "$expect"
180 test_expect_success
'git log --no-walk <commits> sorts by commit time' '
181 git log --no-walk --oneline 5d31159 804a787 394ef78 > actual &&
182 test_cmp expect actual
185 test_expect_success
'git log --no-walk=sorted <commits> sorts by commit time' '
186 git log --no-walk=sorted --oneline 5d31159 804a787 394ef78 > actual &&
187 test_cmp expect actual
195 test_expect_success
'git log --no-walk=unsorted <commits> leaves list of commits as given' '
196 git log --no-walk=unsorted --oneline 5d31159 804a787 394ef78 > actual &&
197 test_cmp expect actual
200 test_expect_success
'git show <commits> leaves list of commits as given' '
201 git show --oneline -s 5d31159 804a787 394ef78 > actual &&
202 test_cmp expect actual
205 test_expect_success
'setup case sensitivity tests' '
209 git commit -a -m Second
212 test_expect_success
'log --grep' '
213 echo second >expect &&
214 git log -1 --pretty="tformat:%s" --grep=sec >actual &&
215 test_cmp expect actual
222 test_expect_success
'log --invert-grep --grep' '
223 git log --pretty="tformat:%s" --invert-grep --grep=th --grep=Sec >actual &&
224 test_cmp expect actual
227 test_expect_success
'log --invert-grep --grep -i' '
228 echo initial >expect &&
229 git log --pretty="tformat:%s" --invert-grep -i --grep=th --grep=Sec >actual &&
230 test_cmp expect actual
233 test_expect_success
'log --grep option parsing' '
234 echo second >expect &&
235 git log -1 --pretty="tformat:%s" --grep sec >actual &&
236 test_cmp expect actual &&
237 test_must_fail git log -1 --pretty="tformat:%s" --grep
240 test_expect_success
'log -i --grep' '
241 echo Second >expect &&
242 git log -1 --pretty="tformat:%s" -i --grep=sec >actual &&
243 test_cmp expect actual
246 test_expect_success
'log --grep -i' '
247 echo Second >expect &&
248 git log -1 --pretty="tformat:%s" --grep=sec -i >actual &&
249 test_cmp expect actual
252 test_expect_success
'log -F -E --grep=<ere> uses ere' '
253 echo second >expect &&
254 git log -1 --pretty="tformat:%s" -F -E --grep=s.c.nd >actual &&
255 test_cmp expect actual
258 test_expect_success
'log with grep.patternType configuration' '
260 git -c grep.patterntype=fixed \
261 log -1 --pretty=tformat:%s --grep=s.c.nd >actual &&
262 test_cmp expect actual
265 test_expect_success
'log with grep.patternType configuration and command line' '
266 echo second >expect &&
267 git -c grep.patterntype=fixed \
268 log -1 --pretty=tformat:%s --basic-regexp --grep=s.c.nd >actual &&
269 test_cmp expect actual
282 test_expect_success
'simple log --graph' '
283 git log --graph --pretty=tformat:%s >actual &&
284 test_cmp expect actual
287 test_expect_success
'set up merge history' '
288 git checkout -b side HEAD~4 &&
289 test_commit side-1 1 1 &&
290 test_commit side-2 2 2 &&
291 git checkout master &&
296 * Merge branch
'side'
310 test_expect_success
'log --graph with merge' '
311 git log --graph --date-order --pretty=tformat:%s |
312 sed "s/ *\$//" >actual &&
313 test_cmp expect actual
316 test_expect_success
'log --raw --graph -m with merge' '
317 git log --raw --graph --oneline -m master | head -n 500 >actual &&
318 grep "initial" actual
321 test_expect_success
'diff-tree --graph' '
322 git diff-tree --graph master^ | head -n 500 >actual &&
329 | | Author
: A U Thor
<author@example.com
>
331 | | Merge branch
'side'
334 | | Author
: A U Thor
<author@example.com
>
338 |
* commit tags
/side-1
339 | | Author
: A U Thor
<author@example.com
>
344 | | Author
: A U Thor
<author@example.com
>
349 | | Author
: A U Thor
<author@example.com
>
354 | | Author
: A U Thor
<author@example.com
>
359 |
/ Author
: A U Thor
<author@example.com
>
363 * commit tags
/side-1~
1
364 | Author
: A U Thor
<author@example.com
>
368 * commit tags
/side-1~
2
369 | Author
: A U Thor
<author@example.com
>
373 * commit tags
/side-1~
3
374 Author
: A U Thor
<author@example.com
>
379 test_expect_success
'log --graph with full output' '
380 git log --graph --date-order --pretty=short |
381 git name-rev --name-only --stdin |
382 sed "s/Merge:.*/Merge: A B/;s/ *\$//" >actual &&
383 test_cmp expect actual
386 test_expect_success
'set up more tangled history' '
387 git checkout -b tangle HEAD~6 &&
388 test_commit tangle-a tangle-a a &&
389 git merge master~3 &&
391 git checkout master &&
393 git checkout -b reach &&
395 git checkout master &&
396 git checkout -b octopus-a &&
397 test_commit octopus-a &&
398 git checkout master &&
399 git checkout -b octopus-b &&
400 test_commit octopus-b &&
401 git checkout master &&
402 test_commit seventh &&
403 git merge octopus-a octopus-b &&
412 *-. \ Merge tags
'octopus-a' and
'octopus-b'
422 * Merge branch
'tangle'
424 |
* Merge branch
'side' (early part
) into tangle
426 |
* \ Merge branch
'master' (early part
) into tangle
429 * | | | Merge branch
'side'
448 test_expect_success
'log --graph with merge' '
449 git log --graph --date-order --pretty=tformat:%s |
450 sed "s/ *\$//" >actual &&
451 test_cmp expect actual
454 test_expect_success
'log.decorate configuration' '
455 git log --oneline >expect.none &&
456 git log --oneline --decorate >expect.short &&
457 git log --oneline --decorate=full >expect.full &&
459 echo "[log] decorate" >>.git/config &&
460 git log --oneline >actual &&
461 test_cmp expect.short actual &&
463 test_config log.decorate true &&
464 git log --oneline >actual &&
465 test_cmp expect.short actual &&
466 git log --oneline --decorate=full >actual &&
467 test_cmp expect.full actual &&
468 git log --oneline --decorate=no >actual &&
469 test_cmp expect.none actual &&
471 test_config log.decorate no &&
472 git log --oneline >actual &&
473 test_cmp expect.none actual &&
474 git log --oneline --decorate >actual &&
475 test_cmp expect.short actual &&
476 git log --oneline --decorate=full >actual &&
477 test_cmp expect.full actual &&
479 test_config log.decorate 1 &&
480 git log --oneline >actual &&
481 test_cmp expect.short actual &&
482 git log --oneline --decorate=full >actual &&
483 test_cmp expect.full actual &&
484 git log --oneline --decorate=no >actual &&
485 test_cmp expect.none actual &&
487 test_config log.decorate short &&
488 git log --oneline >actual &&
489 test_cmp expect.short actual &&
490 git log --oneline --no-decorate >actual &&
491 test_cmp expect.none actual &&
492 git log --oneline --decorate=full >actual &&
493 test_cmp expect.full actual &&
495 test_config log.decorate full &&
496 git log --oneline >actual &&
497 test_cmp expect.full actual &&
498 git log --oneline --no-decorate >actual &&
499 test_cmp expect.none actual &&
500 git log --oneline --decorate >actual &&
501 test_cmp expect.short actual &&
503 test_unconfig log.decorate &&
504 git log --pretty=raw >expect.raw &&
505 test_config log.decorate full &&
506 git log --pretty=raw >actual &&
507 test_cmp expect.raw actual
511 test_expect_success
'reflog is expected format' '
512 git log -g --abbrev-commit --pretty=oneline >expect &&
513 git reflog >actual &&
514 test_cmp expect actual
517 test_expect_success
'whatchanged is expected format' '
518 git log --no-merges --raw >expect &&
519 git whatchanged >actual &&
520 test_cmp expect actual
523 test_expect_success
'log.abbrevCommit configuration' '
524 git log --abbrev-commit >expect.log.abbrev &&
525 git log --no-abbrev-commit >expect.log.full &&
526 git log --pretty=raw >expect.log.raw &&
527 git reflog --abbrev-commit >expect.reflog.abbrev &&
528 git reflog --no-abbrev-commit >expect.reflog.full &&
529 git whatchanged --abbrev-commit >expect.whatchanged.abbrev &&
530 git whatchanged --no-abbrev-commit >expect.whatchanged.full &&
532 test_config log.abbrevCommit true &&
535 test_cmp expect.log.abbrev actual &&
536 git log --no-abbrev-commit >actual &&
537 test_cmp expect.log.full actual &&
539 git log --pretty=raw >actual &&
540 test_cmp expect.log.raw actual &&
542 git reflog >actual &&
543 test_cmp expect.reflog.abbrev actual &&
544 git reflog --no-abbrev-commit >actual &&
545 test_cmp expect.reflog.full actual &&
547 git whatchanged >actual &&
548 test_cmp expect.whatchanged.abbrev actual &&
549 git whatchanged --no-abbrev-commit >actual &&
550 test_cmp expect.whatchanged.full actual
553 test_expect_success
'show added path under "--follow -M"' '
554 # This tests for a regression introduced in v1.7.2-rc0~103^2~2
555 test_create_repo regression &&
558 test_commit needs-another-commit &&
559 test_commit foo.bar &&
560 git log -M --follow -p foo.bar.t &&
561 git log -M --follow --stat foo.bar.t &&
562 git log -M --follow --name-only foo.bar.t
566 test_expect_success
'git log -c --follow' '
567 test_create_repo follow-c &&
570 test_commit initial file original &&
572 test_commit rename file2 original &&
573 git reset --hard initial &&
574 test_commit modify file foo &&
575 git merge -m merge rename &&
576 git log -c --follow file2
581 * commit COMMIT_OBJECT_NAME
582 |\ Merge
: MERGE_PARENTS
583 | | Author
: A U Thor
<author@example.com
>
585 | | Merge HEADS DESCRIPTION
587 |
* commit COMMIT_OBJECT_NAME
588 | | Author
: A U Thor
<author@example.com
>
593 | |
1 file changed
, 1 insertion
(+)
595 | |
diff --git a
/reach.t b
/reach.t
596 | | new
file mode
100644
597 | | index
0000000.
.10c9591
604 *-. \ commit COMMIT_OBJECT_NAME
605 |\ \ \ Merge
: MERGE_PARENTS
606 | | | | Author
: A U Thor
<author@example.com
>
608 | | | | Merge HEADS DESCRIPTION
610 | |
* | commit COMMIT_OBJECT_NAME
611 | | |
/ Author
: A U Thor
<author@example.com
>
615 | | | octopus-b.t |
1 +
616 | | |
1 file changed
, 1 insertion
(+)
618 | | |
diff --git a
/octopus-b.t b
/octopus-b.t
619 | | | new
file mode
100644
620 | | | index
0000000..d5fcad0
622 | | |
+++ b
/octopus-b.t
626 |
* | commit COMMIT_OBJECT_NAME
627 | |
/ Author
: A U Thor
<author@example.com
>
631 | | octopus-a.t |
1 +
632 | |
1 file changed
, 1 insertion
(+)
634 | |
diff --git a
/octopus-a.t b
/octopus-a.t
635 | | new
file mode
100644
636 | | index
0000000.
.11ee015
638 | |
+++ b
/octopus-a.t
642 * | commit COMMIT_OBJECT_NAME
643 |
/ Author
: A U Thor
<author@example.com
>
648 |
1 file changed
, 1 insertion
(+)
650 |
diff --git a
/seventh.t b
/seventh.t
651 | new
file mode
100644
652 | index
0000000.
.9744ffc
658 * commit COMMIT_OBJECT_NAME
659 |\ Merge
: MERGE_PARENTS
660 | | Author
: A U Thor
<author@example.com
>
662 | | Merge branch
'tangle'
664 |
* commit COMMIT_OBJECT_NAME
665 | |\ Merge
: MERGE_PARENTS
666 | | | Author
: A U Thor
<author@example.com
>
668 | | | Merge branch
'side' (early part
) into tangle
670 |
* | commit COMMIT_OBJECT_NAME
671 | |\ \ Merge
: MERGE_PARENTS
672 | | | | Author
: A U Thor
<author@example.com
>
674 | | | | Merge branch
'master' (early part
) into tangle
676 |
* | | commit COMMIT_OBJECT_NAME
677 | | | | Author
: A U Thor
<author@example.com
>
681 | | | | tangle-a |
1 +
682 | | | |
1 file changed
, 1 insertion
(+)
684 | | | |
diff --git a
/tangle-a b
/tangle-a
685 | | | | new
file mode
100644
686 | | | | index
0000000.
.7898192
687 | | | |
--- /dev
/null
688 | | | |
+++ b
/tangle-a
689 | | | | @@
-0,0 +1 @@
692 * | | | commit COMMIT_OBJECT_NAME
693 |\ \ \ \ Merge
: MERGE_PARENTS
694 | | | | | Author
: A U Thor
<author@example.com
>
696 | | | | | Merge branch
'side'
698 |
* | | | commit COMMIT_OBJECT_NAME
699 | | |_|
/ Author
: A U Thor
<author@example.com
>
704 | | | |
1 file changed
, 1 insertion
(+)
706 | | | |
diff --git a
/2 b
/2
707 | | | | new
file mode
100644
708 | | | | index
0000000.
.0cfbf08
709 | | | |
--- /dev
/null
711 | | | | @@
-0,0 +1 @@
714 |
* | | commit COMMIT_OBJECT_NAME
715 | | | | Author
: A U Thor
<author@example.com
>
720 | | | |
1 file changed
, 1 insertion
(+)
722 | | | |
diff --git a
/1 b
/1
723 | | | | new
file mode
100644
724 | | | | index
0000000..d00491f
725 | | | |
--- /dev
/null
727 | | | | @@
-0,0 +1 @@
730 * | | | commit COMMIT_OBJECT_NAME
731 | | | | Author
: A U Thor
<author@example.com
>
736 | | | |
1 file changed
, 1 insertion
(+)
738 | | | |
diff --git a
/one b
/one
739 | | | | new
file mode
100644
740 | | | | index
0000000.
.9a33383
741 | | | |
--- /dev
/null
743 | | | | @@
-0,0 +1 @@
746 * | | | commit COMMIT_OBJECT_NAME
747 | |_|
/ Author
: A U Thor
<author@example.com
>
752 | | |
1 file changed
, 1 deletion
(-)
754 | | |
diff --git a
/a
/two b
/a
/two
755 | | | deleted
file mode
100644
756 | | | index
9245af5.
.0000000
762 * | | commit COMMIT_OBJECT_NAME
763 | | | Author
: A U Thor
<author@example.com
>
768 | | |
1 file changed
, 1 insertion
(+)
770 | | |
diff --git a
/a
/two b
/a
/two
771 | | | new
file mode
100644
772 | | | index
0000000.
.9245af5
778 * | | commit COMMIT_OBJECT_NAME
779 |
/ / Author
: A U Thor
<author@example.com
>
784 | |
1 file changed
, 1 insertion
(+)
786 | |
diff --git a
/ein b
/ein
787 | | new
file mode
100644
788 | | index
0000000.
.9d7e69f
794 * | commit COMMIT_OBJECT_NAME
795 |
/ Author
: A U Thor
<author@example.com
>
801 |
2 files changed
, 1 insertion
(+), 1 deletion
(-)
803 |
diff --git a
/ichi b
/ichi
804 | new
file mode
100644
805 | index
0000000.
.9d7e69f
810 |
diff --git a
/one b
/one
811 | deleted
file mode
100644
812 | index
9d7e69f.
.0000000
818 * commit COMMIT_OBJECT_NAME
819 | Author
: A U Thor
<author@example.com
>
824 |
1 file changed
, 1 insertion
(+), 1 deletion
(-)
826 |
diff --git a
/one b
/one
827 | index
5626abf.
.9d7e69f
100644
834 * commit COMMIT_OBJECT_NAME
835 Author
: A U Thor
<author@example.com
>
840 1 file changed
, 1 insertion
(+)
842 diff --git a
/one b
/one
844 index
0000000.
.5626abf
853 -e 's/commit [0-9a-f]*$/commit COMMIT_OBJECT_NAME/' \
854 -e 's/Merge: [ 0-9a-f]*$/Merge: MERGE_PARENTS/' \
855 -e 's/Merge tag.*/Merge HEADS DESCRIPTION/' \
856 -e 's/Merge commit.*/Merge HEADS DESCRIPTION/' \
857 -e 's/, 0 deletions(-)//' \
858 -e 's/, 0 insertions(+)//' \
859 -e 's/ 1 files changed, / 1 file changed, /' \
860 -e 's/, 1 deletions(-)/, 1 deletion(-)/' \
861 -e 's/, 1 insertions(+)/, 1 insertion(+)/'
864 test_expect_success
'log --graph with diff and stats' '
865 git log --no-renames --graph --pretty=short --stat -p >actual &&
866 sanitize_output >actual.sanitized <actual &&
867 test_i18ncmp expect actual.sanitized
870 test_expect_success
'dotdot is a parent directory' '
872 ( echo sixth && echo fifth ) >expect &&
873 ( cd a/b && git log --format=%s .. ) >actual &&
874 test_cmp expect actual
877 test_expect_success GPG
'log --graph --show-signature' '
878 test_when_finished "git reset --hard && git checkout master" &&
879 git checkout -b signed master &&
882 git commit -S -m signed_commit &&
883 git log --graph --show-signature -n1 signed >actual &&
884 grep "^| gpg: Signature made" actual &&
885 grep "^| gpg: Good signature" actual
888 test_expect_success GPG
'log --graph --show-signature for merged tag' '
889 test_when_finished "git reset --hard && git checkout master" &&
890 git checkout -b plain master &&
893 git commit -m bar_commit &&
894 git checkout -b tagged master &&
897 git commit -m baz_commit &&
898 git tag -s -m signed_tag_msg signed_tag &&
899 git checkout plain &&
900 git merge --no-ff -m msg signed_tag &&
901 git log --graph --show-signature -n1 plain >actual &&
902 grep "^|\\\ merged tag" actual &&
903 grep "^| | gpg: Signature made" actual &&
904 grep "^| | gpg: Good signature" actual
907 test_expect_success
'log --graph --no-walk is forbidden' '
908 test_must_fail git log --graph --no-walk
911 test_expect_success
'log diagnoses bogus HEAD' '
913 test_must_fail git -C empty log 2>stderr &&
914 test_i18ngrep does.not.have.any.commits stderr &&
915 echo 1234abcd >empty/.git/refs/heads/master &&
916 test_must_fail git -C empty log 2>stderr &&
917 test_i18ngrep broken stderr &&
918 echo "ref: refs/heads/invalid.lock" >empty/.git/HEAD &&
919 test_must_fail git -C empty log 2>stderr &&
920 test_i18ngrep broken stderr &&
921 test_must_fail git -C empty log --default totally-bogus 2>stderr &&
922 test_i18ngrep broken stderr
925 test_expect_success
'set up --source tests' '
926 git checkout --orphan source-a &&
929 git checkout -b source-b HEAD^ &&
933 test_expect_success
'log --source paints branch names' '
934 cat >expect <<-\EOF &&
935 09e12a9 source-b three
939 git log --oneline --source source-a source-b >actual &&
940 test_cmp expect actual
943 test_expect_success
'log --source paints tag names' '
944 git tag -m tagged source-tag &&
945 cat >expect <<-\EOF &&
946 09e12a9 source-tag three
948 1ac6c77 source-tag one
950 git log --oneline --source source-tag source-a >actual &&
951 test_cmp expect actual