blob: 222f7559e92caa2a0bbd128b0bb6bac14e2e113f [file] [log] [blame]
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +01001#!/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
Arjen Laarhovend9305082009-01-22 17:37:24 +010019 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
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +010028 mkdir a &&
29 echo ni >a/two &&
30 git add a/two &&
31 test_tick &&
Arjen Laarhovend9305082009-01-22 17:37:24 +010032 git commit -m fifth &&
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +010033
Arjen Laarhovend9305082009-01-22 17:37:24 +010034 git rm a/two &&
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +010035 test_tick &&
Arjen Laarhovend9305082009-01-22 17:37:24 +010036 git commit -m sixth
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +010037
38'
39
Felipe Contrerasbb93afd2009-02-24 23:06:37 +020040printf "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
René Scharfe37bb5d72009-11-22 17:15:29 +010067 This is
68 the sixth
69 commit.
70 This is
71 the fifth
72 commit.
73EOF
74
75test_expect_success 'format %w(12,1,2)' '
76
77 git log -2 --format="%w(12,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
Felipe Contrerasbb93afd2009-02-24 23:06:37 +020088804a787 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
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +0100101test_expect_success 'diff-filter=A' '
102
Matthieu Moydea007f2010-08-05 10:22:52 +0200103 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
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +0100108
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) &&
Arjen Laarhovend9305082009-01-22 17:37:24 +0100126 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) &&
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +0100163 test "$actual" = "$expect" || {
164 echo Oops
165 echo "Actual: $actual"
166 false
167 }
168
169'
170
Michael J Gruberd5cee0f2009-07-17 16:28:06 +0200171cat > 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
181cat > expect << EOF
1825d31159 fourth
183804a787 sixth
184394ef78 fifth
185EOF
186test_expect_success 'git show <commits> leaves list of commits as given' '
187 git show --oneline -s 5d31159 804a787 394ef78 > actual &&
188 test_cmp expect actual
189'
190
Jeff King0843acf2008-08-25 02:15:05 -0400191test_expect_success 'setup case sensitivity tests' '
192 echo case >one &&
193 test_tick &&
Jonathan Niedera48fcd82010-10-30 20:46:54 -0500194 git add one &&
Jeff King0843acf2008-08-25 02:15:05 -0400195 git commit -a -m Second
196'
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +0100197
Jeff King0843acf2008-08-25 02:15:05 -0400198test_expect_success 'log --grep' '
199 echo second >expect &&
200 git log -1 --pretty="tformat:%s" --grep=sec >actual &&
201 test_cmp expect actual
202'
203
Matthieu Moy7d7b86f2010-08-05 10:22:55 +0200204test_expect_success 'log --grep option parsing' '
205 echo second >expect &&
206 git log -1 --pretty="tformat:%s" --grep sec >actual &&
207 test_cmp expect actual &&
208 test_must_fail git log -1 --pretty="tformat:%s" --grep
209'
210
Jeff King0843acf2008-08-25 02:15:05 -0400211test_expect_success 'log -i --grep' '
212 echo Second >expect &&
213 git log -1 --pretty="tformat:%s" -i --grep=sec >actual &&
214 test_cmp expect actual
215'
216
217test_expect_success 'log --grep -i' '
218 echo Second >expect &&
219 git log -1 --pretty="tformat:%s" --grep=sec -i >actual &&
220 test_cmp expect actual
221'
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +0100222
Thomas Rast289e1622009-02-19 12:13:38 +0100223cat > expect <<EOF
224* Second
225* sixth
226* fifth
227* fourth
228* third
229* second
230* initial
231EOF
232
233test_expect_success 'simple log --graph' '
234 git log --graph --pretty=tformat:%s >actual &&
235 test_cmp expect actual
236'
237
238test_expect_success 'set up merge history' '
239 git checkout -b side HEAD~4 &&
240 test_commit side-1 1 1 &&
241 test_commit side-2 2 2 &&
242 git checkout master &&
243 git merge side
244'
245
246cat > expect <<\EOF
247* Merge branch 'side'
248|\
249| * side-2
250| * side-1
251* | Second
252* | sixth
253* | fifth
254* | fourth
255|/
256* third
257* second
258* initial
259EOF
260
261test_expect_success 'log --graph with merge' '
262 git log --graph --date-order --pretty=tformat:%s |
Stephen Boyd9524cf22010-01-26 15:08:31 -0800263 sed "s/ *\$//" >actual &&
Thomas Rast289e1622009-02-19 12:13:38 +0100264 test_cmp expect actual
265'
266
267cat > expect <<\EOF
268* commit master
269|\ Merge: A B
270| | Author: A U Thor <author@example.com>
271| |
272| | Merge branch 'side'
273| |
274| * commit side
275| | Author: A U Thor <author@example.com>
276| |
277| | side-2
278| |
279| * commit tags/side-1
280| | Author: A U Thor <author@example.com>
281| |
282| | side-1
283| |
284* | commit master~1
285| | Author: A U Thor <author@example.com>
286| |
287| | Second
288| |
289* | commit master~2
290| | Author: A U Thor <author@example.com>
291| |
292| | sixth
293| |
294* | commit master~3
295| | Author: A U Thor <author@example.com>
296| |
297| | fifth
298| |
299* | commit master~4
300|/ Author: A U Thor <author@example.com>
301|
302| fourth
303|
304* commit tags/side-1~1
305| Author: A U Thor <author@example.com>
306|
307| third
308|
309* commit tags/side-1~2
310| Author: A U Thor <author@example.com>
311|
312| second
313|
314* commit tags/side-1~3
315 Author: A U Thor <author@example.com>
316
317 initial
318EOF
319
320test_expect_success 'log --graph with full output' '
321 git log --graph --date-order --pretty=short |
322 git name-rev --name-only --stdin |
Stephen Boyd9524cf22010-01-26 15:08:31 -0800323 sed "s/Merge:.*/Merge: A B/;s/ *\$//" >actual &&
Thomas Rast289e1622009-02-19 12:13:38 +0100324 test_cmp expect actual
325'
326
327test_expect_success 'set up more tangled history' '
328 git checkout -b tangle HEAD~6 &&
329 test_commit tangle-a tangle-a a &&
330 git merge master~3 &&
331 git merge side~1 &&
332 git checkout master &&
Allan Caffee7b1d6262009-04-22 17:27:15 -0400333 git merge tangle &&
334 git checkout -b reach &&
335 test_commit reach &&
336 git checkout master &&
337 git checkout -b octopus-a &&
338 test_commit octopus-a &&
339 git checkout master &&
340 git checkout -b octopus-b &&
341 test_commit octopus-b &&
342 git checkout master &&
343 test_commit seventh &&
Jonathan Niedera48fcd82010-10-30 20:46:54 -0500344 git merge octopus-a octopus-b &&
Allan Caffee7b1d6262009-04-22 17:27:15 -0400345 git merge reach
Thomas Rast289e1622009-02-19 12:13:38 +0100346'
347
348cat > expect <<\EOF
Junio C Hamano57b58db2011-11-04 21:31:28 -0700349* Merge tag 'reach'
Allan Caffee7b1d6262009-04-22 17:27:15 -0400350|\
351| \
352| \
Junio C Hamano57b58db2011-11-04 21:31:28 -0700353*-. \ Merge tags 'octopus-a' and 'octopus-b'
Allan Caffee7b1d6262009-04-22 17:27:15 -0400354|\ \ \
355* | | | seventh
356| | * | octopus-b
357| |/ /
358|/| |
359| * | octopus-a
360|/ /
361| * reach
362|/
Thomas Rast289e1622009-02-19 12:13:38 +0100363* Merge branch 'tangle'
364|\
365| * Merge branch 'side' (early part) into tangle
366| |\
367| * \ Merge branch 'master' (early part) into tangle
368| |\ \
369| * | | tangle-a
370* | | | Merge branch 'side'
371|\ \ \ \
372| * | | | side-2
Allan Caffeeeaf158f2009-04-21 08:47:01 -0400373| | |_|/
Thomas Rast289e1622009-02-19 12:13:38 +0100374| |/| |
375| * | | side-1
376* | | | Second
377* | | | sixth
Allan Caffeeeaf158f2009-04-21 08:47:01 -0400378| |_|/
Thomas Rast289e1622009-02-19 12:13:38 +0100379|/| |
380* | | fifth
381* | | fourth
382|/ /
383* | third
384|/
385* second
386* initial
387EOF
388
Linus Torvalds95110d72009-04-26 12:29:13 -0700389test_expect_success 'log --graph with merge' '
Thomas Rast289e1622009-02-19 12:13:38 +0100390 git log --graph --date-order --pretty=tformat:%s |
Stephen Boyd9524cf22010-01-26 15:08:31 -0800391 sed "s/ *\$//" >actual &&
Thomas Rast289e1622009-02-19 12:13:38 +0100392 test_cmp expect actual
393'
394
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800395test_expect_success 'log.decorate configuration' '
Elijah Newren5a57bc62010-10-03 14:00:04 -0600396 test_might_fail git config --unset-all log.decorate &&
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800397
Junio C Hamano4f62c2b2010-04-08 10:17:17 -0700398 git log --oneline >expect.none &&
399 git log --oneline --decorate >expect.short &&
400 git log --oneline --decorate=full >expect.full &&
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800401
402 echo "[log] decorate" >>.git/config &&
Junio C Hamano635530a2010-04-06 14:48:55 -0700403 git log --oneline >actual &&
Junio C Hamano4f62c2b2010-04-08 10:17:17 -0700404 test_cmp expect.short actual &&
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800405
406 git config --unset-all log.decorate &&
407 git config log.decorate true &&
Junio C Hamano635530a2010-04-06 14:48:55 -0700408 git log --oneline >actual &&
Junio C Hamano4f62c2b2010-04-08 10:17:17 -0700409 test_cmp expect.short actual &&
410 git log --oneline --decorate=full >actual &&
411 test_cmp expect.full actual &&
412 git log --oneline --decorate=no >actual &&
413 test_cmp expect.none actual &&
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800414
415 git config --unset-all log.decorate &&
416 git config log.decorate no &&
Junio C Hamano635530a2010-04-06 14:48:55 -0700417 git log --oneline >actual &&
Junio C Hamano4f62c2b2010-04-08 10:17:17 -0700418 test_cmp expect.none actual &&
419 git log --oneline --decorate >actual &&
420 test_cmp expect.short actual &&
421 git log --oneline --decorate=full >actual &&
422 test_cmp expect.full actual &&
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800423
424 git config --unset-all log.decorate &&
Jeff Kingb2be2f62010-11-17 12:00:45 -0500425 git config log.decorate 1 &&
426 git log --oneline >actual &&
427 test_cmp expect.short actual &&
428 git log --oneline --decorate=full >actual &&
429 test_cmp expect.full actual &&
430 git log --oneline --decorate=no >actual &&
431 test_cmp expect.none actual &&
432
433 git config --unset-all log.decorate &&
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800434 git config log.decorate short &&
Junio C Hamano635530a2010-04-06 14:48:55 -0700435 git log --oneline >actual &&
Junio C Hamano4f62c2b2010-04-08 10:17:17 -0700436 test_cmp expect.short actual &&
437 git log --oneline --no-decorate >actual &&
438 test_cmp expect.none actual &&
439 git log --oneline --decorate=full >actual &&
440 test_cmp expect.full actual &&
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800441
442 git config --unset-all log.decorate &&
443 git config log.decorate full &&
Junio C Hamano635530a2010-04-06 14:48:55 -0700444 git log --oneline >actual &&
Junio C Hamano4f62c2b2010-04-08 10:17:17 -0700445 test_cmp expect.full actual &&
446 git log --oneline --no-decorate >actual &&
447 test_cmp expect.none actual &&
448 git log --oneline --decorate >actual &&
449 test_cmp expect.short actual
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800450
Jay Soffian0c476952011-05-18 13:56:04 -0400451 git config --unset-all log.decorate &&
452 git log --pretty=raw >expect.raw &&
453 git config log.decorate full &&
454 git log --pretty=raw >actual &&
455 test_cmp expect.raw actual
456
457'
458
459test_expect_success 'reflog is expected format' '
460 test_might_fail git config --remove-section log &&
461 git log -g --abbrev-commit --pretty=oneline >expect &&
462 git reflog >actual &&
463 test_cmp expect actual
464'
465
466test_expect_success 'whatchanged is expected format' '
467 git log --no-merges --raw >expect &&
468 git whatchanged >actual &&
469 test_cmp expect actual
470'
471
472test_expect_success 'log.abbrevCommit configuration' '
473 test_when_finished "git config --unset log.abbrevCommit" &&
474
475 test_might_fail git config --unset log.abbrevCommit &&
476
477 git log --abbrev-commit >expect.log.abbrev &&
478 git log --no-abbrev-commit >expect.log.full &&
479 git log --pretty=raw >expect.log.raw &&
480 git reflog --abbrev-commit >expect.reflog.abbrev &&
481 git reflog --no-abbrev-commit >expect.reflog.full &&
482 git whatchanged --abbrev-commit >expect.whatchanged.abbrev &&
483 git whatchanged --no-abbrev-commit >expect.whatchanged.full &&
484
485 git config log.abbrevCommit true &&
486
487 git log >actual &&
488 test_cmp expect.log.abbrev actual &&
489 git log --no-abbrev-commit >actual &&
490 test_cmp expect.log.full actual &&
491
492 git log --pretty=raw >actual &&
493 test_cmp expect.log.raw actual &&
494
495 git reflog >actual &&
496 test_cmp expect.reflog.abbrev actual &&
497 git reflog --no-abbrev-commit >actual &&
498 test_cmp expect.reflog.full actual &&
499
500 git whatchanged >actual &&
501 test_cmp expect.whatchanged.abbrev actual &&
502 git whatchanged --no-abbrev-commit >actual &&
503 test_cmp expect.whatchanged.full actual
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800504'
505
Ævar Arnfjörð Bjarmason65113122010-08-15 10:16:25 +0000506test_expect_success 'show added path under "--follow -M"' '
507 # This tests for a regression introduced in v1.7.2-rc0~103^2~2
508 test_create_repo regression &&
509 (
510 cd regression &&
511 test_commit needs-another-commit &&
512 test_commit foo.bar &&
513 git log -M --follow -p foo.bar.t &&
514 git log -M --follow --stat foo.bar.t &&
515 git log -M --follow --name-only foo.bar.t
516 )
517'
Brandon Caseyc65233f2008-07-22 16:23:31 -0500518
Ævar Arnfjörð Bjarmason65113122010-08-15 10:16:25 +0000519test_done