Merge branch 'master' of github.com:Softcatala/git-po
[git] / t / t4202-log.sh
1 #!/bin/sh
2
3 test_description='git log'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY/lib-gpg.sh"
10 . "$TEST_DIRECTORY/lib-terminal.sh"
11 . "$TEST_DIRECTORY/lib-log-graph.sh"
12
13 test_cmp_graph () {
14         lib_test_cmp_graph --format=%s "$@"
15 }
16
17 test_expect_success setup '
18
19         echo one >one &&
20         git add one &&
21         test_tick &&
22         git commit -m initial &&
23
24         echo ichi >one &&
25         git add one &&
26         test_tick &&
27         git commit -m second &&
28
29         git mv one ichi &&
30         test_tick &&
31         git commit -m third &&
32
33         cp ichi ein &&
34         git add ein &&
35         test_tick &&
36         git commit -m fourth &&
37
38         mkdir a &&
39         echo ni >a/two &&
40         git add a/two &&
41         test_tick &&
42         git commit -m fifth  &&
43
44         git rm a/two &&
45         test_tick &&
46         git commit -m sixth
47
48 '
49
50 printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial" > expect
51 test_expect_success 'pretty' '
52
53         git log --pretty="format:%s" > actual &&
54         test_cmp expect actual
55 '
56
57 printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial\n" > expect
58 test_expect_success 'pretty (tformat)' '
59
60         git log --pretty="tformat:%s" > actual &&
61         test_cmp expect actual
62 '
63
64 test_expect_success 'pretty (shortcut)' '
65
66         git log --pretty="%s" > actual &&
67         test_cmp expect actual
68 '
69
70 test_expect_success 'format' '
71
72         git log --format="%s" > actual &&
73         test_cmp expect actual
74 '
75
76 cat > expect << EOF
77  This is
78   the sixth
79   commit.
80  This is
81   the fifth
82   commit.
83 EOF
84
85 test_expect_success 'format %w(11,1,2)' '
86
87         git log -2 --format="%w(11,1,2)This is the %s commit." > actual &&
88         test_cmp expect actual
89 '
90
91 test_expect_success 'format %w(,1,2)' '
92
93         git log -2 --format="%w(,1,2)This is%nthe %s%ncommit." > actual &&
94         test_cmp expect actual
95 '
96
97 cat > expect << EOF
98 $(git rev-parse --short :/sixth  ) sixth
99 $(git rev-parse --short :/fifth  ) fifth
100 $(git rev-parse --short :/fourth ) fourth
101 $(git rev-parse --short :/third  ) third
102 $(git rev-parse --short :/second ) second
103 $(git rev-parse --short :/initial) initial
104 EOF
105 test_expect_success 'oneline' '
106
107         git log --oneline > actual &&
108         test_cmp expect actual
109 '
110
111 test_expect_success 'diff-filter=A' '
112
113         git log --no-renames --pretty="format:%s" --diff-filter=A HEAD > actual &&
114         git log --no-renames --pretty="format:%s" --diff-filter A HEAD > actual-separate &&
115         printf "fifth\nfourth\nthird\ninitial" > expect &&
116         test_cmp expect actual &&
117         test_cmp expect actual-separate
118
119 '
120
121 test_expect_success 'diff-filter=M' '
122
123         actual=$(git log --pretty="format:%s" --diff-filter=M HEAD) &&
124         expect=$(echo second) &&
125         verbose test "$actual" = "$expect"
126
127 '
128
129 test_expect_success 'diff-filter=D' '
130
131         actual=$(git log --no-renames --pretty="format:%s" --diff-filter=D HEAD) &&
132         expect=$(echo sixth ; echo third) &&
133         verbose test "$actual" = "$expect"
134
135 '
136
137 test_expect_success 'diff-filter=R' '
138
139         actual=$(git log -M --pretty="format:%s" --diff-filter=R HEAD) &&
140         expect=$(echo third) &&
141         verbose test "$actual" = "$expect"
142
143 '
144
145 test_expect_success 'diff-filter=C' '
146
147         actual=$(git log -C -C --pretty="format:%s" --diff-filter=C HEAD) &&
148         expect=$(echo fourth) &&
149         verbose test "$actual" = "$expect"
150
151 '
152
153 test_expect_success 'git log --follow' '
154
155         actual=$(git log --follow --pretty="format:%s" ichi) &&
156         expect=$(echo third ; echo second ; echo initial) &&
157         verbose test "$actual" = "$expect"
158 '
159
160 test_expect_success 'git config log.follow works like --follow' '
161         test_config log.follow true &&
162         actual=$(git log --pretty="format:%s" ichi) &&
163         expect=$(echo third ; echo second ; echo initial) &&
164         verbose test "$actual" = "$expect"
165 '
166
167 test_expect_success 'git config log.follow does not die with multiple paths' '
168         test_config log.follow true &&
169         git log --pretty="format:%s" ichi ein
170 '
171
172 test_expect_success 'git config log.follow does not die with no paths' '
173         test_config log.follow true &&
174         git log --
175 '
176
177 test_expect_success 'git config log.follow is overridden by --no-follow' '
178         test_config log.follow true &&
179         actual=$(git log --no-follow --pretty="format:%s" ichi) &&
180         expect="third" &&
181         verbose test "$actual" = "$expect"
182 '
183
184 # Note that these commits are intentionally listed out of order.
185 last_three="$(git rev-parse :/fourth :/sixth :/fifth)"
186 cat > expect << EOF
187 $(git rev-parse --short :/sixth ) sixth
188 $(git rev-parse --short :/fifth ) fifth
189 $(git rev-parse --short :/fourth) fourth
190 EOF
191 test_expect_success 'git log --no-walk <commits> sorts by commit time' '
192         git log --no-walk --oneline $last_three > actual &&
193         test_cmp expect actual
194 '
195
196 test_expect_success 'git log --no-walk=sorted <commits> sorts by commit time' '
197         git log --no-walk=sorted --oneline $last_three > actual &&
198         test_cmp expect actual
199 '
200
201 cat > expect << EOF
202 === $(git rev-parse --short :/sixth ) sixth
203 === $(git rev-parse --short :/fifth ) fifth
204 === $(git rev-parse --short :/fourth) fourth
205 EOF
206 test_expect_success 'git log --line-prefix="=== " --no-walk <commits> sorts by commit time' '
207         git log --line-prefix="=== " --no-walk --oneline $last_three > actual &&
208         test_cmp expect actual
209 '
210
211 cat > expect << EOF
212 $(git rev-parse --short :/fourth) fourth
213 $(git rev-parse --short :/sixth ) sixth
214 $(git rev-parse --short :/fifth ) fifth
215 EOF
216 test_expect_success 'git log --no-walk=unsorted <commits> leaves list of commits as given' '
217         git log --no-walk=unsorted --oneline $last_three > actual &&
218         test_cmp expect actual
219 '
220
221 test_expect_success 'git show <commits> leaves list of commits as given' '
222         git show --oneline -s $last_three > actual &&
223         test_cmp expect actual
224 '
225
226 test_expect_success 'setup case sensitivity tests' '
227         echo case >one &&
228         test_tick &&
229         git add one &&
230         git commit -a -m Second
231 '
232
233 test_expect_success 'log --grep' '
234         echo second >expect &&
235         git log -1 --pretty="tformat:%s" --grep=sec >actual &&
236         test_cmp expect actual
237 '
238
239 cat > expect << EOF
240 second
241 initial
242 EOF
243 test_expect_success 'log --invert-grep --grep' '
244         # Fixed
245         git -c grep.patternType=fixed log --pretty="tformat:%s" --invert-grep --grep=th --grep=Sec >actual &&
246         test_cmp expect actual &&
247
248         # POSIX basic
249         git -c grep.patternType=basic log --pretty="tformat:%s" --invert-grep --grep=t[h] --grep=S[e]c >actual &&
250         test_cmp expect actual &&
251
252         # POSIX extended
253         git -c grep.patternType=basic log --pretty="tformat:%s" --invert-grep --grep=t[h] --grep=S[e]c >actual &&
254         test_cmp expect actual &&
255
256         # PCRE
257         if test_have_prereq PCRE
258         then
259                 git -c grep.patternType=perl log --pretty="tformat:%s" --invert-grep --grep=t[h] --grep=S[e]c >actual &&
260                 test_cmp expect actual
261         fi
262 '
263
264 test_expect_success 'log --invert-grep --grep -i' '
265         echo initial >expect &&
266
267         # Fixed
268         git -c grep.patternType=fixed log --pretty="tformat:%s" --invert-grep -i --grep=th --grep=Sec >actual &&
269         test_cmp expect actual &&
270
271         # POSIX basic
272         git -c grep.patternType=basic log --pretty="tformat:%s" --invert-grep -i --grep=t[h] --grep=S[e]c >actual &&
273         test_cmp expect actual &&
274
275         # POSIX extended
276         git -c grep.patternType=extended log --pretty="tformat:%s" --invert-grep -i --grep=t[h] --grep=S[e]c >actual &&
277         test_cmp expect actual &&
278
279         # PCRE
280         if test_have_prereq PCRE
281         then
282                 git -c grep.patternType=perl log --pretty="tformat:%s" --invert-grep -i --grep=t[h] --grep=S[e]c >actual &&
283                 test_cmp expect actual
284         fi
285 '
286
287 test_expect_success 'log --grep option parsing' '
288         echo second >expect &&
289         git log -1 --pretty="tformat:%s" --grep sec >actual &&
290         test_cmp expect actual &&
291         test_must_fail git log -1 --pretty="tformat:%s" --grep
292 '
293
294 test_expect_success 'log -i --grep' '
295         echo Second >expect &&
296         git log -1 --pretty="tformat:%s" -i --grep=sec >actual &&
297         test_cmp expect actual
298 '
299
300 test_expect_success 'log --grep -i' '
301         echo Second >expect &&
302
303         # Fixed
304         git log -1 --pretty="tformat:%s" --grep=sec -i >actual &&
305         test_cmp expect actual &&
306
307         # POSIX basic
308         git -c grep.patternType=basic log -1 --pretty="tformat:%s" --grep=s[e]c -i >actual &&
309         test_cmp expect actual &&
310
311         # POSIX extended
312         git -c grep.patternType=extended log -1 --pretty="tformat:%s" --grep=s[e]c -i >actual &&
313         test_cmp expect actual &&
314
315         # PCRE
316         if test_have_prereq PCRE
317         then
318                 git -c grep.patternType=perl log -1 --pretty="tformat:%s" --grep=s[e]c -i >actual &&
319                 test_cmp expect actual
320         fi
321 '
322
323 test_expect_success 'log -F -E --grep=<ere> uses ere' '
324         echo second >expect &&
325         # basic would need \(s\) to do the same
326         git log -1 --pretty="tformat:%s" -F -E --grep="(s).c.nd" >actual &&
327         test_cmp expect actual
328 '
329
330 test_expect_success PCRE 'log -F -E --perl-regexp --grep=<pcre> uses PCRE' '
331         test_when_finished "rm -rf num_commits" &&
332         git init num_commits &&
333         (
334                 cd num_commits &&
335                 test_commit 1d &&
336                 test_commit 2e
337         ) &&
338
339         # In PCRE \d in [\d] is like saying "0-9", and matches the 2
340         # in 2e...
341         echo 2e >expect &&
342         git -C num_commits log -1 --pretty="tformat:%s" -F -E --perl-regexp --grep="[\d]" >actual &&
343         test_cmp expect actual &&
344
345         # ...in POSIX basic and extended it is the same as [d],
346         # i.e. "d", which matches 1d, but does not match 2e.
347         echo 1d >expect &&
348         git -C num_commits log -1 --pretty="tformat:%s" -F -E --grep="[\d]" >actual &&
349         test_cmp expect actual
350 '
351
352 test_expect_success 'log with grep.patternType configuration' '
353         git -c grep.patterntype=fixed \
354         log -1 --pretty=tformat:%s --grep=s.c.nd >actual &&
355         test_must_be_empty actual
356 '
357
358 test_expect_success 'log with grep.patternType configuration and command line' '
359         echo second >expect &&
360         git -c grep.patterntype=fixed \
361         log -1 --pretty=tformat:%s --basic-regexp --grep=s.c.nd >actual &&
362         test_cmp expect actual
363 '
364
365 test_expect_success !FAIL_PREREQS 'log with various grep.patternType configurations & command-lines' '
366         git init pattern-type &&
367         (
368                 cd pattern-type &&
369                 test_commit 1 file A &&
370
371                 # The tagname is overridden here because creating a
372                 # tag called "(1|2)" as test_commit would otherwise
373                 # implicitly do would fail on e.g. MINGW.
374                 test_commit "(1|2)" file B 2 &&
375
376                 echo "(1|2)" >expect.fixed &&
377                 cp expect.fixed expect.basic &&
378                 cp expect.fixed expect.extended &&
379                 cp expect.fixed expect.perl &&
380
381                 # A strcmp-like match with fixed.
382                 git -c grep.patternType=fixed log --pretty=tformat:%s \
383                         --grep="(1|2)" >actual.fixed &&
384
385                 # POSIX basic matches (, | and ) literally.
386                 git -c grep.patternType=basic log --pretty=tformat:%s \
387                         --grep="(.|.)" >actual.basic &&
388
389                 # POSIX extended needs to have | escaped to match it
390                 # literally, whereas under basic this is the same as
391                 # (|2), i.e. it would also match "1". This test checks
392                 # for extended by asserting that it is not matching
393                 # what basic would match.
394                 git -c grep.patternType=extended log --pretty=tformat:%s \
395                         --grep="\|2" >actual.extended &&
396                 if test_have_prereq PCRE
397                 then
398                         # Only PCRE would match [\d]\| with only
399                         # "(1|2)" due to [\d]. POSIX basic would match
400                         # both it and "1" since similarly to the
401                         # extended match above it is the same as
402                         # \([\d]\|\). POSIX extended would
403                         # match neither.
404                         git -c grep.patternType=perl log --pretty=tformat:%s \
405                                 --grep="[\d]\|" >actual.perl &&
406                         test_cmp expect.perl actual.perl
407                 fi &&
408                 test_cmp expect.fixed actual.fixed &&
409                 test_cmp expect.basic actual.basic &&
410                 test_cmp expect.extended actual.extended &&
411
412                 git log --pretty=tformat:%s -F \
413                         --grep="(1|2)" >actual.fixed.short-arg &&
414                 git log --pretty=tformat:%s -E \
415                         --grep="\|2" >actual.extended.short-arg &&
416                 if test_have_prereq PCRE
417                 then
418                         git log --pretty=tformat:%s -P \
419                                 --grep="[\d]\|" >actual.perl.short-arg
420                 else
421                         test_must_fail git log -P \
422                                 --grep="[\d]\|"
423                 fi &&
424                 test_cmp expect.fixed actual.fixed.short-arg &&
425                 test_cmp expect.extended actual.extended.short-arg &&
426                 if test_have_prereq PCRE
427                 then
428                         test_cmp expect.perl actual.perl.short-arg
429                 fi &&
430
431                 git log --pretty=tformat:%s --fixed-strings \
432                         --grep="(1|2)" >actual.fixed.long-arg &&
433                 git log --pretty=tformat:%s --basic-regexp \
434                         --grep="(.|.)" >actual.basic.long-arg &&
435                 git log --pretty=tformat:%s --extended-regexp \
436                         --grep="\|2" >actual.extended.long-arg &&
437                 if test_have_prereq PCRE
438                 then
439                         git log --pretty=tformat:%s --perl-regexp \
440                                 --grep="[\d]\|" >actual.perl.long-arg &&
441                         test_cmp expect.perl actual.perl.long-arg
442                 else
443                         test_must_fail git log --perl-regexp \
444                                 --grep="[\d]\|"
445                 fi &&
446                 test_cmp expect.fixed actual.fixed.long-arg &&
447                 test_cmp expect.basic actual.basic.long-arg &&
448                 test_cmp expect.extended actual.extended.long-arg
449         )
450 '
451
452 cat > expect <<EOF
453 * Second
454 * sixth
455 * fifth
456 * fourth
457 * third
458 * second
459 * initial
460 EOF
461
462 test_expect_success 'simple log --graph' '
463         test_cmp_graph
464 '
465
466 cat > expect <<EOF
467 123 * Second
468 123 * sixth
469 123 * fifth
470 123 * fourth
471 123 * third
472 123 * second
473 123 * initial
474 EOF
475
476 test_expect_success 'simple log --graph --line-prefix="123 "' '
477         test_cmp_graph --line-prefix="123 "
478 '
479
480 test_expect_success 'set up merge history' '
481         git checkout -b side HEAD~4 &&
482         test_commit side-1 1 1 &&
483         test_commit side-2 2 2 &&
484         git checkout main &&
485         git merge side
486 '
487
488 cat > expect <<\EOF
489 *   Merge branch 'side'
490 |\
491 | * side-2
492 | * side-1
493 * | Second
494 * | sixth
495 * | fifth
496 * | fourth
497 |/
498 * third
499 * second
500 * initial
501 EOF
502
503 test_expect_success 'log --graph with merge' '
504         test_cmp_graph --date-order
505 '
506
507 cat > expect <<\EOF
508 | | | *   Merge branch 'side'
509 | | | |\
510 | | | | * side-2
511 | | | | * side-1
512 | | | * | Second
513 | | | * | sixth
514 | | | * | fifth
515 | | | * | fourth
516 | | | |/
517 | | | * third
518 | | | * second
519 | | | * initial
520 EOF
521
522 test_expect_success 'log --graph --line-prefix="| | | " with merge' '
523         test_cmp_graph --line-prefix="| | | " --date-order
524 '
525
526 cat > expect.colors <<\EOF
527 *   Merge branch 'side'
528 <BLUE>|<RESET><CYAN>\<RESET>
529 <BLUE>|<RESET> * side-2
530 <BLUE>|<RESET> * side-1
531 * <CYAN>|<RESET> Second
532 * <CYAN>|<RESET> sixth
533 * <CYAN>|<RESET> fifth
534 * <CYAN>|<RESET> fourth
535 <CYAN>|<RESET><CYAN>/<RESET>
536 * third
537 * second
538 * initial
539 EOF
540
541 test_expect_success 'log --graph with merge with log.graphColors' '
542         test_config log.graphColors " blue,invalid-color, cyan, red  , " &&
543         lib_test_cmp_colored_graph --date-order --format=%s
544 '
545
546 test_expect_success 'log --raw --graph -m with merge' '
547         git log --raw --graph --oneline -m main | head -n 500 >actual &&
548         grep "initial" actual
549 '
550
551 test_expect_success 'diff-tree --graph' '
552         git diff-tree --graph main^ | head -n 500 >actual &&
553         grep "one" actual
554 '
555
556 cat > expect <<\EOF
557 *   commit main
558 |\  Merge: A B
559 | | Author: A U Thor <author@example.com>
560 | |
561 | |     Merge branch 'side'
562 | |
563 | * commit tags/side-2
564 | | Author: A U Thor <author@example.com>
565 | |
566 | |     side-2
567 | |
568 | * commit tags/side-1
569 | | Author: A U Thor <author@example.com>
570 | |
571 | |     side-1
572 | |
573 * | commit main~1
574 | | Author: A U Thor <author@example.com>
575 | |
576 | |     Second
577 | |
578 * | commit main~2
579 | | Author: A U Thor <author@example.com>
580 | |
581 | |     sixth
582 | |
583 * | commit main~3
584 | | Author: A U Thor <author@example.com>
585 | |
586 | |     fifth
587 | |
588 * | commit main~4
589 |/  Author: A U Thor <author@example.com>
590 |
591 |       fourth
592 |
593 * commit tags/side-1~1
594 | Author: A U Thor <author@example.com>
595 |
596 |     third
597 |
598 * commit tags/side-1~2
599 | Author: A U Thor <author@example.com>
600 |
601 |     second
602 |
603 * commit tags/side-1~3
604   Author: A U Thor <author@example.com>
605
606       initial
607 EOF
608
609 test_expect_success 'log --graph with full output' '
610         git log --graph --date-order --pretty=short |
611                 git name-rev --name-only --stdin |
612                 sed "s/Merge:.*/Merge: A B/;s/ *\$//" >actual &&
613         test_cmp expect actual
614 '
615
616 test_expect_success 'set up more tangled history' '
617         git checkout -b tangle HEAD~6 &&
618         test_commit tangle-a tangle-a a &&
619         git merge main~3 &&
620         git merge side~1 &&
621         git checkout main &&
622         git merge tangle &&
623         git checkout -b reach &&
624         test_commit reach &&
625         git checkout main &&
626         git checkout -b octopus-a &&
627         test_commit octopus-a &&
628         git checkout main &&
629         git checkout -b octopus-b &&
630         test_commit octopus-b &&
631         git checkout main &&
632         test_commit seventh &&
633         git merge octopus-a octopus-b &&
634         git merge reach
635 '
636
637 cat > expect <<\EOF
638 *   Merge tag 'reach'
639 |\
640 | \
641 |  \
642 *-. \   Merge tags 'octopus-a' and 'octopus-b'
643 |\ \ \
644 * | | | seventh
645 | | * | octopus-b
646 | |/ /
647 |/| |
648 | * | octopus-a
649 |/ /
650 | * reach
651 |/
652 *   Merge branch 'tangle'
653 |\
654 | *   Merge branch 'side' (early part) into tangle
655 | |\
656 | * \   Merge branch 'main' (early part) into tangle
657 | |\ \
658 | * | | tangle-a
659 * | | |   Merge branch 'side'
660 |\ \ \ \
661 | * | | | side-2
662 | | |_|/
663 | |/| |
664 | * | | side-1
665 * | | | Second
666 * | | | sixth
667 | |_|/
668 |/| |
669 * | | fifth
670 * | | fourth
671 |/ /
672 * / third
673 |/
674 * second
675 * initial
676 EOF
677
678 test_expect_success 'log --graph with merge' '
679         test_cmp_graph --date-order
680 '
681
682 test_expect_success 'log.decorate configuration' '
683         git log --oneline --no-decorate >expect.none &&
684         git log --oneline --decorate >expect.short &&
685         git log --oneline --decorate=full >expect.full &&
686
687         echo "[log] decorate" >>.git/config &&
688         git log --oneline >actual &&
689         test_cmp expect.short actual &&
690
691         test_config log.decorate true &&
692         git log --oneline >actual &&
693         test_cmp expect.short actual &&
694         git log --oneline --decorate=full >actual &&
695         test_cmp expect.full actual &&
696         git log --oneline --decorate=no >actual &&
697         test_cmp expect.none actual &&
698
699         test_config log.decorate no &&
700         git log --oneline >actual &&
701         test_cmp expect.none actual &&
702         git log --oneline --decorate >actual &&
703         test_cmp expect.short actual &&
704         git log --oneline --decorate=full >actual &&
705         test_cmp expect.full actual &&
706
707         test_config log.decorate 1 &&
708         git log --oneline >actual &&
709         test_cmp expect.short actual &&
710         git log --oneline --decorate=full >actual &&
711         test_cmp expect.full actual &&
712         git log --oneline --decorate=no >actual &&
713         test_cmp expect.none actual &&
714
715         test_config log.decorate short &&
716         git log --oneline >actual &&
717         test_cmp expect.short actual &&
718         git log --oneline --no-decorate >actual &&
719         test_cmp expect.none actual &&
720         git log --oneline --decorate=full >actual &&
721         test_cmp expect.full actual &&
722
723         test_config log.decorate full &&
724         git log --oneline >actual &&
725         test_cmp expect.full actual &&
726         git log --oneline --no-decorate >actual &&
727         test_cmp expect.none actual &&
728         git log --oneline --decorate >actual &&
729         test_cmp expect.short actual &&
730
731         test_unconfig log.decorate &&
732         git log --pretty=raw >expect.raw &&
733         test_config log.decorate full &&
734         git log --pretty=raw >actual &&
735         test_cmp expect.raw actual
736
737 '
738
739 test_expect_success 'decorate-refs with glob' '
740         cat >expect.decorate <<-\EOF &&
741         Merge-tag-reach
742         Merge-tags-octopus-a-and-octopus-b
743         seventh
744         octopus-b (octopus-b)
745         octopus-a (octopus-a)
746         reach
747         EOF
748         cat >expect.no-decorate <<-\EOF &&
749         Merge-tag-reach
750         Merge-tags-octopus-a-and-octopus-b
751         seventh
752         octopus-b
753         octopus-a
754         reach
755         EOF
756         git log -n6 --decorate=short --pretty="tformat:%f%d" \
757                 --decorate-refs="heads/octopus*" >actual &&
758         test_cmp expect.decorate actual &&
759         git log -n6 --decorate=short --pretty="tformat:%f%d" \
760                 --decorate-refs-exclude="heads/octopus*" \
761                 --decorate-refs="heads/octopus*" >actual &&
762         test_cmp expect.no-decorate actual &&
763         git -c log.excludeDecoration="heads/octopus*" log \
764                 -n6 --decorate=short --pretty="tformat:%f%d" \
765                 --decorate-refs="heads/octopus*" >actual &&
766         test_cmp expect.decorate actual
767 '
768
769 test_expect_success 'decorate-refs without globs' '
770         cat >expect.decorate <<-\EOF &&
771         Merge-tag-reach
772         Merge-tags-octopus-a-and-octopus-b
773         seventh
774         octopus-b
775         octopus-a
776         reach (tag: reach)
777         EOF
778         git log -n6 --decorate=short --pretty="tformat:%f%d" \
779                 --decorate-refs="tags/reach" >actual &&
780         test_cmp expect.decorate actual
781 '
782
783 test_expect_success 'multiple decorate-refs' '
784         cat >expect.decorate <<-\EOF &&
785         Merge-tag-reach
786         Merge-tags-octopus-a-and-octopus-b
787         seventh
788         octopus-b (octopus-b)
789         octopus-a (octopus-a)
790         reach (tag: reach)
791         EOF
792         git log -n6 --decorate=short --pretty="tformat:%f%d" \
793                 --decorate-refs="heads/octopus*" \
794                 --decorate-refs="tags/reach" >actual &&
795     test_cmp expect.decorate actual
796 '
797
798 test_expect_success 'decorate-refs-exclude with glob' '
799         cat >expect.decorate <<-\EOF &&
800         Merge-tag-reach (HEAD -> main)
801         Merge-tags-octopus-a-and-octopus-b
802         seventh (tag: seventh)
803         octopus-b (tag: octopus-b)
804         octopus-a (tag: octopus-a)
805         reach (tag: reach, reach)
806         EOF
807         git log -n6 --decorate=short --pretty="tformat:%f%d" \
808                 --decorate-refs-exclude="heads/octopus*" >actual &&
809         test_cmp expect.decorate actual &&
810         git -c log.excludeDecoration="heads/octopus*" log \
811                 -n6 --decorate=short --pretty="tformat:%f%d" >actual &&
812         test_cmp expect.decorate actual
813 '
814
815 test_expect_success 'decorate-refs-exclude without globs' '
816         cat >expect.decorate <<-\EOF &&
817         Merge-tag-reach (HEAD -> main)
818         Merge-tags-octopus-a-and-octopus-b
819         seventh (tag: seventh)
820         octopus-b (tag: octopus-b, octopus-b)
821         octopus-a (tag: octopus-a, octopus-a)
822         reach (reach)
823         EOF
824         git log -n6 --decorate=short --pretty="tformat:%f%d" \
825                 --decorate-refs-exclude="tags/reach" >actual &&
826         test_cmp expect.decorate actual &&
827         git -c log.excludeDecoration="tags/reach" log \
828                 -n6 --decorate=short --pretty="tformat:%f%d" >actual &&
829         test_cmp expect.decorate actual
830 '
831
832 test_expect_success 'multiple decorate-refs-exclude' '
833         cat >expect.decorate <<-\EOF &&
834         Merge-tag-reach (HEAD -> main)
835         Merge-tags-octopus-a-and-octopus-b
836         seventh (tag: seventh)
837         octopus-b (tag: octopus-b)
838         octopus-a (tag: octopus-a)
839         reach (reach)
840         EOF
841         git log -n6 --decorate=short --pretty="tformat:%f%d" \
842                 --decorate-refs-exclude="heads/octopus*" \
843                 --decorate-refs-exclude="tags/reach" >actual &&
844         test_cmp expect.decorate actual &&
845         git -c log.excludeDecoration="heads/octopus*" \
846                 -c log.excludeDecoration="tags/reach" log \
847                 -n6 --decorate=short --pretty="tformat:%f%d" >actual &&
848         test_cmp expect.decorate actual &&
849         git -c log.excludeDecoration="heads/octopus*" log \
850                 --decorate-refs-exclude="tags/reach" \
851                 -n6 --decorate=short --pretty="tformat:%f%d" >actual &&
852         test_cmp expect.decorate actual
853 '
854
855 test_expect_success 'decorate-refs and decorate-refs-exclude' '
856         cat >expect.no-decorate <<-\EOF &&
857         Merge-tag-reach (main)
858         Merge-tags-octopus-a-and-octopus-b
859         seventh
860         octopus-b
861         octopus-a
862         reach (reach)
863         EOF
864         git log -n6 --decorate=short --pretty="tformat:%f%d" \
865                 --decorate-refs="heads/*" \
866                 --decorate-refs-exclude="heads/oc*" >actual &&
867         test_cmp expect.no-decorate actual
868 '
869
870 test_expect_success 'deocrate-refs and log.excludeDecoration' '
871         cat >expect.decorate <<-\EOF &&
872         Merge-tag-reach (main)
873         Merge-tags-octopus-a-and-octopus-b
874         seventh
875         octopus-b (octopus-b)
876         octopus-a (octopus-a)
877         reach (reach)
878         EOF
879         git -c log.excludeDecoration="heads/oc*" log \
880                 --decorate-refs="heads/*" \
881                 -n6 --decorate=short --pretty="tformat:%f%d" >actual &&
882         test_cmp expect.decorate actual
883 '
884
885 test_expect_success 'decorate-refs-exclude and simplify-by-decoration' '
886         cat >expect.decorate <<-\EOF &&
887         Merge-tag-reach (HEAD -> main)
888         reach (tag: reach, reach)
889         seventh (tag: seventh)
890         Merge-branch-tangle
891         Merge-branch-side-early-part-into-tangle (tangle)
892         tangle-a (tag: tangle-a)
893         EOF
894         git log -n6 --decorate=short --pretty="tformat:%f%d" \
895                 --decorate-refs-exclude="*octopus*" \
896                 --simplify-by-decoration >actual &&
897         test_cmp expect.decorate actual &&
898         git -c log.excludeDecoration="*octopus*" log \
899                 -n6 --decorate=short --pretty="tformat:%f%d" \
900                 --simplify-by-decoration >actual &&
901         test_cmp expect.decorate actual
902 '
903
904 test_expect_success 'log.decorate config parsing' '
905         git log --oneline --decorate=full >expect.full &&
906         git log --oneline --decorate=short >expect.short &&
907
908         test_config log.decorate full &&
909         test_config log.mailmap true &&
910         git log --oneline >actual &&
911         test_cmp expect.full actual &&
912         git log --oneline --decorate=short >actual &&
913         test_cmp expect.short actual
914 '
915
916 test_expect_success TTY 'log output on a TTY' '
917         git log --color --oneline --decorate >expect.short &&
918
919         test_terminal git log --oneline >actual &&
920         test_cmp expect.short actual
921 '
922
923 test_expect_success 'reflog is expected format' '
924         git log -g --abbrev-commit --pretty=oneline >expect &&
925         git reflog >actual &&
926         test_cmp expect actual
927 '
928
929 test_expect_success 'whatchanged is expected format' '
930         git log --no-merges --raw >expect &&
931         git whatchanged >actual &&
932         test_cmp expect actual
933 '
934
935 test_expect_success 'log.abbrevCommit configuration' '
936         git log --abbrev-commit >expect.log.abbrev &&
937         git log --no-abbrev-commit >expect.log.full &&
938         git log --pretty=raw >expect.log.raw &&
939         git reflog --abbrev-commit >expect.reflog.abbrev &&
940         git reflog --no-abbrev-commit >expect.reflog.full &&
941         git whatchanged --abbrev-commit >expect.whatchanged.abbrev &&
942         git whatchanged --no-abbrev-commit >expect.whatchanged.full &&
943
944         test_config log.abbrevCommit true &&
945
946         git log >actual &&
947         test_cmp expect.log.abbrev actual &&
948         git log --no-abbrev-commit >actual &&
949         test_cmp expect.log.full actual &&
950
951         git log --pretty=raw >actual &&
952         test_cmp expect.log.raw actual &&
953
954         git reflog >actual &&
955         test_cmp expect.reflog.abbrev actual &&
956         git reflog --no-abbrev-commit >actual &&
957         test_cmp expect.reflog.full actual &&
958
959         git whatchanged >actual &&
960         test_cmp expect.whatchanged.abbrev actual &&
961         git whatchanged --no-abbrev-commit >actual &&
962         test_cmp expect.whatchanged.full actual
963 '
964
965 test_expect_success 'show added path under "--follow -M"' '
966         # This tests for a regression introduced in v1.7.2-rc0~103^2~2
967         test_create_repo regression &&
968         (
969                 cd regression &&
970                 test_commit needs-another-commit &&
971                 test_commit foo.bar &&
972                 git log -M --follow -p foo.bar.t &&
973                 git log -M --follow --stat foo.bar.t &&
974                 git log -M --follow --name-only foo.bar.t
975         )
976 '
977
978 test_expect_success 'git log -c --follow' '
979         test_create_repo follow-c &&
980         (
981                 cd follow-c &&
982                 test_commit initial file original &&
983                 git rm file &&
984                 test_commit rename file2 original &&
985                 git reset --hard initial &&
986                 test_commit modify file foo &&
987                 git merge -m merge rename &&
988                 git log -c --follow file2
989         )
990 '
991
992 cat >expect <<\EOF
993 *   commit COMMIT_OBJECT_NAME
994 |\  Merge: MERGE_PARENTS
995 | | Author: A U Thor <author@example.com>
996 | |
997 | |     Merge HEADS DESCRIPTION
998 | |
999 | * commit COMMIT_OBJECT_NAME
1000 | | Author: A U Thor <author@example.com>
1001 | |
1002 | |     reach
1003 | | ---
1004 | |  reach.t | 1 +
1005 | |  1 file changed, 1 insertion(+)
1006 | |
1007 | | diff --git a/reach.t b/reach.t
1008 | | new file mode 100644
1009 | | index BEFORE..AFTER
1010 | | --- /dev/null
1011 | | +++ b/reach.t
1012 | | @@ -0,0 +1 @@
1013 | | +reach
1014 | |
1015 |  \
1016 *-. \   commit COMMIT_OBJECT_NAME
1017 |\ \ \  Merge: MERGE_PARENTS
1018 | | | | Author: A U Thor <author@example.com>
1019 | | | |
1020 | | | |     Merge HEADS DESCRIPTION
1021 | | | |
1022 | | * | commit COMMIT_OBJECT_NAME
1023 | | |/  Author: A U Thor <author@example.com>
1024 | | |
1025 | | |       octopus-b
1026 | | |   ---
1027 | | |    octopus-b.t | 1 +
1028 | | |    1 file changed, 1 insertion(+)
1029 | | |
1030 | | |   diff --git a/octopus-b.t b/octopus-b.t
1031 | | |   new file mode 100644
1032 | | |   index BEFORE..AFTER
1033 | | |   --- /dev/null
1034 | | |   +++ b/octopus-b.t
1035 | | |   @@ -0,0 +1 @@
1036 | | |   +octopus-b
1037 | | |
1038 | * | commit COMMIT_OBJECT_NAME
1039 | |/  Author: A U Thor <author@example.com>
1040 | |
1041 | |       octopus-a
1042 | |   ---
1043 | |    octopus-a.t | 1 +
1044 | |    1 file changed, 1 insertion(+)
1045 | |
1046 | |   diff --git a/octopus-a.t b/octopus-a.t
1047 | |   new file mode 100644
1048 | |   index BEFORE..AFTER
1049 | |   --- /dev/null
1050 | |   +++ b/octopus-a.t
1051 | |   @@ -0,0 +1 @@
1052 | |   +octopus-a
1053 | |
1054 * | commit COMMIT_OBJECT_NAME
1055 |/  Author: A U Thor <author@example.com>
1056 |
1057 |       seventh
1058 |   ---
1059 |    seventh.t | 1 +
1060 |    1 file changed, 1 insertion(+)
1061 |
1062 |   diff --git a/seventh.t b/seventh.t
1063 |   new file mode 100644
1064 |   index BEFORE..AFTER
1065 |   --- /dev/null
1066 |   +++ b/seventh.t
1067 |   @@ -0,0 +1 @@
1068 |   +seventh
1069 |
1070 *   commit COMMIT_OBJECT_NAME
1071 |\  Merge: MERGE_PARENTS
1072 | | Author: A U Thor <author@example.com>
1073 | |
1074 | |     Merge branch 'tangle'
1075 | |
1076 | *   commit COMMIT_OBJECT_NAME
1077 | |\  Merge: MERGE_PARENTS
1078 | | | Author: A U Thor <author@example.com>
1079 | | |
1080 | | |     Merge branch 'side' (early part) into tangle
1081 | | |
1082 | * |   commit COMMIT_OBJECT_NAME
1083 | |\ \  Merge: MERGE_PARENTS
1084 | | | | Author: A U Thor <author@example.com>
1085 | | | |
1086 | | | |     Merge branch 'main' (early part) into tangle
1087 | | | |
1088 | * | | commit COMMIT_OBJECT_NAME
1089 | | | | Author: A U Thor <author@example.com>
1090 | | | |
1091 | | | |     tangle-a
1092 | | | | ---
1093 | | | |  tangle-a | 1 +
1094 | | | |  1 file changed, 1 insertion(+)
1095 | | | |
1096 | | | | diff --git a/tangle-a b/tangle-a
1097 | | | | new file mode 100644
1098 | | | | index BEFORE..AFTER
1099 | | | | --- /dev/null
1100 | | | | +++ b/tangle-a
1101 | | | | @@ -0,0 +1 @@
1102 | | | | +a
1103 | | | |
1104 * | | |   commit COMMIT_OBJECT_NAME
1105 |\ \ \ \  Merge: MERGE_PARENTS
1106 | | | | | Author: A U Thor <author@example.com>
1107 | | | | |
1108 | | | | |     Merge branch 'side'
1109 | | | | |
1110 | * | | | commit COMMIT_OBJECT_NAME
1111 | | |_|/  Author: A U Thor <author@example.com>
1112 | |/| |
1113 | | | |       side-2
1114 | | | |   ---
1115 | | | |    2 | 1 +
1116 | | | |    1 file changed, 1 insertion(+)
1117 | | | |
1118 | | | |   diff --git a/2 b/2
1119 | | | |   new file mode 100644
1120 | | | |   index BEFORE..AFTER
1121 | | | |   --- /dev/null
1122 | | | |   +++ b/2
1123 | | | |   @@ -0,0 +1 @@
1124 | | | |   +2
1125 | | | |
1126 | * | | commit COMMIT_OBJECT_NAME
1127 | | | | Author: A U Thor <author@example.com>
1128 | | | |
1129 | | | |     side-1
1130 | | | | ---
1131 | | | |  1 | 1 +
1132 | | | |  1 file changed, 1 insertion(+)
1133 | | | |
1134 | | | | diff --git a/1 b/1
1135 | | | | new file mode 100644
1136 | | | | index BEFORE..AFTER
1137 | | | | --- /dev/null
1138 | | | | +++ b/1
1139 | | | | @@ -0,0 +1 @@
1140 | | | | +1
1141 | | | |
1142 * | | | commit COMMIT_OBJECT_NAME
1143 | | | | Author: A U Thor <author@example.com>
1144 | | | |
1145 | | | |     Second
1146 | | | | ---
1147 | | | |  one | 1 +
1148 | | | |  1 file changed, 1 insertion(+)
1149 | | | |
1150 | | | | diff --git a/one b/one
1151 | | | | new file mode 100644
1152 | | | | index BEFORE..AFTER
1153 | | | | --- /dev/null
1154 | | | | +++ b/one
1155 | | | | @@ -0,0 +1 @@
1156 | | | | +case
1157 | | | |
1158 * | | | commit COMMIT_OBJECT_NAME
1159 | |_|/  Author: A U Thor <author@example.com>
1160 |/| |
1161 | | |       sixth
1162 | | |   ---
1163 | | |    a/two | 1 -
1164 | | |    1 file changed, 1 deletion(-)
1165 | | |
1166 | | |   diff --git a/a/two b/a/two
1167 | | |   deleted file mode 100644
1168 | | |   index BEFORE..AFTER
1169 | | |   --- a/a/two
1170 | | |   +++ /dev/null
1171 | | |   @@ -1 +0,0 @@
1172 | | |   -ni
1173 | | |
1174 * | | commit COMMIT_OBJECT_NAME
1175 | | | Author: A U Thor <author@example.com>
1176 | | |
1177 | | |     fifth
1178 | | | ---
1179 | | |  a/two | 1 +
1180 | | |  1 file changed, 1 insertion(+)
1181 | | |
1182 | | | diff --git a/a/two b/a/two
1183 | | | new file mode 100644
1184 | | | index BEFORE..AFTER
1185 | | | --- /dev/null
1186 | | | +++ b/a/two
1187 | | | @@ -0,0 +1 @@
1188 | | | +ni
1189 | | |
1190 * | | commit COMMIT_OBJECT_NAME
1191 |/ /  Author: A U Thor <author@example.com>
1192 | |
1193 | |       fourth
1194 | |   ---
1195 | |    ein | 1 +
1196 | |    1 file changed, 1 insertion(+)
1197 | |
1198 | |   diff --git a/ein b/ein
1199 | |   new file mode 100644
1200 | |   index BEFORE..AFTER
1201 | |   --- /dev/null
1202 | |   +++ b/ein
1203 | |   @@ -0,0 +1 @@
1204 | |   +ichi
1205 | |
1206 * | commit COMMIT_OBJECT_NAME
1207 |/  Author: A U Thor <author@example.com>
1208 |
1209 |       third
1210 |   ---
1211 |    ichi | 1 +
1212 |    one  | 1 -
1213 |    2 files changed, 1 insertion(+), 1 deletion(-)
1214 |
1215 |   diff --git a/ichi b/ichi
1216 |   new file mode 100644
1217 |   index BEFORE..AFTER
1218 |   --- /dev/null
1219 |   +++ b/ichi
1220 |   @@ -0,0 +1 @@
1221 |   +ichi
1222 |   diff --git a/one b/one
1223 |   deleted file mode 100644
1224 |   index BEFORE..AFTER
1225 |   --- a/one
1226 |   +++ /dev/null
1227 |   @@ -1 +0,0 @@
1228 |   -ichi
1229 |
1230 * commit COMMIT_OBJECT_NAME
1231 | Author: A U Thor <author@example.com>
1232 |
1233 |     second
1234 | ---
1235 |  one | 2 +-
1236 |  1 file changed, 1 insertion(+), 1 deletion(-)
1237 |
1238 | diff --git a/one b/one
1239 | index BEFORE..AFTER 100644
1240 | --- a/one
1241 | +++ b/one
1242 | @@ -1 +1 @@
1243 | -one
1244 | +ichi
1245 |
1246 * commit COMMIT_OBJECT_NAME
1247   Author: A U Thor <author@example.com>
1248
1249       initial
1250   ---
1251    one | 1 +
1252    1 file changed, 1 insertion(+)
1253
1254   diff --git a/one b/one
1255   new file mode 100644
1256   index BEFORE..AFTER
1257   --- /dev/null
1258   +++ b/one
1259   @@ -0,0 +1 @@
1260   +one
1261 EOF
1262
1263 test_expect_success 'log --graph with diff and stats' '
1264         lib_test_cmp_short_graph --no-renames --stat -p
1265 '
1266
1267 cat >expect <<\EOF
1268 *** *   commit COMMIT_OBJECT_NAME
1269 *** |\  Merge: MERGE_PARENTS
1270 *** | | Author: A U Thor <author@example.com>
1271 *** | |
1272 *** | |     Merge HEADS DESCRIPTION
1273 *** | |
1274 *** | * commit COMMIT_OBJECT_NAME
1275 *** | | Author: A U Thor <author@example.com>
1276 *** | |
1277 *** | |     reach
1278 *** | | ---
1279 *** | |  reach.t | 1 +
1280 *** | |  1 file changed, 1 insertion(+)
1281 *** | |
1282 *** | | diff --git a/reach.t b/reach.t
1283 *** | | new file mode 100644
1284 *** | | index BEFORE..AFTER
1285 *** | | --- /dev/null
1286 *** | | +++ b/reach.t
1287 *** | | @@ -0,0 +1 @@
1288 *** | | +reach
1289 *** | |
1290 *** |  \
1291 *** *-. \   commit COMMIT_OBJECT_NAME
1292 *** |\ \ \  Merge: MERGE_PARENTS
1293 *** | | | | Author: A U Thor <author@example.com>
1294 *** | | | |
1295 *** | | | |     Merge HEADS DESCRIPTION
1296 *** | | | |
1297 *** | | * | commit COMMIT_OBJECT_NAME
1298 *** | | |/  Author: A U Thor <author@example.com>
1299 *** | | |
1300 *** | | |       octopus-b
1301 *** | | |   ---
1302 *** | | |    octopus-b.t | 1 +
1303 *** | | |    1 file changed, 1 insertion(+)
1304 *** | | |
1305 *** | | |   diff --git a/octopus-b.t b/octopus-b.t
1306 *** | | |   new file mode 100644
1307 *** | | |   index BEFORE..AFTER
1308 *** | | |   --- /dev/null
1309 *** | | |   +++ b/octopus-b.t
1310 *** | | |   @@ -0,0 +1 @@
1311 *** | | |   +octopus-b
1312 *** | | |
1313 *** | * | commit COMMIT_OBJECT_NAME
1314 *** | |/  Author: A U Thor <author@example.com>
1315 *** | |
1316 *** | |       octopus-a
1317 *** | |   ---
1318 *** | |    octopus-a.t | 1 +
1319 *** | |    1 file changed, 1 insertion(+)
1320 *** | |
1321 *** | |   diff --git a/octopus-a.t b/octopus-a.t
1322 *** | |   new file mode 100644
1323 *** | |   index BEFORE..AFTER
1324 *** | |   --- /dev/null
1325 *** | |   +++ b/octopus-a.t
1326 *** | |   @@ -0,0 +1 @@
1327 *** | |   +octopus-a
1328 *** | |
1329 *** * | commit COMMIT_OBJECT_NAME
1330 *** |/  Author: A U Thor <author@example.com>
1331 *** |
1332 *** |       seventh
1333 *** |   ---
1334 *** |    seventh.t | 1 +
1335 *** |    1 file changed, 1 insertion(+)
1336 *** |
1337 *** |   diff --git a/seventh.t b/seventh.t
1338 *** |   new file mode 100644
1339 *** |   index BEFORE..AFTER
1340 *** |   --- /dev/null
1341 *** |   +++ b/seventh.t
1342 *** |   @@ -0,0 +1 @@
1343 *** |   +seventh
1344 *** |
1345 *** *   commit COMMIT_OBJECT_NAME
1346 *** |\  Merge: MERGE_PARENTS
1347 *** | | Author: A U Thor <author@example.com>
1348 *** | |
1349 *** | |     Merge branch 'tangle'
1350 *** | |
1351 *** | *   commit COMMIT_OBJECT_NAME
1352 *** | |\  Merge: MERGE_PARENTS
1353 *** | | | Author: A U Thor <author@example.com>
1354 *** | | |
1355 *** | | |     Merge branch 'side' (early part) into tangle
1356 *** | | |
1357 *** | * |   commit COMMIT_OBJECT_NAME
1358 *** | |\ \  Merge: MERGE_PARENTS
1359 *** | | | | Author: A U Thor <author@example.com>
1360 *** | | | |
1361 *** | | | |     Merge branch 'main' (early part) into tangle
1362 *** | | | |
1363 *** | * | | commit COMMIT_OBJECT_NAME
1364 *** | | | | Author: A U Thor <author@example.com>
1365 *** | | | |
1366 *** | | | |     tangle-a
1367 *** | | | | ---
1368 *** | | | |  tangle-a | 1 +
1369 *** | | | |  1 file changed, 1 insertion(+)
1370 *** | | | |
1371 *** | | | | diff --git a/tangle-a b/tangle-a
1372 *** | | | | new file mode 100644
1373 *** | | | | index BEFORE..AFTER
1374 *** | | | | --- /dev/null
1375 *** | | | | +++ b/tangle-a
1376 *** | | | | @@ -0,0 +1 @@
1377 *** | | | | +a
1378 *** | | | |
1379 *** * | | |   commit COMMIT_OBJECT_NAME
1380 *** |\ \ \ \  Merge: MERGE_PARENTS
1381 *** | | | | | Author: A U Thor <author@example.com>
1382 *** | | | | |
1383 *** | | | | |     Merge branch 'side'
1384 *** | | | | |
1385 *** | * | | | commit COMMIT_OBJECT_NAME
1386 *** | | |_|/  Author: A U Thor <author@example.com>
1387 *** | |/| |
1388 *** | | | |       side-2
1389 *** | | | |   ---
1390 *** | | | |    2 | 1 +
1391 *** | | | |    1 file changed, 1 insertion(+)
1392 *** | | | |
1393 *** | | | |   diff --git a/2 b/2
1394 *** | | | |   new file mode 100644
1395 *** | | | |   index BEFORE..AFTER
1396 *** | | | |   --- /dev/null
1397 *** | | | |   +++ b/2
1398 *** | | | |   @@ -0,0 +1 @@
1399 *** | | | |   +2
1400 *** | | | |
1401 *** | * | | commit COMMIT_OBJECT_NAME
1402 *** | | | | Author: A U Thor <author@example.com>
1403 *** | | | |
1404 *** | | | |     side-1
1405 *** | | | | ---
1406 *** | | | |  1 | 1 +
1407 *** | | | |  1 file changed, 1 insertion(+)
1408 *** | | | |
1409 *** | | | | diff --git a/1 b/1
1410 *** | | | | new file mode 100644
1411 *** | | | | index BEFORE..AFTER
1412 *** | | | | --- /dev/null
1413 *** | | | | +++ b/1
1414 *** | | | | @@ -0,0 +1 @@
1415 *** | | | | +1
1416 *** | | | |
1417 *** * | | | commit COMMIT_OBJECT_NAME
1418 *** | | | | Author: A U Thor <author@example.com>
1419 *** | | | |
1420 *** | | | |     Second
1421 *** | | | | ---
1422 *** | | | |  one | 1 +
1423 *** | | | |  1 file changed, 1 insertion(+)
1424 *** | | | |
1425 *** | | | | diff --git a/one b/one
1426 *** | | | | new file mode 100644
1427 *** | | | | index BEFORE..AFTER
1428 *** | | | | --- /dev/null
1429 *** | | | | +++ b/one
1430 *** | | | | @@ -0,0 +1 @@
1431 *** | | | | +case
1432 *** | | | |
1433 *** * | | | commit COMMIT_OBJECT_NAME
1434 *** | |_|/  Author: A U Thor <author@example.com>
1435 *** |/| |
1436 *** | | |       sixth
1437 *** | | |   ---
1438 *** | | |    a/two | 1 -
1439 *** | | |    1 file changed, 1 deletion(-)
1440 *** | | |
1441 *** | | |   diff --git a/a/two b/a/two
1442 *** | | |   deleted file mode 100644
1443 *** | | |   index BEFORE..AFTER
1444 *** | | |   --- a/a/two
1445 *** | | |   +++ /dev/null
1446 *** | | |   @@ -1 +0,0 @@
1447 *** | | |   -ni
1448 *** | | |
1449 *** * | | commit COMMIT_OBJECT_NAME
1450 *** | | | Author: A U Thor <author@example.com>
1451 *** | | |
1452 *** | | |     fifth
1453 *** | | | ---
1454 *** | | |  a/two | 1 +
1455 *** | | |  1 file changed, 1 insertion(+)
1456 *** | | |
1457 *** | | | diff --git a/a/two b/a/two
1458 *** | | | new file mode 100644
1459 *** | | | index BEFORE..AFTER
1460 *** | | | --- /dev/null
1461 *** | | | +++ b/a/two
1462 *** | | | @@ -0,0 +1 @@
1463 *** | | | +ni
1464 *** | | |
1465 *** * | | commit COMMIT_OBJECT_NAME
1466 *** |/ /  Author: A U Thor <author@example.com>
1467 *** | |
1468 *** | |       fourth
1469 *** | |   ---
1470 *** | |    ein | 1 +
1471 *** | |    1 file changed, 1 insertion(+)
1472 *** | |
1473 *** | |   diff --git a/ein b/ein
1474 *** | |   new file mode 100644
1475 *** | |   index BEFORE..AFTER
1476 *** | |   --- /dev/null
1477 *** | |   +++ b/ein
1478 *** | |   @@ -0,0 +1 @@
1479 *** | |   +ichi
1480 *** | |
1481 *** * | commit COMMIT_OBJECT_NAME
1482 *** |/  Author: A U Thor <author@example.com>
1483 *** |
1484 *** |       third
1485 *** |   ---
1486 *** |    ichi | 1 +
1487 *** |    one  | 1 -
1488 *** |    2 files changed, 1 insertion(+), 1 deletion(-)
1489 *** |
1490 *** |   diff --git a/ichi b/ichi
1491 *** |   new file mode 100644
1492 *** |   index BEFORE..AFTER
1493 *** |   --- /dev/null
1494 *** |   +++ b/ichi
1495 *** |   @@ -0,0 +1 @@
1496 *** |   +ichi
1497 *** |   diff --git a/one b/one
1498 *** |   deleted file mode 100644
1499 *** |   index BEFORE..AFTER
1500 *** |   --- a/one
1501 *** |   +++ /dev/null
1502 *** |   @@ -1 +0,0 @@
1503 *** |   -ichi
1504 *** |
1505 *** * commit COMMIT_OBJECT_NAME
1506 *** | Author: A U Thor <author@example.com>
1507 *** |
1508 *** |     second
1509 *** | ---
1510 *** |  one | 2 +-
1511 *** |  1 file changed, 1 insertion(+), 1 deletion(-)
1512 *** |
1513 *** | diff --git a/one b/one
1514 *** | index BEFORE..AFTER 100644
1515 *** | --- a/one
1516 *** | +++ b/one
1517 *** | @@ -1 +1 @@
1518 *** | -one
1519 *** | +ichi
1520 *** |
1521 *** * commit COMMIT_OBJECT_NAME
1522 ***   Author: A U Thor <author@example.com>
1523 ***
1524 ***       initial
1525 ***   ---
1526 ***    one | 1 +
1527 ***    1 file changed, 1 insertion(+)
1528 ***
1529 ***   diff --git a/one b/one
1530 ***   new file mode 100644
1531 ***   index BEFORE..AFTER
1532 ***   --- /dev/null
1533 ***   +++ b/one
1534 ***   @@ -0,0 +1 @@
1535 ***   +one
1536 EOF
1537
1538 test_expect_success 'log --line-prefix="*** " --graph with diff and stats' '
1539         lib_test_cmp_short_graph --line-prefix="*** " --no-renames --stat -p
1540 '
1541
1542 cat >expect <<-\EOF
1543 * reach
1544 |
1545 | A     reach.t
1546 * Merge branch 'tangle'
1547 *   Merge branch 'side'
1548 |\
1549 | * side-2
1550 |
1551 |   A   2
1552 * Second
1553 |
1554 | A     one
1555 * sixth
1556
1557   D     a/two
1558 EOF
1559
1560 test_expect_success 'log --graph with --name-status' '
1561         test_cmp_graph --name-status tangle..reach
1562 '
1563
1564 cat >expect <<-\EOF
1565 * reach
1566 |
1567 | reach.t
1568 * Merge branch 'tangle'
1569 *   Merge branch 'side'
1570 |\
1571 | * side-2
1572 |
1573 |   2
1574 * Second
1575 |
1576 | one
1577 * sixth
1578
1579   a/two
1580 EOF
1581
1582 test_expect_success 'log --graph with --name-only' '
1583         test_cmp_graph --name-only tangle..reach
1584 '
1585
1586 test_expect_success 'dotdot is a parent directory' '
1587         mkdir -p a/b &&
1588         ( echo sixth && echo fifth ) >expect &&
1589         ( cd a/b && git log --format=%s .. ) >actual &&
1590         test_cmp expect actual
1591 '
1592
1593 test_expect_success GPG 'setup signed branch' '
1594         test_when_finished "git reset --hard && git checkout main" &&
1595         git checkout -b signed main &&
1596         echo foo >foo &&
1597         git add foo &&
1598         git commit -S -m signed_commit
1599 '
1600
1601 test_expect_success GPG 'setup signed branch with subkey' '
1602         test_when_finished "git reset --hard && git checkout main" &&
1603         git checkout -b signed-subkey main &&
1604         echo foo >foo &&
1605         git add foo &&
1606         git commit -SB7227189 -m signed_commit
1607 '
1608
1609 test_expect_success GPGSM 'setup signed branch x509' '
1610         test_when_finished "git reset --hard && git checkout main" &&
1611         git checkout -b signed-x509 main &&
1612         echo foo >foo &&
1613         git add foo &&
1614         test_config gpg.format x509 &&
1615         test_config user.signingkey $GIT_COMMITTER_EMAIL &&
1616         git commit -S -m signed_commit
1617 '
1618
1619 test_expect_success GPGSM 'log x509 fingerprint' '
1620         echo "F8BF62E0693D0694816377099909C779FA23FD65 | " >expect &&
1621         git log -n1 --format="%GF | %GP" signed-x509 >actual &&
1622         test_cmp expect actual
1623 '
1624
1625 test_expect_success GPGSM 'log OpenPGP fingerprint' '
1626         echo "D4BE22311AD3131E5EDA29A461092E85B7227189" > expect &&
1627         git log -n1 --format="%GP" signed-subkey >actual &&
1628         test_cmp expect actual
1629 '
1630
1631 test_expect_success GPG 'log --graph --show-signature' '
1632         git log --graph --show-signature -n1 signed >actual &&
1633         grep "^| gpg: Signature made" actual &&
1634         grep "^| gpg: Good signature" actual
1635 '
1636
1637 test_expect_success GPGSM 'log --graph --show-signature x509' '
1638         git log --graph --show-signature -n1 signed-x509 >actual &&
1639         grep "^| gpgsm: Signature made" actual &&
1640         grep "^| gpgsm: Good signature" actual
1641 '
1642
1643 test_expect_success GPG 'log --graph --show-signature for merged tag' '
1644         test_when_finished "git reset --hard && git checkout main" &&
1645         git checkout -b plain main &&
1646         echo aaa >bar &&
1647         git add bar &&
1648         git commit -m bar_commit &&
1649         git checkout -b tagged main &&
1650         echo bbb >baz &&
1651         git add baz &&
1652         git commit -m baz_commit &&
1653         git tag -s -m signed_tag_msg signed_tag &&
1654         git checkout plain &&
1655         git merge --no-ff -m msg signed_tag &&
1656         git log --graph --show-signature -n1 plain >actual &&
1657         grep "^|\\\  merged tag" actual &&
1658         grep "^| | gpg: Signature made" actual &&
1659         grep "^| | gpg: Good signature" actual
1660 '
1661
1662 test_expect_success GPG 'log --graph --show-signature for merged tag in shallow clone' '
1663         test_when_finished "git reset --hard && git checkout main" &&
1664         git checkout -b plain-shallow main &&
1665         echo aaa >bar &&
1666         git add bar &&
1667         git commit -m bar_commit &&
1668         git checkout --detach main &&
1669         echo bbb >baz &&
1670         git add baz &&
1671         git commit -m baz_commit &&
1672         git tag -s -m signed_tag_msg signed_tag_shallow &&
1673         hash=$(git rev-parse HEAD) &&
1674         git checkout plain-shallow &&
1675         git merge --no-ff -m msg signed_tag_shallow &&
1676         git clone --depth 1 --no-local . shallow &&
1677         test_when_finished "rm -rf shallow" &&
1678         git -C shallow log --graph --show-signature -n1 plain-shallow >actual &&
1679         grep "tag signed_tag_shallow names a non-parent $hash" actual
1680 '
1681
1682 test_expect_success GPG 'log --graph --show-signature for merged tag with missing key' '
1683         test_when_finished "git reset --hard && git checkout main" &&
1684         git checkout -b plain-nokey main &&
1685         echo aaa >bar &&
1686         git add bar &&
1687         git commit -m bar_commit &&
1688         git checkout -b tagged-nokey main &&
1689         echo bbb >baz &&
1690         git add baz &&
1691         git commit -m baz_commit &&
1692         git tag -s -m signed_tag_msg signed_tag_nokey &&
1693         git checkout plain-nokey &&
1694         git merge --no-ff -m msg signed_tag_nokey &&
1695         GNUPGHOME=. git log --graph --show-signature -n1 plain-nokey >actual &&
1696         grep "^|\\\  merged tag" actual &&
1697         grep "^| | gpg: Signature made" actual &&
1698         grep -E "^| | gpg: Can'"'"'t check signature: (public key not found|No public key)" actual
1699 '
1700
1701 test_expect_success GPG 'log --graph --show-signature for merged tag with bad signature' '
1702         test_when_finished "git reset --hard && git checkout main" &&
1703         git checkout -b plain-bad main &&
1704         echo aaa >bar &&
1705         git add bar &&
1706         git commit -m bar_commit &&
1707         git checkout -b tagged-bad main &&
1708         echo bbb >baz &&
1709         git add baz &&
1710         git commit -m baz_commit &&
1711         git tag -s -m signed_tag_msg signed_tag_bad &&
1712         git cat-file tag signed_tag_bad >raw &&
1713         sed -e "s/signed_tag_msg/forged/" raw >forged &&
1714         git hash-object -w -t tag forged >forged.tag &&
1715         git checkout plain-bad &&
1716         git merge --no-ff -m msg "$(cat forged.tag)" &&
1717         git log --graph --show-signature -n1 plain-bad >actual &&
1718         grep "^|\\\  merged tag" actual &&
1719         grep "^| | gpg: Signature made" actual &&
1720         grep "^| | gpg: BAD signature from" actual
1721 '
1722
1723 test_expect_success GPG 'log --show-signature for merged tag with GPG failure' '
1724         test_when_finished "git reset --hard && git checkout main" &&
1725         git checkout -b plain-fail main &&
1726         echo aaa >bar &&
1727         git add bar &&
1728         git commit -m bar_commit &&
1729         git checkout -b tagged-fail main &&
1730         echo bbb >baz &&
1731         git add baz &&
1732         git commit -m baz_commit &&
1733         git tag -s -m signed_tag_msg signed_tag_fail &&
1734         git checkout plain-fail &&
1735         git merge --no-ff -m msg signed_tag_fail &&
1736         TMPDIR="$(pwd)/bogus" git log --show-signature -n1 plain-fail >actual &&
1737         grep "^merged tag" actual &&
1738         grep "^No signature" actual &&
1739         ! grep "^gpg: Signature made" actual
1740 '
1741
1742 test_expect_success GPGSM 'log --graph --show-signature for merged tag x509' '
1743         test_when_finished "git reset --hard && git checkout main" &&
1744         test_config gpg.format x509 &&
1745         test_config user.signingkey $GIT_COMMITTER_EMAIL &&
1746         git checkout -b plain-x509 main &&
1747         echo aaa >bar &&
1748         git add bar &&
1749         git commit -m bar_commit &&
1750         git checkout -b tagged-x509 main &&
1751         echo bbb >baz &&
1752         git add baz &&
1753         git commit -m baz_commit &&
1754         git tag -s -m signed_tag_msg signed_tag_x509 &&
1755         git checkout plain-x509 &&
1756         git merge --no-ff -m msg signed_tag_x509 &&
1757         git log --graph --show-signature -n1 plain-x509 >actual &&
1758         grep "^|\\\  merged tag" actual &&
1759         grep "^| | gpgsm: Signature made" actual &&
1760         grep "^| | gpgsm: Good signature" actual
1761 '
1762
1763 test_expect_success GPGSM 'log --graph --show-signature for merged tag x509 missing key' '
1764         test_when_finished "git reset --hard && git checkout main" &&
1765         test_config gpg.format x509 &&
1766         test_config user.signingkey $GIT_COMMITTER_EMAIL &&
1767         git checkout -b plain-x509-nokey main &&
1768         echo aaa >bar &&
1769         git add bar &&
1770         git commit -m bar_commit &&
1771         git checkout -b tagged-x509-nokey main &&
1772         echo bbb >baz &&
1773         git add baz &&
1774         git commit -m baz_commit &&
1775         git tag -s -m signed_tag_msg signed_tag_x509_nokey &&
1776         git checkout plain-x509-nokey &&
1777         git merge --no-ff -m msg signed_tag_x509_nokey &&
1778         GNUPGHOME=. git log --graph --show-signature -n1 plain-x509-nokey >actual &&
1779         grep "^|\\\  merged tag" actual &&
1780         grep "^| | gpgsm: certificate not found" actual
1781 '
1782
1783 test_expect_success GPGSM 'log --graph --show-signature for merged tag x509 bad signature' '
1784         test_when_finished "git reset --hard && git checkout main" &&
1785         test_config gpg.format x509 &&
1786         test_config user.signingkey $GIT_COMMITTER_EMAIL &&
1787         git checkout -b plain-x509-bad main &&
1788         echo aaa >bar &&
1789         git add bar &&
1790         git commit -m bar_commit &&
1791         git checkout -b tagged-x509-bad main &&
1792         echo bbb >baz &&
1793         git add baz &&
1794         git commit -m baz_commit &&
1795         git tag -s -m signed_tag_msg signed_tag_x509_bad &&
1796         git cat-file tag signed_tag_x509_bad >raw &&
1797         sed -e "s/signed_tag_msg/forged/" raw >forged &&
1798         git hash-object -w -t tag forged >forged.tag &&
1799         git checkout plain-x509-bad &&
1800         git merge --no-ff -m msg "$(cat forged.tag)" &&
1801         git log --graph --show-signature -n1 plain-x509-bad >actual &&
1802         grep "^|\\\  merged tag" actual &&
1803         grep "^| | gpgsm: Signature made" actual &&
1804         grep "^| | gpgsm: invalid signature" actual
1805 '
1806
1807
1808 test_expect_success GPG '--no-show-signature overrides --show-signature' '
1809         git log -1 --show-signature --no-show-signature signed >actual &&
1810         ! grep "^gpg:" actual
1811 '
1812
1813 test_expect_success GPG 'log.showsignature=true behaves like --show-signature' '
1814         test_config log.showsignature true &&
1815         git log -1 signed >actual &&
1816         grep "gpg: Signature made" actual &&
1817         grep "gpg: Good signature" actual
1818 '
1819
1820 test_expect_success GPG '--no-show-signature overrides log.showsignature=true' '
1821         test_config log.showsignature true &&
1822         git log -1 --no-show-signature signed >actual &&
1823         ! grep "^gpg:" actual
1824 '
1825
1826 test_expect_success GPG '--show-signature overrides log.showsignature=false' '
1827         test_config log.showsignature false &&
1828         git log -1 --show-signature signed >actual &&
1829         grep "gpg: Signature made" actual &&
1830         grep "gpg: Good signature" actual
1831 '
1832
1833 test_expect_success 'log --graph --no-walk is forbidden' '
1834         test_must_fail git log --graph --no-walk
1835 '
1836
1837 test_expect_success 'log diagnoses bogus HEAD' '
1838         git init empty &&
1839         test_must_fail git -C empty log 2>stderr &&
1840         test_i18ngrep does.not.have.any.commits stderr &&
1841         echo 1234abcd >empty/.git/refs/heads/main &&
1842         test_must_fail git -C empty log 2>stderr &&
1843         test_i18ngrep broken stderr &&
1844         echo "ref: refs/heads/invalid.lock" >empty/.git/HEAD &&
1845         test_must_fail git -C empty log 2>stderr &&
1846         test_i18ngrep broken stderr &&
1847         test_must_fail git -C empty log --default totally-bogus 2>stderr &&
1848         test_i18ngrep broken stderr
1849 '
1850
1851 test_expect_success 'log does not default to HEAD when rev input is given' '
1852         git log --branches=does-not-exist >actual &&
1853         test_must_be_empty actual
1854 '
1855
1856 test_expect_success 'do not default to HEAD with ignored object on cmdline' '
1857         git log --ignore-missing $ZERO_OID >actual &&
1858         test_must_be_empty actual
1859 '
1860
1861 test_expect_success 'do not default to HEAD with ignored object on stdin' '
1862         echo $ZERO_OID | git log --ignore-missing --stdin >actual &&
1863         test_must_be_empty actual
1864 '
1865
1866 test_expect_success 'set up --source tests' '
1867         git checkout --orphan source-a &&
1868         test_commit one &&
1869         test_commit two &&
1870         git checkout -b source-b HEAD^ &&
1871         test_commit three
1872 '
1873
1874 test_expect_success 'log --source paints branch names' '
1875         cat >expect <<-EOF &&
1876         $(git rev-parse --short :/three)        source-b three
1877         $(git rev-parse --short :/two  )        source-a two
1878         $(git rev-parse --short :/one  )        source-b one
1879         EOF
1880         git log --oneline --source source-a source-b >actual &&
1881         test_cmp expect actual
1882 '
1883
1884 test_expect_success 'log --source paints tag names' '
1885         git tag -m tagged source-tag &&
1886         cat >expect <<-EOF &&
1887         $(git rev-parse --short :/three)        source-tag three
1888         $(git rev-parse --short :/two  )        source-a two
1889         $(git rev-parse --short :/one  )        source-tag one
1890         EOF
1891         git log --oneline --source source-tag source-a >actual &&
1892         test_cmp expect actual
1893 '
1894
1895 test_expect_success 'log --source paints symmetric ranges' '
1896         cat >expect <<-EOF &&
1897         $(git rev-parse --short :/three)        source-b three
1898         $(git rev-parse --short :/two  )        source-a two
1899         EOF
1900         git log --oneline --source source-a...source-b >actual &&
1901         test_cmp expect actual
1902 '
1903
1904 test_expect_success '--exclude-promisor-objects does not BUG-crash' '
1905         test_must_fail git log --exclude-promisor-objects source-a
1906 '
1907
1908 test_expect_success 'log --end-of-options' '
1909        git update-ref refs/heads/--source HEAD &&
1910        git log --end-of-options --source >actual &&
1911        git log >expect &&
1912        test_cmp expect actual
1913 '
1914
1915 test_done