log --graph: customize the graph lines with config log.graphColors
[git] / t / t4202-log.sh
1 #!/bin/sh
2
3 test_description='git log'
4
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY/lib-gpg.sh"
7
8 test_expect_success setup '
9
10         echo one >one &&
11         git add one &&
12         test_tick &&
13         git commit -m initial &&
14
15         echo ichi >one &&
16         git add one &&
17         test_tick &&
18         git commit -m second &&
19
20         git mv one ichi &&
21         test_tick &&
22         git commit -m third &&
23
24         cp ichi ein &&
25         git add ein &&
26         test_tick &&
27         git commit -m fourth &&
28
29         mkdir a &&
30         echo ni >a/two &&
31         git add a/two &&
32         test_tick &&
33         git commit -m fifth  &&
34
35         git rm a/two &&
36         test_tick &&
37         git commit -m sixth
38
39 '
40
41 printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial" > expect
42 test_expect_success 'pretty' '
43
44         git log --pretty="format:%s" > actual &&
45         test_cmp expect actual
46 '
47
48 printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial\n" > expect
49 test_expect_success 'pretty (tformat)' '
50
51         git log --pretty="tformat:%s" > actual &&
52         test_cmp expect actual
53 '
54
55 test_expect_success 'pretty (shortcut)' '
56
57         git log --pretty="%s" > actual &&
58         test_cmp expect actual
59 '
60
61 test_expect_success 'format' '
62
63         git log --format="%s" > actual &&
64         test_cmp expect actual
65 '
66
67 cat > expect << EOF
68  This is
69   the sixth
70   commit.
71  This is
72   the fifth
73   commit.
74 EOF
75
76 test_expect_success 'format %w(11,1,2)' '
77
78         git log -2 --format="%w(11,1,2)This is the %s commit." > actual &&
79         test_cmp expect actual
80 '
81
82 test_expect_success 'format %w(,1,2)' '
83
84         git log -2 --format="%w(,1,2)This is%nthe %s%ncommit." > actual &&
85         test_cmp expect actual
86 '
87
88 cat > expect << EOF
89 804a787 sixth
90 394ef78 fifth
91 5d31159 fourth
92 2fbe8c0 third
93 f7dab8e second
94 3a2fdcb initial
95 EOF
96 test_expect_success 'oneline' '
97
98         git log --oneline > actual &&
99         test_cmp expect actual
100 '
101
102 test_expect_success 'diff-filter=A' '
103
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
109
110 '
111
112 test_expect_success 'diff-filter=M' '
113
114         actual=$(git log --pretty="format:%s" --diff-filter=M HEAD) &&
115         expect=$(echo second) &&
116         verbose test "$actual" = "$expect"
117
118 '
119
120 test_expect_success 'diff-filter=D' '
121
122         actual=$(git log --no-renames --pretty="format:%s" --diff-filter=D HEAD) &&
123         expect=$(echo sixth ; echo third) &&
124         verbose test "$actual" = "$expect"
125
126 '
127
128 test_expect_success 'diff-filter=R' '
129
130         actual=$(git log -M --pretty="format:%s" --diff-filter=R HEAD) &&
131         expect=$(echo third) &&
132         verbose test "$actual" = "$expect"
133
134 '
135
136 test_expect_success 'diff-filter=C' '
137
138         actual=$(git log -C -C --pretty="format:%s" --diff-filter=C HEAD) &&
139         expect=$(echo fourth) &&
140         verbose test "$actual" = "$expect"
141
142 '
143
144 test_expect_success 'git log --follow' '
145
146         actual=$(git log --follow --pretty="format:%s" ichi) &&
147         expect=$(echo third ; echo second ; echo initial) &&
148         verbose test "$actual" = "$expect"
149 '
150
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"
156 '
157
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
161 '
162
163 test_expect_success 'git config log.follow does not die with no paths' '
164         test_config log.follow true &&
165         git log --
166 '
167
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) &&
171         expect="third" &&
172         verbose test "$actual" = "$expect"
173 '
174
175 cat > expect << EOF
176 804a787 sixth
177 394ef78 fifth
178 5d31159 fourth
179 EOF
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
183 '
184
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
188 '
189
190 cat > expect << EOF
191 5d31159 fourth
192 804a787 sixth
193 394ef78 fifth
194 EOF
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
198 '
199
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
203 '
204
205 test_expect_success 'setup case sensitivity tests' '
206         echo case >one &&
207         test_tick &&
208         git add one &&
209         git commit -a -m Second
210 '
211
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
216 '
217
218 cat > expect << EOF
219 second
220 initial
221 EOF
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
225 '
226
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
231 '
232
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
238 '
239
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
244 '
245
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
250 '
251
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
256 '
257
258 test_expect_success 'log with grep.patternType configuration' '
259         >expect &&
260         git -c grep.patterntype=fixed \
261         log -1 --pretty=tformat:%s --grep=s.c.nd >actual &&
262         test_cmp expect actual
263 '
264
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
270 '
271
272 cat > expect <<EOF
273 * Second
274 * sixth
275 * fifth
276 * fourth
277 * third
278 * second
279 * initial
280 EOF
281
282 test_expect_success 'simple log --graph' '
283         git log --graph --pretty=tformat:%s >actual &&
284         test_cmp expect actual
285 '
286
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 &&
292         git merge side
293 '
294
295 cat > expect <<\EOF
296 *   Merge branch 'side'
297 |\
298 | * side-2
299 | * side-1
300 * | Second
301 * | sixth
302 * | fifth
303 * | fourth
304 |/
305 * third
306 * second
307 * initial
308 EOF
309
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
314 '
315
316 cat > expect.colors <<\EOF
317 *   Merge branch 'side'
318 <BLUE>|<RESET><CYAN>\<RESET>
319 <BLUE>|<RESET> * side-2
320 <BLUE>|<RESET> * side-1
321 * <CYAN>|<RESET> Second
322 * <CYAN>|<RESET> sixth
323 * <CYAN>|<RESET> fifth
324 * <CYAN>|<RESET> fourth
325 <CYAN>|<RESET><CYAN>/<RESET>
326 * third
327 * second
328 * initial
329 EOF
330
331 test_expect_success 'log --graph with merge with log.graphColors' '
332         test_config log.graphColors ",, blue,invalid-color, cyan, red  , " &&
333         git log --color=always --graph --date-order --pretty=tformat:%s |
334                 test_decode_color | sed "s/ *\$//" >actual &&
335         test_cmp expect.colors actual
336 '
337
338 test_expect_success 'log --raw --graph -m with merge' '
339         git log --raw --graph --oneline -m master | head -n 500 >actual &&
340         grep "initial" actual
341 '
342
343 test_expect_success 'diff-tree --graph' '
344         git diff-tree --graph master^ | head -n 500 >actual &&
345         grep "one" actual
346 '
347
348 cat > expect <<\EOF
349 *   commit master
350 |\  Merge: A B
351 | | Author: A U Thor <author@example.com>
352 | |
353 | |     Merge branch 'side'
354 | |
355 | * commit side
356 | | Author: A U Thor <author@example.com>
357 | |
358 | |     side-2
359 | |
360 | * commit tags/side-1
361 | | Author: A U Thor <author@example.com>
362 | |
363 | |     side-1
364 | |
365 * | commit master~1
366 | | Author: A U Thor <author@example.com>
367 | |
368 | |     Second
369 | |
370 * | commit master~2
371 | | Author: A U Thor <author@example.com>
372 | |
373 | |     sixth
374 | |
375 * | commit master~3
376 | | Author: A U Thor <author@example.com>
377 | |
378 | |     fifth
379 | |
380 * | commit master~4
381 |/  Author: A U Thor <author@example.com>
382 |
383 |       fourth
384 |
385 * commit tags/side-1~1
386 | Author: A U Thor <author@example.com>
387 |
388 |     third
389 |
390 * commit tags/side-1~2
391 | Author: A U Thor <author@example.com>
392 |
393 |     second
394 |
395 * commit tags/side-1~3
396   Author: A U Thor <author@example.com>
397
398       initial
399 EOF
400
401 test_expect_success 'log --graph with full output' '
402         git log --graph --date-order --pretty=short |
403                 git name-rev --name-only --stdin |
404                 sed "s/Merge:.*/Merge: A B/;s/ *\$//" >actual &&
405         test_cmp expect actual
406 '
407
408 test_expect_success 'set up more tangled history' '
409         git checkout -b tangle HEAD~6 &&
410         test_commit tangle-a tangle-a a &&
411         git merge master~3 &&
412         git merge side~1 &&
413         git checkout master &&
414         git merge tangle &&
415         git checkout -b reach &&
416         test_commit reach &&
417         git checkout master &&
418         git checkout -b octopus-a &&
419         test_commit octopus-a &&
420         git checkout master &&
421         git checkout -b octopus-b &&
422         test_commit octopus-b &&
423         git checkout master &&
424         test_commit seventh &&
425         git merge octopus-a octopus-b &&
426         git merge reach
427 '
428
429 cat > expect <<\EOF
430 *   Merge tag 'reach'
431 |\
432 | \
433 |  \
434 *-. \   Merge tags 'octopus-a' and 'octopus-b'
435 |\ \ \
436 * | | | seventh
437 | | * | octopus-b
438 | |/ /
439 |/| |
440 | * | octopus-a
441 |/ /
442 | * reach
443 |/
444 *   Merge branch 'tangle'
445 |\
446 | *   Merge branch 'side' (early part) into tangle
447 | |\
448 | * \   Merge branch 'master' (early part) into tangle
449 | |\ \
450 | * | | tangle-a
451 * | | |   Merge branch 'side'
452 |\ \ \ \
453 | * | | | side-2
454 | | |_|/
455 | |/| |
456 | * | | side-1
457 * | | | Second
458 * | | | sixth
459 | |_|/
460 |/| |
461 * | | fifth
462 * | | fourth
463 |/ /
464 * | third
465 |/
466 * second
467 * initial
468 EOF
469
470 test_expect_success 'log --graph with merge' '
471         git log --graph --date-order --pretty=tformat:%s |
472                 sed "s/ *\$//" >actual &&
473         test_cmp expect actual
474 '
475
476 test_expect_success 'log.decorate configuration' '
477         git log --oneline >expect.none &&
478         git log --oneline --decorate >expect.short &&
479         git log --oneline --decorate=full >expect.full &&
480
481         echo "[log] decorate" >>.git/config &&
482         git log --oneline >actual &&
483         test_cmp expect.short actual &&
484
485         test_config log.decorate true &&
486         git log --oneline >actual &&
487         test_cmp expect.short actual &&
488         git log --oneline --decorate=full >actual &&
489         test_cmp expect.full actual &&
490         git log --oneline --decorate=no >actual &&
491         test_cmp expect.none actual &&
492
493         test_config log.decorate no &&
494         git log --oneline >actual &&
495         test_cmp expect.none actual &&
496         git log --oneline --decorate >actual &&
497         test_cmp expect.short actual &&
498         git log --oneline --decorate=full >actual &&
499         test_cmp expect.full actual &&
500
501         test_config log.decorate 1 &&
502         git log --oneline >actual &&
503         test_cmp expect.short actual &&
504         git log --oneline --decorate=full >actual &&
505         test_cmp expect.full actual &&
506         git log --oneline --decorate=no >actual &&
507         test_cmp expect.none actual &&
508
509         test_config log.decorate short &&
510         git log --oneline >actual &&
511         test_cmp expect.short actual &&
512         git log --oneline --no-decorate >actual &&
513         test_cmp expect.none actual &&
514         git log --oneline --decorate=full >actual &&
515         test_cmp expect.full actual &&
516
517         test_config log.decorate full &&
518         git log --oneline >actual &&
519         test_cmp expect.full actual &&
520         git log --oneline --no-decorate >actual &&
521         test_cmp expect.none actual &&
522         git log --oneline --decorate >actual &&
523         test_cmp expect.short actual &&
524
525         test_unconfig log.decorate &&
526         git log --pretty=raw >expect.raw &&
527         test_config log.decorate full &&
528         git log --pretty=raw >actual &&
529         test_cmp expect.raw actual
530
531 '
532
533 test_expect_success 'reflog is expected format' '
534         git log -g --abbrev-commit --pretty=oneline >expect &&
535         git reflog >actual &&
536         test_cmp expect actual
537 '
538
539 test_expect_success 'whatchanged is expected format' '
540         git log --no-merges --raw >expect &&
541         git whatchanged >actual &&
542         test_cmp expect actual
543 '
544
545 test_expect_success 'log.abbrevCommit configuration' '
546         git log --abbrev-commit >expect.log.abbrev &&
547         git log --no-abbrev-commit >expect.log.full &&
548         git log --pretty=raw >expect.log.raw &&
549         git reflog --abbrev-commit >expect.reflog.abbrev &&
550         git reflog --no-abbrev-commit >expect.reflog.full &&
551         git whatchanged --abbrev-commit >expect.whatchanged.abbrev &&
552         git whatchanged --no-abbrev-commit >expect.whatchanged.full &&
553
554         test_config log.abbrevCommit true &&
555
556         git log >actual &&
557         test_cmp expect.log.abbrev actual &&
558         git log --no-abbrev-commit >actual &&
559         test_cmp expect.log.full actual &&
560
561         git log --pretty=raw >actual &&
562         test_cmp expect.log.raw actual &&
563
564         git reflog >actual &&
565         test_cmp expect.reflog.abbrev actual &&
566         git reflog --no-abbrev-commit >actual &&
567         test_cmp expect.reflog.full actual &&
568
569         git whatchanged >actual &&
570         test_cmp expect.whatchanged.abbrev actual &&
571         git whatchanged --no-abbrev-commit >actual &&
572         test_cmp expect.whatchanged.full actual
573 '
574
575 test_expect_success 'show added path under "--follow -M"' '
576         # This tests for a regression introduced in v1.7.2-rc0~103^2~2
577         test_create_repo regression &&
578         (
579                 cd regression &&
580                 test_commit needs-another-commit &&
581                 test_commit foo.bar &&
582                 git log -M --follow -p foo.bar.t &&
583                 git log -M --follow --stat foo.bar.t &&
584                 git log -M --follow --name-only foo.bar.t
585         )
586 '
587
588 test_expect_success 'git log -c --follow' '
589         test_create_repo follow-c &&
590         (
591                 cd follow-c &&
592                 test_commit initial file original &&
593                 git rm file &&
594                 test_commit rename file2 original &&
595                 git reset --hard initial &&
596                 test_commit modify file foo &&
597                 git merge -m merge rename &&
598                 git log -c --follow file2
599         )
600 '
601
602 cat >expect <<\EOF
603 *   commit COMMIT_OBJECT_NAME
604 |\  Merge: MERGE_PARENTS
605 | | Author: A U Thor <author@example.com>
606 | |
607 | |     Merge HEADS DESCRIPTION
608 | |
609 | * commit COMMIT_OBJECT_NAME
610 | | Author: A U Thor <author@example.com>
611 | |
612 | |     reach
613 | | ---
614 | |  reach.t | 1 +
615 | |  1 file changed, 1 insertion(+)
616 | |
617 | | diff --git a/reach.t b/reach.t
618 | | new file mode 100644
619 | | index 0000000..10c9591
620 | | --- /dev/null
621 | | +++ b/reach.t
622 | | @@ -0,0 +1 @@
623 | | +reach
624 | |
625 |  \
626 *-. \   commit COMMIT_OBJECT_NAME
627 |\ \ \  Merge: MERGE_PARENTS
628 | | | | Author: A U Thor <author@example.com>
629 | | | |
630 | | | |     Merge HEADS DESCRIPTION
631 | | | |
632 | | * | commit COMMIT_OBJECT_NAME
633 | | |/  Author: A U Thor <author@example.com>
634 | | |
635 | | |       octopus-b
636 | | |   ---
637 | | |    octopus-b.t | 1 +
638 | | |    1 file changed, 1 insertion(+)
639 | | |
640 | | |   diff --git a/octopus-b.t b/octopus-b.t
641 | | |   new file mode 100644
642 | | |   index 0000000..d5fcad0
643 | | |   --- /dev/null
644 | | |   +++ b/octopus-b.t
645 | | |   @@ -0,0 +1 @@
646 | | |   +octopus-b
647 | | |
648 | * | commit COMMIT_OBJECT_NAME
649 | |/  Author: A U Thor <author@example.com>
650 | |
651 | |       octopus-a
652 | |   ---
653 | |    octopus-a.t | 1 +
654 | |    1 file changed, 1 insertion(+)
655 | |
656 | |   diff --git a/octopus-a.t b/octopus-a.t
657 | |   new file mode 100644
658 | |   index 0000000..11ee015
659 | |   --- /dev/null
660 | |   +++ b/octopus-a.t
661 | |   @@ -0,0 +1 @@
662 | |   +octopus-a
663 | |
664 * | commit COMMIT_OBJECT_NAME
665 |/  Author: A U Thor <author@example.com>
666 |
667 |       seventh
668 |   ---
669 |    seventh.t | 1 +
670 |    1 file changed, 1 insertion(+)
671 |
672 |   diff --git a/seventh.t b/seventh.t
673 |   new file mode 100644
674 |   index 0000000..9744ffc
675 |   --- /dev/null
676 |   +++ b/seventh.t
677 |   @@ -0,0 +1 @@
678 |   +seventh
679 |
680 *   commit COMMIT_OBJECT_NAME
681 |\  Merge: MERGE_PARENTS
682 | | Author: A U Thor <author@example.com>
683 | |
684 | |     Merge branch 'tangle'
685 | |
686 | *   commit COMMIT_OBJECT_NAME
687 | |\  Merge: MERGE_PARENTS
688 | | | Author: A U Thor <author@example.com>
689 | | |
690 | | |     Merge branch 'side' (early part) into tangle
691 | | |
692 | * |   commit COMMIT_OBJECT_NAME
693 | |\ \  Merge: MERGE_PARENTS
694 | | | | Author: A U Thor <author@example.com>
695 | | | |
696 | | | |     Merge branch 'master' (early part) into tangle
697 | | | |
698 | * | | commit COMMIT_OBJECT_NAME
699 | | | | Author: A U Thor <author@example.com>
700 | | | |
701 | | | |     tangle-a
702 | | | | ---
703 | | | |  tangle-a | 1 +
704 | | | |  1 file changed, 1 insertion(+)
705 | | | |
706 | | | | diff --git a/tangle-a b/tangle-a
707 | | | | new file mode 100644
708 | | | | index 0000000..7898192
709 | | | | --- /dev/null
710 | | | | +++ b/tangle-a
711 | | | | @@ -0,0 +1 @@
712 | | | | +a
713 | | | |
714 * | | |   commit COMMIT_OBJECT_NAME
715 |\ \ \ \  Merge: MERGE_PARENTS
716 | | | | | Author: A U Thor <author@example.com>
717 | | | | |
718 | | | | |     Merge branch 'side'
719 | | | | |
720 | * | | | commit COMMIT_OBJECT_NAME
721 | | |_|/  Author: A U Thor <author@example.com>
722 | |/| |
723 | | | |       side-2
724 | | | |   ---
725 | | | |    2 | 1 +
726 | | | |    1 file changed, 1 insertion(+)
727 | | | |
728 | | | |   diff --git a/2 b/2
729 | | | |   new file mode 100644
730 | | | |   index 0000000..0cfbf08
731 | | | |   --- /dev/null
732 | | | |   +++ b/2
733 | | | |   @@ -0,0 +1 @@
734 | | | |   +2
735 | | | |
736 | * | | commit COMMIT_OBJECT_NAME
737 | | | | Author: A U Thor <author@example.com>
738 | | | |
739 | | | |     side-1
740 | | | | ---
741 | | | |  1 | 1 +
742 | | | |  1 file changed, 1 insertion(+)
743 | | | |
744 | | | | diff --git a/1 b/1
745 | | | | new file mode 100644
746 | | | | index 0000000..d00491f
747 | | | | --- /dev/null
748 | | | | +++ b/1
749 | | | | @@ -0,0 +1 @@
750 | | | | +1
751 | | | |
752 * | | | commit COMMIT_OBJECT_NAME
753 | | | | Author: A U Thor <author@example.com>
754 | | | |
755 | | | |     Second
756 | | | | ---
757 | | | |  one | 1 +
758 | | | |  1 file changed, 1 insertion(+)
759 | | | |
760 | | | | diff --git a/one b/one
761 | | | | new file mode 100644
762 | | | | index 0000000..9a33383
763 | | | | --- /dev/null
764 | | | | +++ b/one
765 | | | | @@ -0,0 +1 @@
766 | | | | +case
767 | | | |
768 * | | | commit COMMIT_OBJECT_NAME
769 | |_|/  Author: A U Thor <author@example.com>
770 |/| |
771 | | |       sixth
772 | | |   ---
773 | | |    a/two | 1 -
774 | | |    1 file changed, 1 deletion(-)
775 | | |
776 | | |   diff --git a/a/two b/a/two
777 | | |   deleted file mode 100644
778 | | |   index 9245af5..0000000
779 | | |   --- a/a/two
780 | | |   +++ /dev/null
781 | | |   @@ -1 +0,0 @@
782 | | |   -ni
783 | | |
784 * | | commit COMMIT_OBJECT_NAME
785 | | | Author: A U Thor <author@example.com>
786 | | |
787 | | |     fifth
788 | | | ---
789 | | |  a/two | 1 +
790 | | |  1 file changed, 1 insertion(+)
791 | | |
792 | | | diff --git a/a/two b/a/two
793 | | | new file mode 100644
794 | | | index 0000000..9245af5
795 | | | --- /dev/null
796 | | | +++ b/a/two
797 | | | @@ -0,0 +1 @@
798 | | | +ni
799 | | |
800 * | | commit COMMIT_OBJECT_NAME
801 |/ /  Author: A U Thor <author@example.com>
802 | |
803 | |       fourth
804 | |   ---
805 | |    ein | 1 +
806 | |    1 file changed, 1 insertion(+)
807 | |
808 | |   diff --git a/ein b/ein
809 | |   new file mode 100644
810 | |   index 0000000..9d7e69f
811 | |   --- /dev/null
812 | |   +++ b/ein
813 | |   @@ -0,0 +1 @@
814 | |   +ichi
815 | |
816 * | commit COMMIT_OBJECT_NAME
817 |/  Author: A U Thor <author@example.com>
818 |
819 |       third
820 |   ---
821 |    ichi | 1 +
822 |    one  | 1 -
823 |    2 files changed, 1 insertion(+), 1 deletion(-)
824 |
825 |   diff --git a/ichi b/ichi
826 |   new file mode 100644
827 |   index 0000000..9d7e69f
828 |   --- /dev/null
829 |   +++ b/ichi
830 |   @@ -0,0 +1 @@
831 |   +ichi
832 |   diff --git a/one b/one
833 |   deleted file mode 100644
834 |   index 9d7e69f..0000000
835 |   --- a/one
836 |   +++ /dev/null
837 |   @@ -1 +0,0 @@
838 |   -ichi
839 |
840 * commit COMMIT_OBJECT_NAME
841 | Author: A U Thor <author@example.com>
842 |
843 |     second
844 | ---
845 |  one | 2 +-
846 |  1 file changed, 1 insertion(+), 1 deletion(-)
847 |
848 | diff --git a/one b/one
849 | index 5626abf..9d7e69f 100644
850 | --- a/one
851 | +++ b/one
852 | @@ -1 +1 @@
853 | -one
854 | +ichi
855 |
856 * commit COMMIT_OBJECT_NAME
857   Author: A U Thor <author@example.com>
858
859       initial
860   ---
861    one | 1 +
862    1 file changed, 1 insertion(+)
863
864   diff --git a/one b/one
865   new file mode 100644
866   index 0000000..5626abf
867   --- /dev/null
868   +++ b/one
869   @@ -0,0 +1 @@
870   +one
871 EOF
872
873 sanitize_output () {
874         sed -e 's/ *$//' \
875             -e 's/commit [0-9a-f]*$/commit COMMIT_OBJECT_NAME/' \
876             -e 's/Merge: [ 0-9a-f]*$/Merge: MERGE_PARENTS/' \
877             -e 's/Merge tag.*/Merge HEADS DESCRIPTION/' \
878             -e 's/Merge commit.*/Merge HEADS DESCRIPTION/' \
879             -e 's/, 0 deletions(-)//' \
880             -e 's/, 0 insertions(+)//' \
881             -e 's/ 1 files changed, / 1 file changed, /' \
882             -e 's/, 1 deletions(-)/, 1 deletion(-)/' \
883             -e 's/, 1 insertions(+)/, 1 insertion(+)/'
884 }
885
886 test_expect_success 'log --graph with diff and stats' '
887         git log --no-renames --graph --pretty=short --stat -p >actual &&
888         sanitize_output >actual.sanitized <actual &&
889         test_i18ncmp expect actual.sanitized
890 '
891
892 test_expect_success 'dotdot is a parent directory' '
893         mkdir -p a/b &&
894         ( echo sixth && echo fifth ) >expect &&
895         ( cd a/b && git log --format=%s .. ) >actual &&
896         test_cmp expect actual
897 '
898
899 test_expect_success GPG 'setup signed branch' '
900         test_when_finished "git reset --hard && git checkout master" &&
901         git checkout -b signed master &&
902         echo foo >foo &&
903         git add foo &&
904         git commit -S -m signed_commit
905 '
906
907 test_expect_success GPG 'log --graph --show-signature' '
908         git log --graph --show-signature -n1 signed >actual &&
909         grep "^| gpg: Signature made" actual &&
910         grep "^| gpg: Good signature" actual
911 '
912
913 test_expect_success GPG 'log --graph --show-signature for merged tag' '
914         test_when_finished "git reset --hard && git checkout master" &&
915         git checkout -b plain master &&
916         echo aaa >bar &&
917         git add bar &&
918         git commit -m bar_commit &&
919         git checkout -b tagged master &&
920         echo bbb >baz &&
921         git add baz &&
922         git commit -m baz_commit &&
923         git tag -s -m signed_tag_msg signed_tag &&
924         git checkout plain &&
925         git merge --no-ff -m msg signed_tag &&
926         git log --graph --show-signature -n1 plain >actual &&
927         grep "^|\\\  merged tag" actual &&
928         grep "^| | gpg: Signature made" actual &&
929         grep "^| | gpg: Good signature" actual
930 '
931
932 test_expect_success GPG '--no-show-signature overrides --show-signature' '
933         git log -1 --show-signature --no-show-signature signed >actual &&
934         ! grep "^gpg:" actual
935 '
936
937 test_expect_success GPG 'log.showsignature=true behaves like --show-signature' '
938         test_config log.showsignature true &&
939         git log -1 signed >actual &&
940         grep "gpg: Signature made" actual &&
941         grep "gpg: Good signature" actual
942 '
943
944 test_expect_success GPG '--no-show-signature overrides log.showsignature=true' '
945         test_config log.showsignature true &&
946         git log -1 --no-show-signature signed >actual &&
947         ! grep "^gpg:" actual
948 '
949
950 test_expect_success GPG '--show-signature overrides log.showsignature=false' '
951         test_config log.showsignature false &&
952         git log -1 --show-signature signed >actual &&
953         grep "gpg: Signature made" actual &&
954         grep "gpg: Good signature" actual
955 '
956
957 test_expect_success 'log --graph --no-walk is forbidden' '
958         test_must_fail git log --graph --no-walk
959 '
960
961 test_expect_success 'log diagnoses bogus HEAD' '
962         git init empty &&
963         test_must_fail git -C empty log 2>stderr &&
964         test_i18ngrep does.not.have.any.commits stderr &&
965         echo 1234abcd >empty/.git/refs/heads/master &&
966         test_must_fail git -C empty log 2>stderr &&
967         test_i18ngrep broken stderr &&
968         echo "ref: refs/heads/invalid.lock" >empty/.git/HEAD &&
969         test_must_fail git -C empty log 2>stderr &&
970         test_i18ngrep broken stderr &&
971         test_must_fail git -C empty log --default totally-bogus 2>stderr &&
972         test_i18ngrep broken stderr
973 '
974
975 test_expect_success 'set up --source tests' '
976         git checkout --orphan source-a &&
977         test_commit one &&
978         test_commit two &&
979         git checkout -b source-b HEAD^ &&
980         test_commit three
981 '
982
983 test_expect_success 'log --source paints branch names' '
984         cat >expect <<-\EOF &&
985         09e12a9 source-b three
986         8e393e1 source-a two
987         1ac6c77 source-b one
988         EOF
989         git log --oneline --source source-a source-b >actual &&
990         test_cmp expect actual
991 '
992
993 test_expect_success 'log --source paints tag names' '
994         git tag -m tagged source-tag &&
995         cat >expect <<-\EOF &&
996         09e12a9 source-tag three
997         8e393e1 source-a two
998         1ac6c77 source-tag one
999         EOF
1000         git log --oneline --source source-tag source-a >actual &&
1001         test_cmp expect actual
1002 '
1003
1004 test_done