git stash: make sure that .git/logs/refs/ exists
[git/mingw/4msysgit.git] / t / t4202-log.sh
blobcb03d287698f110b66e69636348caccdbe6a94f8
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(11,1,2)' '
77 git log -2 --format="%w(11,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 test_expect_success 'log -F -E --grep=<ere> uses ere' '
234 echo second >expect &&
235 git log -1 --pretty="tformat:%s" -F -E --grep=s.c.nd >actual &&
236 test_cmp expect actual
239 cat > expect <<EOF
240 * Second
241 * sixth
242 * fifth
243 * fourth
244 * third
245 * second
246 * initial
249 test_expect_success 'simple log --graph' '
250 git log --graph --pretty=tformat:%s >actual &&
251 test_cmp expect actual
254 test_expect_success 'set up merge history' '
255 git checkout -b side HEAD~4 &&
256 test_commit side-1 1 1 &&
257 test_commit side-2 2 2 &&
258 git checkout master &&
259 git merge side
262 cat > expect <<\EOF
263 * Merge branch 'side'
265 | * side-2
266 | * side-1
267 * | Second
268 * | sixth
269 * | fifth
270 * | fourth
272 * third
273 * second
274 * initial
277 test_expect_success 'log --graph with merge' '
278 git log --graph --date-order --pretty=tformat:%s |
279 sed "s/ *\$//" >actual &&
280 test_cmp expect actual
283 test_expect_success 'log --raw --graph -m with merge' '
284 git log --raw --graph --oneline -m master | head -n 500 >actual &&
285 grep "initial" actual
288 test_expect_success 'diff-tree --graph' '
289 git diff-tree --graph master^ | head -n 500 >actual &&
290 grep "one" actual
293 cat > expect <<\EOF
294 * commit master
295 |\ Merge: A B
296 | | Author: A U Thor <author@example.com>
298 | | Merge branch 'side'
300 | * commit side
301 | | Author: A U Thor <author@example.com>
303 | | side-2
305 | * commit tags/side-1
306 | | Author: A U Thor <author@example.com>
308 | | side-1
310 * | commit master~1
311 | | Author: A U Thor <author@example.com>
313 | | Second
315 * | commit master~2
316 | | Author: A U Thor <author@example.com>
318 | | sixth
320 * | commit master~3
321 | | Author: A U Thor <author@example.com>
323 | | fifth
325 * | commit master~4
326 |/ Author: A U Thor <author@example.com>
328 | fourth
330 * commit tags/side-1~1
331 | Author: A U Thor <author@example.com>
333 | third
335 * commit tags/side-1~2
336 | Author: A U Thor <author@example.com>
338 | second
340 * commit tags/side-1~3
341 Author: A U Thor <author@example.com>
343 initial
346 test_expect_success 'log --graph with full output' '
347 git log --graph --date-order --pretty=short |
348 git name-rev --name-only --stdin |
349 sed "s/Merge:.*/Merge: A B/;s/ *\$//" >actual &&
350 test_cmp expect actual
353 test_expect_success 'set up more tangled history' '
354 git checkout -b tangle HEAD~6 &&
355 test_commit tangle-a tangle-a a &&
356 git merge master~3 &&
357 git merge side~1 &&
358 git checkout master &&
359 git merge tangle &&
360 git checkout -b reach &&
361 test_commit reach &&
362 git checkout master &&
363 git checkout -b octopus-a &&
364 test_commit octopus-a &&
365 git checkout master &&
366 git checkout -b octopus-b &&
367 test_commit octopus-b &&
368 git checkout master &&
369 test_commit seventh &&
370 git merge octopus-a octopus-b &&
371 git merge reach
374 cat > expect <<\EOF
375 * Merge tag 'reach'
379 *-. \ Merge tags 'octopus-a' and 'octopus-b'
380 |\ \ \
381 * | | | seventh
382 | | * | octopus-b
383 | |/ /
384 |/| |
385 | * | octopus-a
386 |/ /
387 | * reach
389 * Merge branch 'tangle'
391 | * Merge branch 'side' (early part) into tangle
392 | |\
393 | * \ Merge branch 'master' (early part) into tangle
394 | |\ \
395 | * | | tangle-a
396 * | | | Merge branch 'side'
397 |\ \ \ \
398 | * | | | side-2
399 | | |_|/
400 | |/| |
401 | * | | side-1
402 * | | | Second
403 * | | | sixth
404 | |_|/
405 |/| |
406 * | | fifth
407 * | | fourth
408 |/ /
409 * | third
411 * second
412 * initial
415 test_expect_success 'log --graph with merge' '
416 git log --graph --date-order --pretty=tformat:%s |
417 sed "s/ *\$//" >actual &&
418 test_cmp expect actual
421 test_expect_success 'log.decorate configuration' '
422 git log --oneline >expect.none &&
423 git log --oneline --decorate >expect.short &&
424 git log --oneline --decorate=full >expect.full &&
426 echo "[log] decorate" >>.git/config &&
427 git log --oneline >actual &&
428 test_cmp expect.short actual &&
430 test_config log.decorate true &&
431 git log --oneline >actual &&
432 test_cmp expect.short actual &&
433 git log --oneline --decorate=full >actual &&
434 test_cmp expect.full actual &&
435 git log --oneline --decorate=no >actual &&
436 test_cmp expect.none actual &&
438 test_config log.decorate no &&
439 git log --oneline >actual &&
440 test_cmp expect.none actual &&
441 git log --oneline --decorate >actual &&
442 test_cmp expect.short actual &&
443 git log --oneline --decorate=full >actual &&
444 test_cmp expect.full actual &&
446 test_config log.decorate 1 &&
447 git log --oneline >actual &&
448 test_cmp expect.short actual &&
449 git log --oneline --decorate=full >actual &&
450 test_cmp expect.full actual &&
451 git log --oneline --decorate=no >actual &&
452 test_cmp expect.none actual &&
454 test_config log.decorate short &&
455 git log --oneline >actual &&
456 test_cmp expect.short actual &&
457 git log --oneline --no-decorate >actual &&
458 test_cmp expect.none actual &&
459 git log --oneline --decorate=full >actual &&
460 test_cmp expect.full actual &&
462 test_config log.decorate full &&
463 git log --oneline >actual &&
464 test_cmp expect.full actual &&
465 git log --oneline --no-decorate >actual &&
466 test_cmp expect.none actual &&
467 git log --oneline --decorate >actual &&
468 test_cmp expect.short actual
470 test_unconfig log.decorate &&
471 git log --pretty=raw >expect.raw &&
472 test_config log.decorate full &&
473 git log --pretty=raw >actual &&
474 test_cmp expect.raw actual
478 test_expect_success 'reflog is expected format' '
479 git log -g --abbrev-commit --pretty=oneline >expect &&
480 git reflog >actual &&
481 test_cmp expect actual
484 test_expect_success 'whatchanged is expected format' '
485 git log --no-merges --raw >expect &&
486 git whatchanged >actual &&
487 test_cmp expect actual
490 test_expect_success 'log.abbrevCommit configuration' '
491 git log --abbrev-commit >expect.log.abbrev &&
492 git log --no-abbrev-commit >expect.log.full &&
493 git log --pretty=raw >expect.log.raw &&
494 git reflog --abbrev-commit >expect.reflog.abbrev &&
495 git reflog --no-abbrev-commit >expect.reflog.full &&
496 git whatchanged --abbrev-commit >expect.whatchanged.abbrev &&
497 git whatchanged --no-abbrev-commit >expect.whatchanged.full &&
499 test_config log.abbrevCommit true &&
501 git log >actual &&
502 test_cmp expect.log.abbrev actual &&
503 git log --no-abbrev-commit >actual &&
504 test_cmp expect.log.full actual &&
506 git log --pretty=raw >actual &&
507 test_cmp expect.log.raw actual &&
509 git reflog >actual &&
510 test_cmp expect.reflog.abbrev actual &&
511 git reflog --no-abbrev-commit >actual &&
512 test_cmp expect.reflog.full actual &&
514 git whatchanged >actual &&
515 test_cmp expect.whatchanged.abbrev actual &&
516 git whatchanged --no-abbrev-commit >actual &&
517 test_cmp expect.whatchanged.full actual
520 test_expect_success 'show added path under "--follow -M"' '
521 # This tests for a regression introduced in v1.7.2-rc0~103^2~2
522 test_create_repo regression &&
524 cd regression &&
525 test_commit needs-another-commit &&
526 test_commit foo.bar &&
527 git log -M --follow -p foo.bar.t &&
528 git log -M --follow --stat foo.bar.t &&
529 git log -M --follow --name-only foo.bar.t
533 test_expect_success 'git log -c --follow' '
534 test_create_repo follow-c &&
536 cd follow-c &&
537 test_commit initial file original &&
538 git rm file &&
539 test_commit rename file2 original &&
540 git reset --hard initial &&
541 test_commit modify file foo &&
542 git merge -m merge rename &&
543 git log -c --follow file2
547 cat >expect <<\EOF
548 * commit COMMIT_OBJECT_NAME
549 |\ Merge: MERGE_PARENTS
550 | | Author: A U Thor <author@example.com>
552 | | Merge HEADS DESCRIPTION
554 | * commit COMMIT_OBJECT_NAME
555 | | Author: A U Thor <author@example.com>
557 | | reach
558 | | ---
559 | | reach.t | 1 +
560 | | 1 file changed, 1 insertion(+)
562 | | diff --git a/reach.t b/reach.t
563 | | new file mode 100644
564 | | index 0000000..10c9591
565 | | --- /dev/null
566 | | +++ b/reach.t
567 | | @@ -0,0 +1 @@
568 | | +reach
571 *-. \ commit COMMIT_OBJECT_NAME
572 |\ \ \ Merge: MERGE_PARENTS
573 | | | | Author: A U Thor <author@example.com>
574 | | | |
575 | | | | Merge HEADS DESCRIPTION
576 | | | |
577 | | * | commit COMMIT_OBJECT_NAME
578 | | |/ Author: A U Thor <author@example.com>
579 | | |
580 | | | octopus-b
581 | | | ---
582 | | | octopus-b.t | 1 +
583 | | | 1 file changed, 1 insertion(+)
584 | | |
585 | | | diff --git a/octopus-b.t b/octopus-b.t
586 | | | new file mode 100644
587 | | | index 0000000..d5fcad0
588 | | | --- /dev/null
589 | | | +++ b/octopus-b.t
590 | | | @@ -0,0 +1 @@
591 | | | +octopus-b
592 | | |
593 | * | commit COMMIT_OBJECT_NAME
594 | |/ Author: A U Thor <author@example.com>
596 | | octopus-a
597 | | ---
598 | | octopus-a.t | 1 +
599 | | 1 file changed, 1 insertion(+)
601 | | diff --git a/octopus-a.t b/octopus-a.t
602 | | new file mode 100644
603 | | index 0000000..11ee015
604 | | --- /dev/null
605 | | +++ b/octopus-a.t
606 | | @@ -0,0 +1 @@
607 | | +octopus-a
609 * | commit COMMIT_OBJECT_NAME
610 |/ Author: A U Thor <author@example.com>
612 | seventh
613 | ---
614 | seventh.t | 1 +
615 | 1 file changed, 1 insertion(+)
617 | diff --git a/seventh.t b/seventh.t
618 | new file mode 100644
619 | index 0000000..9744ffc
620 | --- /dev/null
621 | +++ b/seventh.t
622 | @@ -0,0 +1 @@
623 | +seventh
625 * commit COMMIT_OBJECT_NAME
626 |\ Merge: MERGE_PARENTS
627 | | Author: A U Thor <author@example.com>
629 | | Merge branch 'tangle'
631 | * commit COMMIT_OBJECT_NAME
632 | |\ Merge: MERGE_PARENTS
633 | | | Author: A U Thor <author@example.com>
634 | | |
635 | | | Merge branch 'side' (early part) into tangle
636 | | |
637 | * | commit COMMIT_OBJECT_NAME
638 | |\ \ Merge: MERGE_PARENTS
639 | | | | Author: A U Thor <author@example.com>
640 | | | |
641 | | | | Merge branch 'master' (early part) into tangle
642 | | | |
643 | * | | commit COMMIT_OBJECT_NAME
644 | | | | Author: A U Thor <author@example.com>
645 | | | |
646 | | | | tangle-a
647 | | | | ---
648 | | | | tangle-a | 1 +
649 | | | | 1 file changed, 1 insertion(+)
650 | | | |
651 | | | | diff --git a/tangle-a b/tangle-a
652 | | | | new file mode 100644
653 | | | | index 0000000..7898192
654 | | | | --- /dev/null
655 | | | | +++ b/tangle-a
656 | | | | @@ -0,0 +1 @@
657 | | | | +a
658 | | | |
659 * | | | commit COMMIT_OBJECT_NAME
660 |\ \ \ \ Merge: MERGE_PARENTS
661 | | | | | Author: A U Thor <author@example.com>
662 | | | | |
663 | | | | | Merge branch 'side'
664 | | | | |
665 | * | | | commit COMMIT_OBJECT_NAME
666 | | |_|/ Author: A U Thor <author@example.com>
667 | |/| |
668 | | | | side-2
669 | | | | ---
670 | | | | 2 | 1 +
671 | | | | 1 file changed, 1 insertion(+)
672 | | | |
673 | | | | diff --git a/2 b/2
674 | | | | new file mode 100644
675 | | | | index 0000000..0cfbf08
676 | | | | --- /dev/null
677 | | | | +++ b/2
678 | | | | @@ -0,0 +1 @@
679 | | | | +2
680 | | | |
681 | * | | commit COMMIT_OBJECT_NAME
682 | | | | Author: A U Thor <author@example.com>
683 | | | |
684 | | | | side-1
685 | | | | ---
686 | | | | 1 | 1 +
687 | | | | 1 file changed, 1 insertion(+)
688 | | | |
689 | | | | diff --git a/1 b/1
690 | | | | new file mode 100644
691 | | | | index 0000000..d00491f
692 | | | | --- /dev/null
693 | | | | +++ b/1
694 | | | | @@ -0,0 +1 @@
695 | | | | +1
696 | | | |
697 * | | | commit COMMIT_OBJECT_NAME
698 | | | | Author: A U Thor <author@example.com>
699 | | | |
700 | | | | Second
701 | | | | ---
702 | | | | one | 1 +
703 | | | | 1 file changed, 1 insertion(+)
704 | | | |
705 | | | | diff --git a/one b/one
706 | | | | new file mode 100644
707 | | | | index 0000000..9a33383
708 | | | | --- /dev/null
709 | | | | +++ b/one
710 | | | | @@ -0,0 +1 @@
711 | | | | +case
712 | | | |
713 * | | | commit COMMIT_OBJECT_NAME
714 | |_|/ Author: A U Thor <author@example.com>
715 |/| |
716 | | | sixth
717 | | | ---
718 | | | a/two | 1 -
719 | | | 1 file changed, 1 deletion(-)
720 | | |
721 | | | diff --git a/a/two b/a/two
722 | | | deleted file mode 100644
723 | | | index 9245af5..0000000
724 | | | --- a/a/two
725 | | | +++ /dev/null
726 | | | @@ -1 +0,0 @@
727 | | | -ni
728 | | |
729 * | | commit COMMIT_OBJECT_NAME
730 | | | Author: A U Thor <author@example.com>
731 | | |
732 | | | fifth
733 | | | ---
734 | | | a/two | 1 +
735 | | | 1 file changed, 1 insertion(+)
736 | | |
737 | | | diff --git a/a/two b/a/two
738 | | | new file mode 100644
739 | | | index 0000000..9245af5
740 | | | --- /dev/null
741 | | | +++ b/a/two
742 | | | @@ -0,0 +1 @@
743 | | | +ni
744 | | |
745 * | | commit COMMIT_OBJECT_NAME
746 |/ / Author: A U Thor <author@example.com>
748 | | fourth
749 | | ---
750 | | ein | 1 +
751 | | 1 file changed, 1 insertion(+)
753 | | diff --git a/ein b/ein
754 | | new file mode 100644
755 | | index 0000000..9d7e69f
756 | | --- /dev/null
757 | | +++ b/ein
758 | | @@ -0,0 +1 @@
759 | | +ichi
761 * | commit COMMIT_OBJECT_NAME
762 |/ Author: A U Thor <author@example.com>
764 | third
765 | ---
766 | ichi | 1 +
767 | one | 1 -
768 | 2 files changed, 1 insertion(+), 1 deletion(-)
770 | diff --git a/ichi b/ichi
771 | new file mode 100644
772 | index 0000000..9d7e69f
773 | --- /dev/null
774 | +++ b/ichi
775 | @@ -0,0 +1 @@
776 | +ichi
777 | diff --git a/one b/one
778 | deleted file mode 100644
779 | index 9d7e69f..0000000
780 | --- a/one
781 | +++ /dev/null
782 | @@ -1 +0,0 @@
783 | -ichi
785 * commit COMMIT_OBJECT_NAME
786 | Author: A U Thor <author@example.com>
788 | second
789 | ---
790 | one | 2 +-
791 | 1 file changed, 1 insertion(+), 1 deletion(-)
793 | diff --git a/one b/one
794 | index 5626abf..9d7e69f 100644
795 | --- a/one
796 | +++ b/one
797 | @@ -1 +1 @@
798 | -one
799 | +ichi
801 * commit COMMIT_OBJECT_NAME
802 Author: A U Thor <author@example.com>
804 initial
806 one | 1 +
807 1 file changed, 1 insertion(+)
809 diff --git a/one b/one
810 new file mode 100644
811 index 0000000..5626abf
812 --- /dev/null
813 +++ b/one
814 @@ -0,0 +1 @@
815 +one
818 sanitize_output () {
819 sed -e 's/ *$//' \
820 -e 's/commit [0-9a-f]*$/commit COMMIT_OBJECT_NAME/' \
821 -e 's/Merge: [ 0-9a-f]*$/Merge: MERGE_PARENTS/' \
822 -e 's/Merge tag.*/Merge HEADS DESCRIPTION/' \
823 -e 's/Merge commit.*/Merge HEADS DESCRIPTION/' \
824 -e 's/, 0 deletions(-)//' \
825 -e 's/, 0 insertions(+)//' \
826 -e 's/ 1 files changed, / 1 file changed, /' \
827 -e 's/, 1 deletions(-)/, 1 deletion(-)/' \
828 -e 's/, 1 insertions(+)/, 1 insertion(+)/'
831 test_expect_success 'log --graph with diff and stats' '
832 git log --graph --pretty=short --stat -p >actual &&
833 sanitize_output >actual.sanitized <actual &&
834 test_i18ncmp expect actual.sanitized
837 test_expect_success 'dotdot is a parent directory' '
838 mkdir -p a/b &&
839 ( echo sixth && echo fifth ) >expect &&
840 ( cd a/b && git log --format=%s .. ) >actual &&
841 test_cmp expect actual
844 test_done