1#!/bin/sh
2
3test_description='git log'
4
5. ./test-lib.sh
6
7test_expect_success setup '
8
9 echo one >one &&
10 git add one &&
11 test_tick &&
12 git commit -m initial &&
13
14 echo ichi >one &&
15 git add one &&
16 test_tick &&
17 git commit -m second &&
18
19 git mv one ichi &&
20 test_tick &&
21 git commit -m third &&
22
23 cp ichi ein &&
24 git add ein &&
25 test_tick &&
26 git commit -m fourth &&
27
28 mkdir a &&
29 echo ni >a/two &&
30 git add a/two &&
31 test_tick &&
32 git commit -m fifth &&
33
34 git rm a/two &&
35 test_tick &&
36 git commit -m sixth
37
38'
39
40printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial" > expect
41test_expect_success 'pretty' '
42
43 git log --pretty="format:%s" > actual &&
44 test_cmp expect actual
45'
46
47printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial\n" > expect
48test_expect_success 'pretty (tformat)' '
49
50 git log --pretty="tformat:%s" > actual &&
51 test_cmp expect actual
52'
53
54test_expect_success 'pretty (shortcut)' '
55
56 git log --pretty="%s" > actual &&
57 test_cmp expect actual
58'
59
60test_expect_success 'format' '
61
62 git log --format="%s" > actual &&
63 test_cmp expect actual
64'
65
66cat > expect << EOF
67 This is
68 the sixth
69 commit.
70 This is
71 the fifth
72 commit.
73EOF
74
75test_expect_success 'format %w(11,1,2)' '
76
77 git log -2 --format="%w(11,1,2)This is the %s commit." > actual &&
78 test_cmp expect actual
79'
80
81test_expect_success 'format %w(,1,2)' '
82
83 git log -2 --format="%w(,1,2)This is%nthe %s%ncommit." > actual &&
84 test_cmp expect actual
85'
86
87cat > expect << EOF
88804a787 sixth
89394ef78 fifth
905d31159 fourth
912fbe8c0 third
92f7dab8e second
933a2fdcb initial
94EOF
95test_expect_success 'oneline' '
96
97 git log --oneline > actual &&
98 test_cmp expect actual
99'
100
101test_expect_success 'diff-filter=A' '
102
103 git log --pretty="format:%s" --diff-filter=A HEAD > actual &&
104 git log --pretty="format:%s" --diff-filter A HEAD > actual-separate &&
105 printf "fifth\nfourth\nthird\ninitial" > expect &&
106 test_cmp expect actual &&
107 test_cmp expect actual-separate
108
109'
110
111test_expect_success 'diff-filter=M' '
112
113 actual=$(git log --pretty="format:%s" --diff-filter=M HEAD) &&
114 expect=$(echo second) &&
115 test "$actual" = "$expect" || {
116 echo Oops
117 echo "Actual: $actual"
118 false
119 }
120
121'
122
123test_expect_success 'diff-filter=D' '
124
125 actual=$(git log --pretty="format:%s" --diff-filter=D HEAD) &&
126 expect=$(echo sixth ; echo third) &&
127 test "$actual" = "$expect" || {
128 echo Oops
129 echo "Actual: $actual"
130 false
131 }
132
133'
134
135test_expect_success 'diff-filter=R' '
136
137 actual=$(git log -M --pretty="format:%s" --diff-filter=R HEAD) &&
138 expect=$(echo third) &&
139 test "$actual" = "$expect" || {
140 echo Oops
141 echo "Actual: $actual"
142 false
143 }
144
145'
146
147test_expect_success 'diff-filter=C' '
148
149 actual=$(git log -C -C --pretty="format:%s" --diff-filter=C HEAD) &&
150 expect=$(echo fourth) &&
151 test "$actual" = "$expect" || {
152 echo Oops
153 echo "Actual: $actual"
154 false
155 }
156
157'
158
159test_expect_success 'git log --follow' '
160
161 actual=$(git log --follow --pretty="format:%s" ichi) &&
162 expect=$(echo third ; echo second ; echo initial) &&
163 test "$actual" = "$expect" || {
164 echo Oops
165 echo "Actual: $actual"
166 false
167 }
168
169'
170
171cat > expect << EOF
172804a787 sixth
173394ef78 fifth
1745d31159 fourth
175EOF
176test_expect_success 'git log --no-walk <commits> sorts by commit time' '
177 git log --no-walk --oneline 5d31159 804a787 394ef78 > actual &&
178 test_cmp expect actual
179'
180
181test_expect_success 'git log --no-walk=sorted <commits> sorts by commit time' '
182 git log --no-walk=sorted --oneline 5d31159 804a787 394ef78 > actual &&
183 test_cmp expect actual
184'
185
186cat > expect << EOF
1875d31159 fourth
188804a787 sixth
189394ef78 fifth
190EOF
191test_expect_success 'git log --no-walk=unsorted <commits> leaves list of commits as given' '
192 git log --no-walk=unsorted --oneline 5d31159 804a787 394ef78 > actual &&
193 test_cmp expect actual
194'
195
196test_expect_success 'git show <commits> leaves list of commits as given' '
197 git show --oneline -s 5d31159 804a787 394ef78 > actual &&
198 test_cmp expect actual
199'
200
201test_expect_success 'setup case sensitivity tests' '
202 echo case >one &&
203 test_tick &&
204 git add one &&
205 git commit -a -m Second
206'
207
208test_expect_success 'log --grep' '
209 echo second >expect &&
210 git log -1 --pretty="tformat:%s" --grep=sec >actual &&
211 test_cmp expect actual
212'
213
214test_expect_success 'log --grep option parsing' '
215 echo second >expect &&
216 git log -1 --pretty="tformat:%s" --grep sec >actual &&
217 test_cmp expect actual &&
218 test_must_fail git log -1 --pretty="tformat:%s" --grep
219'
220
221test_expect_success 'log -i --grep' '
222 echo Second >expect &&
223 git log -1 --pretty="tformat:%s" -i --grep=sec >actual &&
224 test_cmp expect actual
225'
226
227test_expect_success 'log --grep -i' '
228 echo Second >expect &&
229 git log -1 --pretty="tformat:%s" --grep=sec -i >actual &&
230 test_cmp expect actual
231'
232
233test_expect_success 'log -F -E --grep=<ere> uses ere' '
234 echo second >expect &&
235 git log -1 --pretty="tformat:%s" -F -E --grep=s.c.nd >actual &&
236 test_cmp expect actual
237'
238
239cat > expect <<EOF
240* Second
241* sixth
242* fifth
243* fourth
244* third
245* second
246* initial
247EOF
248
249test_expect_success 'simple log --graph' '
250 git log --graph --pretty=tformat:%s >actual &&
251 test_cmp expect actual
252'
253
254test_expect_success 'set up merge history' '
255 git checkout -b side HEAD~4 &&
256 test_commit side-1 1 1 &&
257 test_commit side-2 2 2 &&
258 git checkout master &&
259 git merge side
260'
261
262cat > expect <<\EOF
263* Merge branch 'side'
264|\
265| * side-2
266| * side-1
267* | Second
268* | sixth
269* | fifth
270* | fourth
271|/
272* third
273* second
274* initial
275EOF
276
277test_expect_success 'log --graph with merge' '
278 git log --graph --date-order --pretty=tformat:%s |
279 sed "s/ *\$//" >actual &&
280 test_cmp expect actual
281'
282
283cat > expect <<\EOF
284* commit master
285|\ Merge: A B
286| | Author: A U Thor <author@example.com>
287| |
288| | Merge branch 'side'
289| |
290| * commit side
291| | Author: A U Thor <author@example.com>
292| |
293| | side-2
294| |
295| * commit tags/side-1
296| | Author: A U Thor <author@example.com>
297| |
298| | side-1
299| |
300* | commit master~1
301| | Author: A U Thor <author@example.com>
302| |
303| | Second
304| |
305* | commit master~2
306| | Author: A U Thor <author@example.com>
307| |
308| | sixth
309| |
310* | commit master~3
311| | Author: A U Thor <author@example.com>
312| |
313| | fifth
314| |
315* | commit master~4
316|/ Author: A U Thor <author@example.com>
317|
318| fourth
319|
320* commit tags/side-1~1
321| Author: A U Thor <author@example.com>
322|
323| third
324|
325* commit tags/side-1~2
326| Author: A U Thor <author@example.com>
327|
328| second
329|
330* commit tags/side-1~3
331 Author: A U Thor <author@example.com>
332
333 initial
334EOF
335
336test_expect_success 'log --graph with full output' '
337 git log --graph --date-order --pretty=short |
338 git name-rev --name-only --stdin |
339 sed "s/Merge:.*/Merge: A B/;s/ *\$//" >actual &&
340 test_cmp expect actual
341'
342
343test_expect_success 'set up more tangled history' '
344 git checkout -b tangle HEAD~6 &&
345 test_commit tangle-a tangle-a a &&
346 git merge master~3 &&
347 git merge side~1 &&
348 git checkout master &&
349 git merge tangle &&
350 git checkout -b reach &&
351 test_commit reach &&
352 git checkout master &&
353 git checkout -b octopus-a &&
354 test_commit octopus-a &&
355 git checkout master &&
356 git checkout -b octopus-b &&
357 test_commit octopus-b &&
358 git checkout master &&
359 test_commit seventh &&
360 git merge octopus-a octopus-b &&
361 git merge reach
362'
363
364cat > expect <<\EOF
365* Merge tag 'reach'
366|\
367| \
368| \
369*-. \ Merge tags 'octopus-a' and 'octopus-b'
370|\ \ \
371* | | | seventh
372| | * | octopus-b
373| |/ /
374|/| |
375| * | octopus-a
376|/ /
377| * reach
378|/
379* Merge branch 'tangle'
380|\
381| * Merge branch 'side' (early part) into tangle
382| |\
383| * \ Merge branch 'master' (early part) into tangle
384| |\ \
385| * | | tangle-a
386* | | | Merge branch 'side'
387|\ \ \ \
388| * | | | side-2
389| | |_|/
390| |/| |
391| * | | side-1
392* | | | Second
393* | | | sixth
394| |_|/
395|/| |
396* | | fifth
397* | | fourth
398|/ /
399* | third
400|/
401* second
402* initial
403EOF
404
405test_expect_success 'log --graph with merge' '
406 git log --graph --date-order --pretty=tformat:%s |
407 sed "s/ *\$//" >actual &&
408 test_cmp expect actual
409'
410
411test_expect_success 'log.decorate configuration' '
412 test_might_fail git config --unset-all log.decorate &&
413
414 git log --oneline >expect.none &&
415 git log --oneline --decorate >expect.short &&
416 git log --oneline --decorate=full >expect.full &&
417
418 echo "[log] decorate" >>.git/config &&
419 git log --oneline >actual &&
420 test_cmp expect.short actual &&
421
422 git config --unset-all log.decorate &&
423 git config log.decorate true &&
424 git log --oneline >actual &&
425 test_cmp expect.short actual &&
426 git log --oneline --decorate=full >actual &&
427 test_cmp expect.full actual &&
428 git log --oneline --decorate=no >actual &&
429 test_cmp expect.none actual &&
430
431 git config --unset-all log.decorate &&
432 git config log.decorate no &&
433 git log --oneline >actual &&
434 test_cmp expect.none actual &&
435 git log --oneline --decorate >actual &&
436 test_cmp expect.short actual &&
437 git log --oneline --decorate=full >actual &&
438 test_cmp expect.full actual &&
439
440 git config --unset-all log.decorate &&
441 git config log.decorate 1 &&
442 git log --oneline >actual &&
443 test_cmp expect.short actual &&
444 git log --oneline --decorate=full >actual &&
445 test_cmp expect.full actual &&
446 git log --oneline --decorate=no >actual &&
447 test_cmp expect.none actual &&
448
449 git config --unset-all log.decorate &&
450 git config log.decorate short &&
451 git log --oneline >actual &&
452 test_cmp expect.short actual &&
453 git log --oneline --no-decorate >actual &&
454 test_cmp expect.none actual &&
455 git log --oneline --decorate=full >actual &&
456 test_cmp expect.full actual &&
457
458 git config --unset-all log.decorate &&
459 git config log.decorate full &&
460 git log --oneline >actual &&
461 test_cmp expect.full actual &&
462 git log --oneline --no-decorate >actual &&
463 test_cmp expect.none actual &&
464 git log --oneline --decorate >actual &&
465 test_cmp expect.short actual
466
467 git config --unset-all log.decorate &&
468 git log --pretty=raw >expect.raw &&
469 git config log.decorate full &&
470 git log --pretty=raw >actual &&
471 test_cmp expect.raw actual
472
473'
474
475test_expect_success 'reflog is expected format' '
476 test_might_fail git config --remove-section log &&
477 git log -g --abbrev-commit --pretty=oneline >expect &&
478 git reflog >actual &&
479 test_cmp expect actual
480'
481
482test_expect_success 'whatchanged is expected format' '
483 git log --no-merges --raw >expect &&
484 git whatchanged >actual &&
485 test_cmp expect actual
486'
487
488test_expect_success 'log.abbrevCommit configuration' '
489 test_when_finished "git config --unset log.abbrevCommit" &&
490
491 test_might_fail git config --unset log.abbrevCommit &&
492
493 git log --abbrev-commit >expect.log.abbrev &&
494 git log --no-abbrev-commit >expect.log.full &&
495 git log --pretty=raw >expect.log.raw &&
496 git reflog --abbrev-commit >expect.reflog.abbrev &&
497 git reflog --no-abbrev-commit >expect.reflog.full &&
498 git whatchanged --abbrev-commit >expect.whatchanged.abbrev &&
499 git whatchanged --no-abbrev-commit >expect.whatchanged.full &&
500
501 git config log.abbrevCommit true &&
502
503 git log >actual &&
504 test_cmp expect.log.abbrev actual &&
505 git log --no-abbrev-commit >actual &&
506 test_cmp expect.log.full actual &&
507
508 git log --pretty=raw >actual &&
509 test_cmp expect.log.raw actual &&
510
511 git reflog >actual &&
512 test_cmp expect.reflog.abbrev actual &&
513 git reflog --no-abbrev-commit >actual &&
514 test_cmp expect.reflog.full actual &&
515
516 git whatchanged >actual &&
517 test_cmp expect.whatchanged.abbrev actual &&
518 git whatchanged --no-abbrev-commit >actual &&
519 test_cmp expect.whatchanged.full actual
520'
521
522test_expect_success 'show added path under "--follow -M"' '
523 # This tests for a regression introduced in v1.7.2-rc0~103^2~2
524 test_create_repo regression &&
525 (
526 cd regression &&
527 test_commit needs-another-commit &&
528 test_commit foo.bar &&
529 git log -M --follow -p foo.bar.t &&
530 git log -M --follow --stat foo.bar.t &&
531 git log -M --follow --name-only foo.bar.t
532 )
533'
534
535cat >expect <<\EOF
536* commit COMMIT_OBJECT_NAME
537|\ Merge: MERGE_PARENTS
538| | Author: A U Thor <author@example.com>
539| |
540| | Merge HEADS DESCRIPTION
541| |
542| * commit COMMIT_OBJECT_NAME
543| | Author: A U Thor <author@example.com>
544| |
545| | reach
546| | ---
547| | reach.t | 1 +
548| | 1 file changed, 1 insertion(+)
549| |
550| | diff --git a/reach.t b/reach.t
551| | new file mode 100644
552| | index 0000000..10c9591
553| | --- /dev/null
554| | +++ b/reach.t
555| | @@ -0,0 +1 @@
556| | +reach
557| |
558| \
559*-. \ commit COMMIT_OBJECT_NAME
560|\ \ \ Merge: MERGE_PARENTS
561| | | | Author: A U Thor <author@example.com>
562| | | |
563| | | | Merge HEADS DESCRIPTION
564| | | |
565| | * | commit COMMIT_OBJECT_NAME
566| | |/ Author: A U Thor <author@example.com>
567| | |
568| | | octopus-b
569| | | ---
570| | | octopus-b.t | 1 +
571| | | 1 file changed, 1 insertion(+)
572| | |
573| | | diff --git a/octopus-b.t b/octopus-b.t
574| | | new file mode 100644
575| | | index 0000000..d5fcad0
576| | | --- /dev/null
577| | | +++ b/octopus-b.t
578| | | @@ -0,0 +1 @@
579| | | +octopus-b
580| | |
581| * | commit COMMIT_OBJECT_NAME
582| |/ Author: A U Thor <author@example.com>
583| |
584| | octopus-a
585| | ---
586| | octopus-a.t | 1 +
587| | 1 file changed, 1 insertion(+)
588| |
589| | diff --git a/octopus-a.t b/octopus-a.t
590| | new file mode 100644
591| | index 0000000..11ee015
592| | --- /dev/null
593| | +++ b/octopus-a.t
594| | @@ -0,0 +1 @@
595| | +octopus-a
596| |
597* | commit COMMIT_OBJECT_NAME
598|/ Author: A U Thor <author@example.com>
599|
600| seventh
601| ---
602| seventh.t | 1 +
603| 1 file changed, 1 insertion(+)
604|
605| diff --git a/seventh.t b/seventh.t
606| new file mode 100644
607| index 0000000..9744ffc
608| --- /dev/null
609| +++ b/seventh.t
610| @@ -0,0 +1 @@
611| +seventh
612|
613* commit COMMIT_OBJECT_NAME
614|\ Merge: MERGE_PARENTS
615| | Author: A U Thor <author@example.com>
616| |
617| | Merge branch 'tangle'
618| |
619| * commit COMMIT_OBJECT_NAME
620| |\ Merge: MERGE_PARENTS
621| | | Author: A U Thor <author@example.com>
622| | |
623| | | Merge branch 'side' (early part) into tangle
624| | |
625| * | commit COMMIT_OBJECT_NAME
626| |\ \ Merge: MERGE_PARENTS
627| | | | Author: A U Thor <author@example.com>
628| | | |
629| | | | Merge branch 'master' (early part) into tangle
630| | | |
631| * | | commit COMMIT_OBJECT_NAME
632| | | | Author: A U Thor <author@example.com>
633| | | |
634| | | | tangle-a
635| | | | ---
636| | | | tangle-a | 1 +
637| | | | 1 file changed, 1 insertion(+)
638| | | |
639| | | | diff --git a/tangle-a b/tangle-a
640| | | | new file mode 100644
641| | | | index 0000000..7898192
642| | | | --- /dev/null
643| | | | +++ b/tangle-a
644| | | | @@ -0,0 +1 @@
645| | | | +a
646| | | |
647* | | | commit COMMIT_OBJECT_NAME
648|\ \ \ \ Merge: MERGE_PARENTS
649| | | | | Author: A U Thor <author@example.com>
650| | | | |
651| | | | | Merge branch 'side'
652| | | | |
653| * | | | commit COMMIT_OBJECT_NAME
654| | |_|/ Author: A U Thor <author@example.com>
655| |/| |
656| | | | side-2
657| | | | ---
658| | | | 2 | 1 +
659| | | | 1 file changed, 1 insertion(+)
660| | | |
661| | | | diff --git a/2 b/2
662| | | | new file mode 100644
663| | | | index 0000000..0cfbf08
664| | | | --- /dev/null
665| | | | +++ b/2
666| | | | @@ -0,0 +1 @@
667| | | | +2
668| | | |
669| * | | commit COMMIT_OBJECT_NAME
670| | | | Author: A U Thor <author@example.com>
671| | | |
672| | | | side-1
673| | | | ---
674| | | | 1 | 1 +
675| | | | 1 file changed, 1 insertion(+)
676| | | |
677| | | | diff --git a/1 b/1
678| | | | new file mode 100644
679| | | | index 0000000..d00491f
680| | | | --- /dev/null
681| | | | +++ b/1
682| | | | @@ -0,0 +1 @@
683| | | | +1
684| | | |
685* | | | commit COMMIT_OBJECT_NAME
686| | | | Author: A U Thor <author@example.com>
687| | | |
688| | | | Second
689| | | | ---
690| | | | one | 1 +
691| | | | 1 file changed, 1 insertion(+)
692| | | |
693| | | | diff --git a/one b/one
694| | | | new file mode 100644
695| | | | index 0000000..9a33383
696| | | | --- /dev/null
697| | | | +++ b/one
698| | | | @@ -0,0 +1 @@
699| | | | +case
700| | | |
701* | | | commit COMMIT_OBJECT_NAME
702| |_|/ Author: A U Thor <author@example.com>
703|/| |
704| | | sixth
705| | | ---
706| | | a/two | 1 -
707| | | 1 file changed, 1 deletion(-)
708| | |
709| | | diff --git a/a/two b/a/two
710| | | deleted file mode 100644
711| | | index 9245af5..0000000
712| | | --- a/a/two
713| | | +++ /dev/null
714| | | @@ -1 +0,0 @@
715| | | -ni
716| | |
717* | | commit COMMIT_OBJECT_NAME
718| | | Author: A U Thor <author@example.com>
719| | |
720| | | fifth
721| | | ---
722| | | a/two | 1 +
723| | | 1 file changed, 1 insertion(+)
724| | |
725| | | diff --git a/a/two b/a/two
726| | | new file mode 100644
727| | | index 0000000..9245af5
728| | | --- /dev/null
729| | | +++ b/a/two
730| | | @@ -0,0 +1 @@
731| | | +ni
732| | |
733* | | commit COMMIT_OBJECT_NAME
734|/ / Author: A U Thor <author@example.com>
735| |
736| | fourth
737| | ---
738| | ein | 1 +
739| | 1 file changed, 1 insertion(+)
740| |
741| | diff --git a/ein b/ein
742| | new file mode 100644
743| | index 0000000..9d7e69f
744| | --- /dev/null
745| | +++ b/ein
746| | @@ -0,0 +1 @@
747| | +ichi
748| |
749* | commit COMMIT_OBJECT_NAME
750|/ Author: A U Thor <author@example.com>
751|
752| third
753| ---
754| ichi | 1 +
755| one | 1 -
756| 2 files changed, 1 insertion(+), 1 deletion(-)
757|
758| diff --git a/ichi b/ichi
759| new file mode 100644
760| index 0000000..9d7e69f
761| --- /dev/null
762| +++ b/ichi
763| @@ -0,0 +1 @@
764| +ichi
765| diff --git a/one b/one
766| deleted file mode 100644
767| index 9d7e69f..0000000
768| --- a/one
769| +++ /dev/null
770| @@ -1 +0,0 @@
771| -ichi
772|
773* commit COMMIT_OBJECT_NAME
774| Author: A U Thor <author@example.com>
775|
776| second
777| ---
778| one | 2 +-
779| 1 file changed, 1 insertion(+), 1 deletion(-)
780|
781| diff --git a/one b/one
782| index 5626abf..9d7e69f 100644
783| --- a/one
784| +++ b/one
785| @@ -1 +1 @@
786| -one
787| +ichi
788|
789* commit COMMIT_OBJECT_NAME
790 Author: A U Thor <author@example.com>
791
792 initial
793 ---
794 one | 1 +
795 1 file changed, 1 insertion(+)
796
797 diff --git a/one b/one
798 new file mode 100644
799 index 0000000..5626abf
800 --- /dev/null
801 +++ b/one
802 @@ -0,0 +1 @@
803 +one
804EOF
805
806sanitize_output () {
807 sed -e 's/ *$//' \
808 -e 's/commit [0-9a-f]*$/commit COMMIT_OBJECT_NAME/' \
809 -e 's/Merge: [ 0-9a-f]*$/Merge: MERGE_PARENTS/' \
810 -e 's/Merge tag.*/Merge HEADS DESCRIPTION/' \
811 -e 's/Merge commit.*/Merge HEADS DESCRIPTION/' \
812 -e 's/, 0 deletions(-)//' \
813 -e 's/, 0 insertions(+)//' \
814 -e 's/ 1 files changed, / 1 file changed, /' \
815 -e 's/, 1 deletions(-)/, 1 deletion(-)/' \
816 -e 's/, 1 insertions(+)/, 1 insertion(+)/'
817}
818
819test_expect_success 'log --graph with diff and stats' '
820 git log --graph --pretty=short --stat -p >actual &&
821 sanitize_output >actual.sanitized <actual &&
822 test_i18ncmp expect actual.sanitized
823'
824
825test_expect_success 'dotdot is a parent directory' '
826 mkdir -p a/b &&
827 ( echo sixth && echo fifth ) >expect &&
828 ( cd a/b && git log --format=%s .. ) >actual &&
829 test_cmp expect actual
830'
831
832test_done