blob: e4f02d8208b4d274935a37962f1bf6d80b858ada [file] [log] [blame]
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +01001#!/bin/sh
2
3test_description='git log'
4
Johannes Schindelin8f378542020-11-18 23:44:27 +00005GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00006export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +01008. ./test-lib.sh
Zoltan Klingercf3983d2014-07-09 12:10:21 +10009. "$TEST_DIRECTORY/lib-gpg.sh"
Alex Henrie940a9112017-03-23 23:46:31 -060010. "$TEST_DIRECTORY/lib-terminal.sh"
Abhishek Kumar989eea92020-02-24 19:08:13 +053011. "$TEST_DIRECTORY/lib-log-graph.sh"
12
13test_cmp_graph () {
14 lib_test_cmp_graph --format=%s "$@"
15}
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +010016
17test_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
Arjen Laarhovend9305082009-01-22 17:37:24 +010029 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
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +010038 mkdir a &&
39 echo ni >a/two &&
40 git add a/two &&
41 test_tick &&
Arjen Laarhovend9305082009-01-22 17:37:24 +010042 git commit -m fifth &&
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +010043
Arjen Laarhovend9305082009-01-22 17:37:24 +010044 git rm a/two &&
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +010045 test_tick &&
Arjen Laarhovend9305082009-01-22 17:37:24 +010046 git commit -m sixth
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +010047
48'
49
Felipe Contrerasbb93afd2009-02-24 23:06:37 +020050printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial" > expect
51test_expect_success 'pretty' '
52
53 git log --pretty="format:%s" > actual &&
54 test_cmp expect actual
55'
56
57printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial\n" > expect
58test_expect_success 'pretty (tformat)' '
59
60 git log --pretty="tformat:%s" > actual &&
61 test_cmp expect actual
62'
63
64test_expect_success 'pretty (shortcut)' '
65
66 git log --pretty="%s" > actual &&
67 test_cmp expect actual
68'
69
70test_expect_success 'format' '
71
72 git log --format="%s" > actual &&
73 test_cmp expect actual
74'
75
76cat > expect << EOF
René Scharfe37bb5d72009-11-22 17:15:29 +010077 This is
78 the sixth
79 commit.
80 This is
81 the fifth
82 commit.
83EOF
84
Jan H. Schönherr14e1a4e2012-10-18 16:43:28 +020085test_expect_success 'format %w(11,1,2)' '
René Scharfe37bb5d72009-11-22 17:15:29 +010086
Jan H. Schönherr14e1a4e2012-10-18 16:43:28 +020087 git log -2 --format="%w(11,1,2)This is the %s commit." > actual &&
René Scharfe37bb5d72009-11-22 17:15:29 +010088 test_cmp expect actual
89'
90
91test_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
97cat > expect << EOF
brian m. carlsoncb78f4f2019-12-21 19:49:21 +000098$(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
Felipe Contrerasbb93afd2009-02-24 23:06:37 +0200104EOF
105test_expect_success 'oneline' '
106
107 git log --oneline > actual &&
108 test_cmp expect actual
109'
110
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +0100111test_expect_success 'diff-filter=A' '
112
Matthieu Moy5404c112016-02-25 09:59:21 +0100113 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 &&
Matthieu Moydea007f2010-08-05 10:22:52 +0200115 printf "fifth\nfourth\nthird\ninitial" > expect &&
116 test_cmp expect actual &&
117 test_cmp expect actual-separate
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +0100118
119'
120
121test_expect_success 'diff-filter=M' '
122
Eric Sunshine88511d22021-12-09 00:11:00 -0500123 git log --pretty="format:%s" --diff-filter=M HEAD >actual &&
124 printf "second" >expect &&
125 test_cmp expect actual
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +0100126
127'
128
129test_expect_success 'diff-filter=D' '
130
Eric Sunshine88511d22021-12-09 00:11:00 -0500131 git log --no-renames --pretty="format:%s" --diff-filter=D HEAD >actual &&
132 printf "sixth\nthird" >expect &&
133 test_cmp expect actual
Arjen Laarhovend9305082009-01-22 17:37:24 +0100134
135'
136
137test_expect_success 'diff-filter=R' '
138
Eric Sunshine88511d22021-12-09 00:11:00 -0500139 git log -M --pretty="format:%s" --diff-filter=R HEAD >actual &&
140 printf "third" >expect &&
141 test_cmp expect actual
Arjen Laarhovend9305082009-01-22 17:37:24 +0100142
143'
144
Johannes Schindelin75408ca2022-01-28 12:02:50 +0000145test_expect_success 'multiple --diff-filter bits' '
146
147 git log -M --pretty="format:%s" --diff-filter=R HEAD >expect &&
148 git log -M --pretty="format:%s" --diff-filter=Ra HEAD >actual &&
149 test_cmp expect actual &&
150 git log -M --pretty="format:%s" --diff-filter=aR HEAD >actual &&
151 test_cmp expect actual &&
152 git log -M --pretty="format:%s" \
153 --diff-filter=a --diff-filter=R HEAD >actual &&
154 test_cmp expect actual
155
156'
157
Arjen Laarhovend9305082009-01-22 17:37:24 +0100158test_expect_success 'diff-filter=C' '
159
Eric Sunshine88511d22021-12-09 00:11:00 -0500160 git log -C -C --pretty="format:%s" --diff-filter=C HEAD >actual &&
161 printf "fourth" >expect &&
162 test_cmp expect actual
Arjen Laarhovend9305082009-01-22 17:37:24 +0100163
164'
165
166test_expect_success 'git log --follow' '
167
Eric Sunshine88511d22021-12-09 00:11:00 -0500168 git log --follow --pretty="format:%s" ichi >actual &&
169 printf "third\nsecond\ninitial" >expect &&
170 test_cmp expect actual
David Turner076c9832015-07-07 21:29:34 -0400171'
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +0100172
David Turner076c9832015-07-07 21:29:34 -0400173test_expect_success 'git config log.follow works like --follow' '
174 test_config log.follow true &&
Eric Sunshine88511d22021-12-09 00:11:00 -0500175 git log --pretty="format:%s" ichi >actual &&
176 printf "third\nsecond\ninitial" >expect &&
177 test_cmp expect actual
David Turner076c9832015-07-07 21:29:34 -0400178'
179
180test_expect_success 'git config log.follow does not die with multiple paths' '
181 test_config log.follow true &&
182 git log --pretty="format:%s" ichi ein
183'
184
185test_expect_success 'git config log.follow does not die with no paths' '
186 test_config log.follow true &&
187 git log --
188'
189
190test_expect_success 'git config log.follow is overridden by --no-follow' '
191 test_config log.follow true &&
Eric Sunshine88511d22021-12-09 00:11:00 -0500192 git log --no-follow --pretty="format:%s" ichi >actual &&
193 printf "third" >expect &&
194 test_cmp expect actual
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +0100195'
196
brian m. carlsoncb78f4f2019-12-21 19:49:21 +0000197# Note that these commits are intentionally listed out of order.
198last_three="$(git rev-parse :/fourth :/sixth :/fifth)"
Michael J Gruberd5cee0f2009-07-17 16:28:06 +0200199cat > expect << EOF
brian m. carlsoncb78f4f2019-12-21 19:49:21 +0000200$(git rev-parse --short :/sixth ) sixth
201$(git rev-parse --short :/fifth ) fifth
202$(git rev-parse --short :/fourth) fourth
Michael J Gruberd5cee0f2009-07-17 16:28:06 +0200203EOF
204test_expect_success 'git log --no-walk <commits> sorts by commit time' '
brian m. carlsoncb78f4f2019-12-21 19:49:21 +0000205 git log --no-walk --oneline $last_three > actual &&
Michael J Gruberd5cee0f2009-07-17 16:28:06 +0200206 test_cmp expect actual
207'
208
Martin von Zweigbergkca92e592012-08-28 23:15:54 -0700209test_expect_success 'git log --no-walk=sorted <commits> sorts by commit time' '
brian m. carlsoncb78f4f2019-12-21 19:49:21 +0000210 git log --no-walk=sorted --oneline $last_three > actual &&
Martin von Zweigbergkca92e592012-08-28 23:15:54 -0700211 test_cmp expect actual
212'
213
Michael J Gruberd5cee0f2009-07-17 16:28:06 +0200214cat > expect << EOF
brian m. carlsoncb78f4f2019-12-21 19:49:21 +0000215=== $(git rev-parse --short :/sixth ) sixth
216=== $(git rev-parse --short :/fifth ) fifth
217=== $(git rev-parse --short :/fourth) fourth
Jacob Keller660e1132016-08-31 16:27:20 -0700218EOF
219test_expect_success 'git log --line-prefix="=== " --no-walk <commits> sorts by commit time' '
brian m. carlsoncb78f4f2019-12-21 19:49:21 +0000220 git log --line-prefix="=== " --no-walk --oneline $last_three > actual &&
Jacob Keller660e1132016-08-31 16:27:20 -0700221 test_cmp expect actual
222'
223
224cat > expect << EOF
brian m. carlsoncb78f4f2019-12-21 19:49:21 +0000225$(git rev-parse --short :/fourth) fourth
226$(git rev-parse --short :/sixth ) sixth
227$(git rev-parse --short :/fifth ) fifth
Michael J Gruberd5cee0f2009-07-17 16:28:06 +0200228EOF
Martin von Zweigbergkca92e592012-08-28 23:15:54 -0700229test_expect_success 'git log --no-walk=unsorted <commits> leaves list of commits as given' '
brian m. carlsoncb78f4f2019-12-21 19:49:21 +0000230 git log --no-walk=unsorted --oneline $last_three > actual &&
Martin von Zweigbergkca92e592012-08-28 23:15:54 -0700231 test_cmp expect actual
232'
233
Michael J Gruberd5cee0f2009-07-17 16:28:06 +0200234test_expect_success 'git show <commits> leaves list of commits as given' '
brian m. carlsoncb78f4f2019-12-21 19:49:21 +0000235 git show --oneline -s $last_three > actual &&
Michael J Gruberd5cee0f2009-07-17 16:28:06 +0200236 test_cmp expect actual
237'
238
Jeff King0843acf2008-08-25 02:15:05 -0400239test_expect_success 'setup case sensitivity tests' '
240 echo case >one &&
241 test_tick &&
Jonathan Niedera48fcd82010-10-30 20:46:54 -0500242 git add one &&
Jeff King0843acf2008-08-25 02:15:05 -0400243 git commit -a -m Second
244'
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +0100245
Jeff King0843acf2008-08-25 02:15:05 -0400246test_expect_success 'log --grep' '
247 echo second >expect &&
248 git log -1 --pretty="tformat:%s" --grep=sec >actual &&
249 test_cmp expect actual
250'
251
Ævar Arnfjörð Bjarmasondb843762022-10-11 11:48:45 +0200252for noop_opt in --invert-grep --all-match
253do
254 test_expect_success "log $noop_opt without --grep is a NOOP" '
255 git log >expect &&
256 git log $noop_opt >actual &&
257 test_cmp expect actual
258 '
259done
260
Christoph Junghans22dfa8a2015-01-12 18:33:32 -0700261cat > expect << EOF
262second
263initial
264EOF
265test_expect_success 'log --invert-grep --grep' '
Ævar Arnfjörð Bjarmason9e3cbc52017-05-20 21:42:08 +0000266 # Fixed
267 git -c grep.patternType=fixed log --pretty="tformat:%s" --invert-grep --grep=th --grep=Sec >actual &&
268 test_cmp expect actual &&
269
270 # POSIX basic
271 git -c grep.patternType=basic log --pretty="tformat:%s" --invert-grep --grep=t[h] --grep=S[e]c >actual &&
272 test_cmp expect actual &&
273
274 # POSIX extended
René Scharfee6a9bc02021-12-17 17:48:52 +0100275 git -c grep.patternType=extended log --pretty="tformat:%s" --invert-grep --grep=t[h] --grep=S[e]c >actual &&
Ævar Arnfjörð Bjarmason9e3cbc52017-05-20 21:42:08 +0000276 test_cmp expect actual &&
277
278 # PCRE
279 if test_have_prereq PCRE
280 then
281 git -c grep.patternType=perl log --pretty="tformat:%s" --invert-grep --grep=t[h] --grep=S[e]c >actual &&
282 test_cmp expect actual
283 fi
Christoph Junghans22dfa8a2015-01-12 18:33:32 -0700284'
285
286test_expect_success 'log --invert-grep --grep -i' '
287 echo initial >expect &&
Ævar Arnfjörð Bjarmason9e3cbc52017-05-20 21:42:08 +0000288
289 # Fixed
290 git -c grep.patternType=fixed log --pretty="tformat:%s" --invert-grep -i --grep=th --grep=Sec >actual &&
291 test_cmp expect actual &&
292
293 # POSIX basic
294 git -c grep.patternType=basic log --pretty="tformat:%s" --invert-grep -i --grep=t[h] --grep=S[e]c >actual &&
295 test_cmp expect actual &&
296
297 # POSIX extended
298 git -c grep.patternType=extended log --pretty="tformat:%s" --invert-grep -i --grep=t[h] --grep=S[e]c >actual &&
299 test_cmp expect actual &&
300
301 # PCRE
302 if test_have_prereq PCRE
303 then
304 git -c grep.patternType=perl log --pretty="tformat:%s" --invert-grep -i --grep=t[h] --grep=S[e]c >actual &&
305 test_cmp expect actual
306 fi
Christoph Junghans22dfa8a2015-01-12 18:33:32 -0700307'
308
Matthieu Moy7d7b86f2010-08-05 10:22:55 +0200309test_expect_success 'log --grep option parsing' '
310 echo second >expect &&
311 git log -1 --pretty="tformat:%s" --grep sec >actual &&
312 test_cmp expect actual &&
313 test_must_fail git log -1 --pretty="tformat:%s" --grep
314'
315
Jeff King0843acf2008-08-25 02:15:05 -0400316test_expect_success 'log -i --grep' '
317 echo Second >expect &&
318 git log -1 --pretty="tformat:%s" -i --grep=sec >actual &&
319 test_cmp expect actual
320'
321
322test_expect_success 'log --grep -i' '
323 echo Second >expect &&
Ævar Arnfjörð Bjarmason9e3cbc52017-05-20 21:42:08 +0000324
325 # Fixed
Jeff King0843acf2008-08-25 02:15:05 -0400326 git log -1 --pretty="tformat:%s" --grep=sec -i >actual &&
Ævar Arnfjörð Bjarmason9e3cbc52017-05-20 21:42:08 +0000327 test_cmp expect actual &&
328
329 # POSIX basic
330 git -c grep.patternType=basic log -1 --pretty="tformat:%s" --grep=s[e]c -i >actual &&
331 test_cmp expect actual &&
332
333 # POSIX extended
334 git -c grep.patternType=extended log -1 --pretty="tformat:%s" --grep=s[e]c -i >actual &&
335 test_cmp expect actual &&
336
337 # PCRE
338 if test_have_prereq PCRE
339 then
340 git -c grep.patternType=perl log -1 --pretty="tformat:%s" --grep=s[e]c -i >actual &&
341 test_cmp expect actual
342 fi
Jeff King0843acf2008-08-25 02:15:05 -0400343'
Arjen Laarhoven0faf2da2007-12-25 12:06:47 +0100344
Junio C Hamano34a4ae52012-10-03 14:50:51 -0700345test_expect_success 'log -F -E --grep=<ere> uses ere' '
346 echo second >expect &&
Ævar Arnfjörð Bjarmason9df46762017-05-20 21:42:07 +0000347 # basic would need \(s\) to do the same
348 git log -1 --pretty="tformat:%s" -F -E --grep="(s).c.nd" >actual &&
349 test_cmp expect actual
350'
351
352test_expect_success PCRE 'log -F -E --perl-regexp --grep=<pcre> uses PCRE' '
353 test_when_finished "rm -rf num_commits" &&
354 git init num_commits &&
355 (
356 cd num_commits &&
357 test_commit 1d &&
358 test_commit 2e
359 ) &&
360
361 # In PCRE \d in [\d] is like saying "0-9", and matches the 2
362 # in 2e...
363 echo 2e >expect &&
364 git -C num_commits log -1 --pretty="tformat:%s" -F -E --perl-regexp --grep="[\d]" >actual &&
365 test_cmp expect actual &&
366
367 # ...in POSIX basic and extended it is the same as [d],
368 # i.e. "d", which matches 1d, but does not match 2e.
369 echo 1d >expect &&
370 git -C num_commits log -1 --pretty="tformat:%s" -F -E --grep="[\d]" >actual &&
Junio C Hamano34a4ae52012-10-03 14:50:51 -0700371 test_cmp expect actual
372'
373
Junio C Hamano84655412016-07-22 11:43:14 -0700374test_expect_success 'log with grep.patternType configuration' '
Junio C Hamano84655412016-07-22 11:43:14 -0700375 git -c grep.patterntype=fixed \
376 log -1 --pretty=tformat:%s --grep=s.c.nd >actual &&
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +0000377 test_must_be_empty actual
Junio C Hamano84655412016-07-22 11:43:14 -0700378'
379
380test_expect_success 'log with grep.patternType configuration and command line' '
381 echo second >expect &&
382 git -c grep.patterntype=fixed \
383 log -1 --pretty=tformat:%s --basic-regexp --grep=s.c.nd >actual &&
384 test_cmp expect actual
385'
386
Ævar Arnfjörð Bjarmasondfe1a172019-05-13 20:32:42 +0200387test_expect_success !FAIL_PREREQS 'log with various grep.patternType configurations & command-lines' '
Ævar Arnfjörð Bjarmason9df46762017-05-20 21:42:07 +0000388 git init pattern-type &&
389 (
390 cd pattern-type &&
391 test_commit 1 file A &&
392
393 # The tagname is overridden here because creating a
394 # tag called "(1|2)" as test_commit would otherwise
395 # implicitly do would fail on e.g. MINGW.
396 test_commit "(1|2)" file B 2 &&
397
398 echo "(1|2)" >expect.fixed &&
399 cp expect.fixed expect.basic &&
400 cp expect.fixed expect.extended &&
401 cp expect.fixed expect.perl &&
402
403 # A strcmp-like match with fixed.
404 git -c grep.patternType=fixed log --pretty=tformat:%s \
405 --grep="(1|2)" >actual.fixed &&
406
407 # POSIX basic matches (, | and ) literally.
408 git -c grep.patternType=basic log --pretty=tformat:%s \
409 --grep="(.|.)" >actual.basic &&
410
411 # POSIX extended needs to have | escaped to match it
412 # literally, whereas under basic this is the same as
413 # (|2), i.e. it would also match "1". This test checks
414 # for extended by asserting that it is not matching
415 # what basic would match.
416 git -c grep.patternType=extended log --pretty=tformat:%s \
417 --grep="\|2" >actual.extended &&
418 if test_have_prereq PCRE
419 then
420 # Only PCRE would match [\d]\| with only
421 # "(1|2)" due to [\d]. POSIX basic would match
422 # both it and "1" since similarly to the
423 # extended match above it is the same as
424 # \([\d]\|\). POSIX extended would
425 # match neither.
426 git -c grep.patternType=perl log --pretty=tformat:%s \
427 --grep="[\d]\|" >actual.perl &&
428 test_cmp expect.perl actual.perl
429 fi &&
430 test_cmp expect.fixed actual.fixed &&
431 test_cmp expect.basic actual.basic &&
432 test_cmp expect.extended actual.extended &&
433
434 git log --pretty=tformat:%s -F \
435 --grep="(1|2)" >actual.fixed.short-arg &&
436 git log --pretty=tformat:%s -E \
437 --grep="\|2" >actual.extended.short-arg &&
Ævar Arnfjörð Bjarmason7531a2d2017-05-25 20:05:24 +0000438 if test_have_prereq PCRE
439 then
440 git log --pretty=tformat:%s -P \
441 --grep="[\d]\|" >actual.perl.short-arg
442 else
443 test_must_fail git log -P \
444 --grep="[\d]\|"
445 fi &&
Ævar Arnfjörð Bjarmason9df46762017-05-20 21:42:07 +0000446 test_cmp expect.fixed actual.fixed.short-arg &&
447 test_cmp expect.extended actual.extended.short-arg &&
Ævar Arnfjörð Bjarmason7531a2d2017-05-25 20:05:24 +0000448 if test_have_prereq PCRE
449 then
450 test_cmp expect.perl actual.perl.short-arg
451 fi &&
Ævar Arnfjörð Bjarmason9df46762017-05-20 21:42:07 +0000452
453 git log --pretty=tformat:%s --fixed-strings \
454 --grep="(1|2)" >actual.fixed.long-arg &&
455 git log --pretty=tformat:%s --basic-regexp \
456 --grep="(.|.)" >actual.basic.long-arg &&
457 git log --pretty=tformat:%s --extended-regexp \
458 --grep="\|2" >actual.extended.long-arg &&
459 if test_have_prereq PCRE
460 then
461 git log --pretty=tformat:%s --perl-regexp \
462 --grep="[\d]\|" >actual.perl.long-arg &&
463 test_cmp expect.perl actual.perl.long-arg
Ævar Arnfjörð Bjarmason9001c192017-05-20 21:42:09 +0000464 else
465 test_must_fail git log --perl-regexp \
466 --grep="[\d]\|"
Ævar Arnfjörð Bjarmason9df46762017-05-20 21:42:07 +0000467 fi &&
468 test_cmp expect.fixed actual.fixed.long-arg &&
469 test_cmp expect.basic actual.basic.long-arg &&
470 test_cmp expect.extended actual.extended.long-arg
471 )
472'
473
Ævar Arnfjörð Bjarmasonff37a602022-02-16 01:00:31 +0100474for cmd in show whatchanged reflog format-patch
475do
476 case "$cmd" in
477 format-patch) myarg="HEAD~.." ;;
478 *) myarg= ;;
479 esac
480
481 test_expect_success "$cmd: understands grep.patternType, like 'log'" '
482 git init "pattern-type-$cmd" &&
483 (
484 cd "pattern-type-$cmd" &&
485 test_commit 1 file A &&
486 test_commit "(1|2)" file B 2 &&
487
488 git -c grep.patternType=fixed $cmd --grep="..." $myarg >actual &&
489 test_must_be_empty actual &&
490
491 git -c grep.patternType=basic $cmd --grep="..." $myarg >actual &&
492 test_file_not_empty actual
493 )
494 '
495done
Ævar Arnfjörð Bjarmasonff37a602022-02-16 01:00:31 +0100496
Hamza Mahfooz6a5c3372021-10-07 16:31:47 -0400497test_expect_success 'log --author' '
498 cat >expect <<-\EOF &&
499 Author: <BOLD;RED>A U<RESET> Thor <author@example.com>
500 EOF
501 git log -1 --color=always --author="A U" >log &&
502 grep Author log >actual.raw &&
503 test_decode_color <actual.raw >actual &&
504 test_cmp expect actual
505'
506
507test_expect_success 'log --committer' '
508 cat >expect <<-\EOF &&
509 Commit: C O Mitter <committer@<BOLD;RED>example<RESET>.com>
510 EOF
511 git log -1 --color=always --pretty=fuller --committer="example" >log &&
512 grep "Commit:" log >actual.raw &&
513 test_decode_color <actual.raw >actual &&
514 test_cmp expect actual
515'
516
517test_expect_success 'log -i --grep with color' '
518 cat >expect <<-\EOF &&
519 <BOLD;RED>Sec<RESET>ond
520 <BOLD;RED>sec<RESET>ond
521 EOF
522 git log --color=always -i --grep=^sec >log &&
523 grep -i sec log >actual.raw &&
524 test_decode_color <actual.raw >actual &&
525 test_cmp expect actual
526'
527
528test_expect_success '-c color.grep.selected log --grep' '
529 cat >expect <<-\EOF &&
530 <GREEN>th<RESET><BOLD;RED>ir<RESET><GREEN>d<RESET>
531 EOF
532 git -c color.grep.selected="green" log --color=always --grep=ir >log &&
533 grep ir log >actual.raw &&
534 test_decode_color <actual.raw >actual &&
535 test_cmp expect actual
536'
537
538test_expect_success '-c color.grep.matchSelected log --grep' '
539 cat >expect <<-\EOF &&
540 <BLUE>i<RESET>n<BLUE>i<RESET>t<BLUE>i<RESET>al
541 EOF
542 git -c color.grep.matchSelected="blue" log --color=always --grep=i >log &&
543 grep al log >actual.raw &&
544 test_decode_color <actual.raw >actual &&
545 test_cmp expect actual
546'
547
Thomas Rast289e1622009-02-19 12:13:38 +0100548cat > expect <<EOF
549* Second
550* sixth
551* fifth
552* fourth
553* third
554* second
555* initial
556EOF
557
558test_expect_success 'simple log --graph' '
Abhishek Kumar989eea92020-02-24 19:08:13 +0530559 test_cmp_graph
Thomas Rast289e1622009-02-19 12:13:38 +0100560'
561
Jacob Keller660e1132016-08-31 16:27:20 -0700562cat > expect <<EOF
563123 * Second
564123 * sixth
565123 * fifth
566123 * fourth
567123 * third
568123 * second
569123 * initial
570EOF
571
572test_expect_success 'simple log --graph --line-prefix="123 "' '
Abhishek Kumar989eea92020-02-24 19:08:13 +0530573 test_cmp_graph --line-prefix="123 "
Jacob Keller660e1132016-08-31 16:27:20 -0700574'
575
Thomas Rast289e1622009-02-19 12:13:38 +0100576test_expect_success 'set up merge history' '
577 git checkout -b side HEAD~4 &&
578 test_commit side-1 1 1 &&
579 test_commit side-2 2 2 &&
Johannes Schindelin8f378542020-11-18 23:44:27 +0000580 git checkout main &&
Thomas Rast289e1622009-02-19 12:13:38 +0100581 git merge side
582'
583
584cat > expect <<\EOF
Junio C Hamano21531922020-07-30 10:06:42 -0700585* Merge branch 'side'
Thomas Rast289e1622009-02-19 12:13:38 +0100586|\
587| * side-2
588| * side-1
589* | Second
590* | sixth
591* | fifth
592* | fourth
593|/
594* third
595* second
596* initial
597EOF
598
599test_expect_success 'log --graph with merge' '
Abhishek Kumar989eea92020-02-24 19:08:13 +0530600 test_cmp_graph --date-order
Thomas Rast289e1622009-02-19 12:13:38 +0100601'
602
Jacob Keller660e1132016-08-31 16:27:20 -0700603cat > expect <<\EOF
Junio C Hamano21531922020-07-30 10:06:42 -0700604| | | * Merge branch 'side'
Jacob Keller660e1132016-08-31 16:27:20 -0700605| | | |\
606| | | | * side-2
607| | | | * side-1
608| | | * | Second
609| | | * | sixth
610| | | * | fifth
611| | | * | fourth
612| | | |/
613| | | * third
614| | | * second
615| | | * initial
616EOF
617
618test_expect_success 'log --graph --line-prefix="| | | " with merge' '
Abhishek Kumar989eea92020-02-24 19:08:13 +0530619 test_cmp_graph --line-prefix="| | | " --date-order
Jacob Keller660e1132016-08-31 16:27:20 -0700620'
621
Nguyễn Thái Ngọc Duy73c727d2017-01-19 18:41:23 +0700622cat > expect.colors <<\EOF
Junio C Hamano21531922020-07-30 10:06:42 -0700623* Merge branch 'side'
Nguyễn Thái Ngọc Duy73c727d2017-01-19 18:41:23 +0700624<BLUE>|<RESET><CYAN>\<RESET>
625<BLUE>|<RESET> * side-2
626<BLUE>|<RESET> * side-1
627* <CYAN>|<RESET> Second
628* <CYAN>|<RESET> sixth
629* <CYAN>|<RESET> fifth
630* <CYAN>|<RESET> fourth
631<CYAN>|<RESET><CYAN>/<RESET>
632* third
633* second
634* initial
635EOF
636
637test_expect_success 'log --graph with merge with log.graphColors' '
Jeff King55cccf42017-02-01 01:21:29 +0100638 test_config log.graphColors " blue,invalid-color, cyan, red , " &&
Abhishek Kumarffe00552020-02-24 19:08:14 +0530639 lib_test_cmp_colored_graph --date-order --format=%s
Nguyễn Thái Ngọc Duy73c727d2017-01-19 18:41:23 +0700640'
641
Michał Kiedrowicz656197a2009-07-25 01:45:00 +0200642test_expect_success 'log --raw --graph -m with merge' '
Johannes Schindelin8f378542020-11-18 23:44:27 +0000643 git log --raw --graph --oneline -m main | head -n 500 >actual &&
Michał Kiedrowicz656197a2009-07-25 01:45:00 +0200644 grep "initial" actual
645'
646
647test_expect_success 'diff-tree --graph' '
Johannes Schindelin8f378542020-11-18 23:44:27 +0000648 git diff-tree --graph main^ | head -n 500 >actual &&
Michał Kiedrowicz656197a2009-07-25 01:45:00 +0200649 grep "one" actual
650'
651
Thomas Rast289e1622009-02-19 12:13:38 +0100652cat > expect <<\EOF
Johannes Schindelin8f378542020-11-18 23:44:27 +0000653* commit main
Thomas Rast289e1622009-02-19 12:13:38 +0100654|\ Merge: A B
655| | Author: A U Thor <author@example.com>
656| |
Junio C Hamano21531922020-07-30 10:06:42 -0700657| | Merge branch 'side'
Thomas Rast289e1622009-02-19 12:13:38 +0100658| |
Junio C Hamanoef1e7402017-03-29 16:39:16 +0200659| * commit tags/side-2
Thomas Rast289e1622009-02-19 12:13:38 +0100660| | Author: A U Thor <author@example.com>
661| |
662| | side-2
663| |
664| * commit tags/side-1
665| | Author: A U Thor <author@example.com>
666| |
667| | side-1
668| |
Johannes Schindelin8f378542020-11-18 23:44:27 +0000669* | commit main~1
Thomas Rast289e1622009-02-19 12:13:38 +0100670| | Author: A U Thor <author@example.com>
671| |
672| | Second
673| |
Johannes Schindelin8f378542020-11-18 23:44:27 +0000674* | commit main~2
Thomas Rast289e1622009-02-19 12:13:38 +0100675| | Author: A U Thor <author@example.com>
676| |
677| | sixth
678| |
Johannes Schindelin8f378542020-11-18 23:44:27 +0000679* | commit main~3
Thomas Rast289e1622009-02-19 12:13:38 +0100680| | Author: A U Thor <author@example.com>
681| |
682| | fifth
683| |
Johannes Schindelin8f378542020-11-18 23:44:27 +0000684* | commit main~4
Thomas Rast289e1622009-02-19 12:13:38 +0100685|/ Author: A U Thor <author@example.com>
686|
687| fourth
688|
689* commit tags/side-1~1
690| Author: A U Thor <author@example.com>
691|
692| third
693|
694* commit tags/side-1~2
695| Author: A U Thor <author@example.com>
696|
697| second
698|
699* commit tags/side-1~3
700 Author: A U Thor <author@example.com>
701
702 initial
703EOF
704
705test_expect_success 'log --graph with full output' '
706 git log --graph --date-order --pretty=short |
John Cai34ae3b72022-01-05 23:29:31 +0000707 git name-rev --name-only --annotate-stdin |
Stephen Boyd9524cf22010-01-26 15:08:31 -0800708 sed "s/Merge:.*/Merge: A B/;s/ *\$//" >actual &&
Thomas Rast289e1622009-02-19 12:13:38 +0100709 test_cmp expect actual
710'
711
712test_expect_success 'set up more tangled history' '
713 git checkout -b tangle HEAD~6 &&
714 test_commit tangle-a tangle-a a &&
Johannes Schindelin8f378542020-11-18 23:44:27 +0000715 git merge main~3 &&
Derrick Stolee748706d2022-08-05 17:58:40 +0000716 git update-ref refs/prefetch/merge HEAD &&
Thomas Rast289e1622009-02-19 12:13:38 +0100717 git merge side~1 &&
Derrick Stolee748706d2022-08-05 17:58:40 +0000718 git update-ref refs/rewritten/merge HEAD &&
Johannes Schindelin8f378542020-11-18 23:44:27 +0000719 git checkout main &&
Allan Caffee7b1d6262009-04-22 17:27:15 -0400720 git merge tangle &&
Derrick Stolee748706d2022-08-05 17:58:40 +0000721 git update-ref refs/hidden/tangle HEAD &&
Allan Caffee7b1d6262009-04-22 17:27:15 -0400722 git checkout -b reach &&
723 test_commit reach &&
Johannes Schindelin8f378542020-11-18 23:44:27 +0000724 git checkout main &&
Allan Caffee7b1d6262009-04-22 17:27:15 -0400725 git checkout -b octopus-a &&
726 test_commit octopus-a &&
Johannes Schindelin8f378542020-11-18 23:44:27 +0000727 git checkout main &&
Allan Caffee7b1d6262009-04-22 17:27:15 -0400728 git checkout -b octopus-b &&
729 test_commit octopus-b &&
Johannes Schindelin8f378542020-11-18 23:44:27 +0000730 git checkout main &&
Allan Caffee7b1d6262009-04-22 17:27:15 -0400731 test_commit seventh &&
Jonathan Niedera48fcd82010-10-30 20:46:54 -0500732 git merge octopus-a octopus-b &&
Allan Caffee7b1d6262009-04-22 17:27:15 -0400733 git merge reach
Thomas Rast289e1622009-02-19 12:13:38 +0100734'
735
736cat > expect <<\EOF
Junio C Hamano21531922020-07-30 10:06:42 -0700737* Merge tag 'reach'
Allan Caffee7b1d6262009-04-22 17:27:15 -0400738|\
739| \
740| \
Junio C Hamano21531922020-07-30 10:06:42 -0700741*-. \ Merge tags 'octopus-a' and 'octopus-b'
Allan Caffee7b1d6262009-04-22 17:27:15 -0400742|\ \ \
743* | | | seventh
744| | * | octopus-b
745| |/ /
746|/| |
747| * | octopus-a
748|/ /
749| * reach
750|/
Junio C Hamano21531922020-07-30 10:06:42 -0700751* Merge branch 'tangle'
Thomas Rast289e1622009-02-19 12:13:38 +0100752|\
753| * Merge branch 'side' (early part) into tangle
754| |\
Johannes Schindelin8f378542020-11-18 23:44:27 +0000755| * \ Merge branch 'main' (early part) into tangle
Thomas Rast289e1622009-02-19 12:13:38 +0100756| |\ \
757| * | | tangle-a
Junio C Hamano21531922020-07-30 10:06:42 -0700758* | | | Merge branch 'side'
Thomas Rast289e1622009-02-19 12:13:38 +0100759|\ \ \ \
760| * | | | side-2
Allan Caffeeeaf158f2009-04-21 08:47:01 -0400761| | |_|/
Thomas Rast289e1622009-02-19 12:13:38 +0100762| |/| |
763| * | | side-1
764* | | | Second
765* | | | sixth
Allan Caffeeeaf158f2009-04-21 08:47:01 -0400766| |_|/
Thomas Rast289e1622009-02-19 12:13:38 +0100767|/| |
768* | | fifth
769* | | fourth
770|/ /
James Coglan479db182019-10-15 23:47:57 +0000771* / third
Thomas Rast289e1622009-02-19 12:13:38 +0100772|/
773* second
774* initial
775EOF
776
Linus Torvalds95110d72009-04-26 12:29:13 -0700777test_expect_success 'log --graph with merge' '
Abhishek Kumar989eea92020-02-24 19:08:13 +0530778 test_cmp_graph --date-order
Thomas Rast289e1622009-02-19 12:13:38 +0100779'
780
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800781test_expect_success 'log.decorate configuration' '
Alex Henrie940a9112017-03-23 23:46:31 -0600782 git log --oneline --no-decorate >expect.none &&
Junio C Hamano4f62c2b2010-04-08 10:17:17 -0700783 git log --oneline --decorate >expect.short &&
784 git log --oneline --decorate=full >expect.full &&
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800785
786 echo "[log] decorate" >>.git/config &&
Junio C Hamano635530a2010-04-06 14:48:55 -0700787 git log --oneline >actual &&
Junio C Hamano4f62c2b2010-04-08 10:17:17 -0700788 test_cmp expect.short actual &&
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800789
Yann Droneaud90e76b72013-03-24 22:06:06 +0100790 test_config log.decorate true &&
Junio C Hamano635530a2010-04-06 14:48:55 -0700791 git log --oneline >actual &&
Junio C Hamano4f62c2b2010-04-08 10:17:17 -0700792 test_cmp expect.short actual &&
793 git log --oneline --decorate=full >actual &&
794 test_cmp expect.full actual &&
795 git log --oneline --decorate=no >actual &&
796 test_cmp expect.none actual &&
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800797
Yann Droneaud90e76b72013-03-24 22:06:06 +0100798 test_config log.decorate no &&
Junio C Hamano635530a2010-04-06 14:48:55 -0700799 git log --oneline >actual &&
Junio C Hamano4f62c2b2010-04-08 10:17:17 -0700800 test_cmp expect.none actual &&
801 git log --oneline --decorate >actual &&
802 test_cmp expect.short actual &&
803 git log --oneline --decorate=full >actual &&
804 test_cmp expect.full actual &&
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800805
Yann Droneaud90e76b72013-03-24 22:06:06 +0100806 test_config log.decorate 1 &&
Jeff Kingb2be2f62010-11-17 12:00:45 -0500807 git log --oneline >actual &&
808 test_cmp expect.short actual &&
809 git log --oneline --decorate=full >actual &&
810 test_cmp expect.full actual &&
811 git log --oneline --decorate=no >actual &&
812 test_cmp expect.none actual &&
813
Yann Droneaud90e76b72013-03-24 22:06:06 +0100814 test_config log.decorate short &&
Junio C Hamano635530a2010-04-06 14:48:55 -0700815 git log --oneline >actual &&
Junio C Hamano4f62c2b2010-04-08 10:17:17 -0700816 test_cmp expect.short actual &&
817 git log --oneline --no-decorate >actual &&
818 test_cmp expect.none actual &&
819 git log --oneline --decorate=full >actual &&
820 test_cmp expect.full actual &&
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800821
Yann Droneaud90e76b72013-03-24 22:06:06 +0100822 test_config log.decorate full &&
Junio C Hamano635530a2010-04-06 14:48:55 -0700823 git log --oneline >actual &&
Junio C Hamano4f62c2b2010-04-08 10:17:17 -0700824 test_cmp expect.full actual &&
825 git log --oneline --no-decorate >actual &&
826 test_cmp expect.none actual &&
827 git log --oneline --decorate >actual &&
Jeff King8fb26872015-03-20 06:06:15 -0400828 test_cmp expect.short actual &&
Junio C Hamano8a3d2032010-02-17 10:20:49 -0800829
Yann Droneaud90e76b72013-03-24 22:06:06 +0100830 test_unconfig log.decorate &&
Jay Soffian0c476952011-05-18 13:56:04 -0400831 git log --pretty=raw >expect.raw &&
Yann Droneaud90e76b72013-03-24 22:06:06 +0100832 test_config log.decorate full &&
Jay Soffian0c476952011-05-18 13:56:04 -0400833 git log --pretty=raw >actual &&
834 test_cmp expect.raw actual
835
836'
837
Ævar Arnfjörð Bjarmason1c7e2392023-03-28 16:04:26 +0200838test_expect_failure 'parse log.excludeDecoration with no value' '
839 cp .git/config .git/config.orig &&
840 test_when_finished mv .git/config.orig .git/config &&
841
842 cat >>.git/config <<-\EOF &&
843 [log]
844 excludeDecoration
845 EOF
846 git log --decorate=short
847'
848
Rafael Ascensão65516f52017-11-21 21:33:41 +0000849test_expect_success 'decorate-refs with glob' '
850 cat >expect.decorate <<-\EOF &&
Junio C Hamano21531922020-07-30 10:06:42 -0700851 Merge-tag-reach
852 Merge-tags-octopus-a-and-octopus-b
Rafael Ascensão65516f52017-11-21 21:33:41 +0000853 seventh
854 octopus-b (octopus-b)
855 octopus-a (octopus-a)
856 reach
857 EOF
Derrick Stoleea6be5e62020-04-16 14:15:49 +0000858 cat >expect.no-decorate <<-\EOF &&
Junio C Hamano21531922020-07-30 10:06:42 -0700859 Merge-tag-reach
860 Merge-tags-octopus-a-and-octopus-b
Derrick Stoleea6be5e62020-04-16 14:15:49 +0000861 seventh
862 octopus-b
863 octopus-a
864 reach
865 EOF
Rafael Ascensão65516f52017-11-21 21:33:41 +0000866 git log -n6 --decorate=short --pretty="tformat:%f%d" \
867 --decorate-refs="heads/octopus*" >actual &&
Derrick Stoleea6be5e62020-04-16 14:15:49 +0000868 test_cmp expect.decorate actual &&
869 git log -n6 --decorate=short --pretty="tformat:%f%d" \
870 --decorate-refs-exclude="heads/octopus*" \
871 --decorate-refs="heads/octopus*" >actual &&
872 test_cmp expect.no-decorate actual &&
873 git -c log.excludeDecoration="heads/octopus*" log \
874 -n6 --decorate=short --pretty="tformat:%f%d" \
875 --decorate-refs="heads/octopus*" >actual &&
Rafael Ascensão65516f52017-11-21 21:33:41 +0000876 test_cmp expect.decorate actual
877'
878
879test_expect_success 'decorate-refs without globs' '
880 cat >expect.decorate <<-\EOF &&
Junio C Hamano21531922020-07-30 10:06:42 -0700881 Merge-tag-reach
882 Merge-tags-octopus-a-and-octopus-b
Rafael Ascensão65516f52017-11-21 21:33:41 +0000883 seventh
884 octopus-b
885 octopus-a
886 reach (tag: reach)
887 EOF
888 git log -n6 --decorate=short --pretty="tformat:%f%d" \
889 --decorate-refs="tags/reach" >actual &&
890 test_cmp expect.decorate actual
891'
892
893test_expect_success 'multiple decorate-refs' '
894 cat >expect.decorate <<-\EOF &&
Junio C Hamano21531922020-07-30 10:06:42 -0700895 Merge-tag-reach
896 Merge-tags-octopus-a-and-octopus-b
Rafael Ascensão65516f52017-11-21 21:33:41 +0000897 seventh
898 octopus-b (octopus-b)
899 octopus-a (octopus-a)
900 reach (tag: reach)
901 EOF
902 git log -n6 --decorate=short --pretty="tformat:%f%d" \
903 --decorate-refs="heads/octopus*" \
904 --decorate-refs="tags/reach" >actual &&
905 test_cmp expect.decorate actual
906'
907
908test_expect_success 'decorate-refs-exclude with glob' '
909 cat >expect.decorate <<-\EOF &&
Johannes Schindelin8f378542020-11-18 23:44:27 +0000910 Merge-tag-reach (HEAD -> main)
Junio C Hamano21531922020-07-30 10:06:42 -0700911 Merge-tags-octopus-a-and-octopus-b
Rafael Ascensão65516f52017-11-21 21:33:41 +0000912 seventh (tag: seventh)
913 octopus-b (tag: octopus-b)
914 octopus-a (tag: octopus-a)
915 reach (tag: reach, reach)
916 EOF
917 git log -n6 --decorate=short --pretty="tformat:%f%d" \
918 --decorate-refs-exclude="heads/octopus*" >actual &&
Derrick Stoleea6be5e62020-04-16 14:15:49 +0000919 test_cmp expect.decorate actual &&
920 git -c log.excludeDecoration="heads/octopus*" log \
921 -n6 --decorate=short --pretty="tformat:%f%d" >actual &&
Rafael Ascensão65516f52017-11-21 21:33:41 +0000922 test_cmp expect.decorate actual
923'
924
925test_expect_success 'decorate-refs-exclude without globs' '
926 cat >expect.decorate <<-\EOF &&
Johannes Schindelin8f378542020-11-18 23:44:27 +0000927 Merge-tag-reach (HEAD -> main)
Junio C Hamano21531922020-07-30 10:06:42 -0700928 Merge-tags-octopus-a-and-octopus-b
Rafael Ascensão65516f52017-11-21 21:33:41 +0000929 seventh (tag: seventh)
930 octopus-b (tag: octopus-b, octopus-b)
931 octopus-a (tag: octopus-a, octopus-a)
932 reach (reach)
933 EOF
934 git log -n6 --decorate=short --pretty="tformat:%f%d" \
935 --decorate-refs-exclude="tags/reach" >actual &&
Derrick Stoleea6be5e62020-04-16 14:15:49 +0000936 test_cmp expect.decorate actual &&
937 git -c log.excludeDecoration="tags/reach" log \
938 -n6 --decorate=short --pretty="tformat:%f%d" >actual &&
Rafael Ascensão65516f52017-11-21 21:33:41 +0000939 test_cmp expect.decorate actual
940'
941
942test_expect_success 'multiple decorate-refs-exclude' '
943 cat >expect.decorate <<-\EOF &&
Johannes Schindelin8f378542020-11-18 23:44:27 +0000944 Merge-tag-reach (HEAD -> main)
Junio C Hamano21531922020-07-30 10:06:42 -0700945 Merge-tags-octopus-a-and-octopus-b
Rafael Ascensão65516f52017-11-21 21:33:41 +0000946 seventh (tag: seventh)
947 octopus-b (tag: octopus-b)
948 octopus-a (tag: octopus-a)
949 reach (reach)
950 EOF
951 git log -n6 --decorate=short --pretty="tformat:%f%d" \
952 --decorate-refs-exclude="heads/octopus*" \
953 --decorate-refs-exclude="tags/reach" >actual &&
Derrick Stoleea6be5e62020-04-16 14:15:49 +0000954 test_cmp expect.decorate actual &&
955 git -c log.excludeDecoration="heads/octopus*" \
956 -c log.excludeDecoration="tags/reach" log \
957 -n6 --decorate=short --pretty="tformat:%f%d" >actual &&
958 test_cmp expect.decorate actual &&
959 git -c log.excludeDecoration="heads/octopus*" log \
960 --decorate-refs-exclude="tags/reach" \
961 -n6 --decorate=short --pretty="tformat:%f%d" >actual &&
Rafael Ascensão65516f52017-11-21 21:33:41 +0000962 test_cmp expect.decorate actual
963'
964
965test_expect_success 'decorate-refs and decorate-refs-exclude' '
Derrick Stoleea6be5e62020-04-16 14:15:49 +0000966 cat >expect.no-decorate <<-\EOF &&
Johannes Schindelin8f378542020-11-18 23:44:27 +0000967 Merge-tag-reach (main)
Junio C Hamano21531922020-07-30 10:06:42 -0700968 Merge-tags-octopus-a-and-octopus-b
Rafael Ascensão65516f52017-11-21 21:33:41 +0000969 seventh
970 octopus-b
971 octopus-a
972 reach (reach)
973 EOF
974 git log -n6 --decorate=short --pretty="tformat:%f%d" \
975 --decorate-refs="heads/*" \
976 --decorate-refs-exclude="heads/oc*" >actual &&
Derrick Stoleea6be5e62020-04-16 14:15:49 +0000977 test_cmp expect.no-decorate actual
978'
979
980test_expect_success 'deocrate-refs and log.excludeDecoration' '
981 cat >expect.decorate <<-\EOF &&
Johannes Schindelin8f378542020-11-18 23:44:27 +0000982 Merge-tag-reach (main)
Junio C Hamano21531922020-07-30 10:06:42 -0700983 Merge-tags-octopus-a-and-octopus-b
Derrick Stoleea6be5e62020-04-16 14:15:49 +0000984 seventh
985 octopus-b (octopus-b)
986 octopus-a (octopus-a)
987 reach (reach)
988 EOF
989 git -c log.excludeDecoration="heads/oc*" log \
990 --decorate-refs="heads/*" \
991 -n6 --decorate=short --pretty="tformat:%f%d" >actual &&
Rafael Ascensão65516f52017-11-21 21:33:41 +0000992 test_cmp expect.decorate actual
993'
994
René Scharfe0cc73802019-09-08 19:58:51 +0200995test_expect_success 'decorate-refs-exclude and simplify-by-decoration' '
René Scharfeb4ecbcf2019-09-08 19:58:41 +0200996 cat >expect.decorate <<-\EOF &&
Johannes Schindelin8f378542020-11-18 23:44:27 +0000997 Merge-tag-reach (HEAD -> main)
René Scharfeb4ecbcf2019-09-08 19:58:41 +0200998 reach (tag: reach, reach)
999 seventh (tag: seventh)
Derrick Stolee748706d2022-08-05 17:58:40 +00001000 Merge-branch-tangle (refs/hidden/tangle)
1001 Merge-branch-side-early-part-into-tangle (refs/rewritten/merge, tangle)
1002 Merge-branch-main-early-part-into-tangle (refs/prefetch/merge)
René Scharfeb4ecbcf2019-09-08 19:58:41 +02001003 EOF
1004 git log -n6 --decorate=short --pretty="tformat:%f%d" \
1005 --decorate-refs-exclude="*octopus*" \
1006 --simplify-by-decoration >actual &&
Derrick Stoleea6be5e62020-04-16 14:15:49 +00001007 test_cmp expect.decorate actual &&
1008 git -c log.excludeDecoration="*octopus*" log \
1009 -n6 --decorate=short --pretty="tformat:%f%d" \
1010 --simplify-by-decoration >actual &&
René Scharfeb4ecbcf2019-09-08 19:58:41 +02001011 test_cmp expect.decorate actual
1012'
1013
Jeff King14b9c2b2021-12-02 00:35:43 -05001014test_expect_success 'decorate-refs with implied decorate from format' '
1015 cat >expect <<-\EOF &&
1016 side-2 (tag: side-2)
1017 side-1
1018 EOF
1019 git log --no-walk --format="%s%d" \
1020 --decorate-refs="*side-2" side-1 side-2 \
1021 >actual &&
1022 test_cmp expect actual
1023'
1024
1025test_expect_success 'implied decorate does not override option' '
1026 cat >expect <<-\EOF &&
1027 side-2 (tag: refs/tags/side-2, refs/heads/side)
1028 side-1 (tag: refs/tags/side-1)
1029 EOF
1030 git log --no-walk --format="%s%d" \
1031 --decorate=full side-1 side-2 \
1032 >actual &&
1033 test_cmp expect actual
1034'
1035
Jeff Kingbe738602021-12-02 00:37:53 -05001036test_expect_success 'decorate-refs and simplify-by-decoration without output' '
1037 cat >expect <<-\EOF &&
1038 side-2
1039 initial
1040 EOF
1041 # Do not just use a --format without %d here; we want to
1042 # make sure that we did not accidentally turn on displaying
1043 # the decorations, too. And that requires one of the regular
1044 # formats.
1045 git log --decorate-refs="*side-2" --oneline \
1046 --simplify-by-decoration >actual.raw &&
1047 sed "s/^[0-9a-f]* //" <actual.raw >actual &&
1048 test_cmp expect actual
1049'
1050
Derrick Stoleeb877e612022-08-05 17:58:33 +00001051test_expect_success 'decorate-refs-exclude HEAD' '
1052 git log --decorate=full --oneline \
1053 --decorate-refs-exclude="HEAD" >actual &&
1054 ! grep HEAD actual
1055'
1056
Derrick Stolee92156292022-08-05 17:58:39 +00001057test_expect_success 'decorate-refs focus from default' '
1058 git log --decorate=full --oneline \
1059 --decorate-refs="refs/heads" >actual &&
1060 ! grep HEAD actual
1061'
1062
Derrick Stolee748706d2022-08-05 17:58:40 +00001063test_expect_success '--clear-decorations overrides defaults' '
1064 cat >expect.default <<-\EOF &&
1065 Merge-tag-reach (HEAD -> refs/heads/main)
1066 Merge-tags-octopus-a-and-octopus-b
1067 seventh (tag: refs/tags/seventh)
1068 octopus-b (tag: refs/tags/octopus-b, refs/heads/octopus-b)
1069 octopus-a (tag: refs/tags/octopus-a, refs/heads/octopus-a)
1070 reach (tag: refs/tags/reach, refs/heads/reach)
1071 Merge-branch-tangle
1072 Merge-branch-side-early-part-into-tangle (refs/heads/tangle)
1073 Merge-branch-main-early-part-into-tangle
1074 tangle-a (tag: refs/tags/tangle-a)
1075 Merge-branch-side
1076 side-2 (tag: refs/tags/side-2, refs/heads/side)
1077 side-1 (tag: refs/tags/side-1)
1078 Second
1079 sixth
1080 fifth
1081 fourth
1082 third
1083 second
1084 initial
1085 EOF
1086 git log --decorate=full --pretty="tformat:%f%d" >actual &&
1087 test_cmp expect.default actual &&
1088
1089 cat >expect.all <<-\EOF &&
1090 Merge-tag-reach (HEAD -> refs/heads/main)
1091 Merge-tags-octopus-a-and-octopus-b
1092 seventh (tag: refs/tags/seventh)
1093 octopus-b (tag: refs/tags/octopus-b, refs/heads/octopus-b)
1094 octopus-a (tag: refs/tags/octopus-a, refs/heads/octopus-a)
1095 reach (tag: refs/tags/reach, refs/heads/reach)
1096 Merge-branch-tangle (refs/hidden/tangle)
1097 Merge-branch-side-early-part-into-tangle (refs/rewritten/merge, refs/heads/tangle)
1098 Merge-branch-main-early-part-into-tangle (refs/prefetch/merge)
1099 tangle-a (tag: refs/tags/tangle-a)
1100 Merge-branch-side
1101 side-2 (tag: refs/tags/side-2, refs/heads/side)
1102 side-1 (tag: refs/tags/side-1)
1103 Second
1104 sixth
1105 fifth
1106 fourth
1107 third
1108 second
1109 initial
1110 EOF
1111 git log --decorate=full --pretty="tformat:%f%d" \
1112 --clear-decorations >actual &&
Derrick Stolee3e103ed2022-08-05 17:58:41 +00001113 test_cmp expect.all actual &&
1114 git -c log.initialDecorationSet=all log \
1115 --decorate=full --pretty="tformat:%f%d" >actual &&
Derrick Stolee748706d2022-08-05 17:58:40 +00001116 test_cmp expect.all actual
1117'
1118
1119test_expect_success '--clear-decorations clears previous exclusions' '
1120 cat >expect.all <<-\EOF &&
1121 Merge-tag-reach (HEAD -> refs/heads/main)
1122 reach (tag: refs/tags/reach, refs/heads/reach)
1123 Merge-tags-octopus-a-and-octopus-b
1124 octopus-b (tag: refs/tags/octopus-b, refs/heads/octopus-b)
1125 octopus-a (tag: refs/tags/octopus-a, refs/heads/octopus-a)
1126 seventh (tag: refs/tags/seventh)
1127 Merge-branch-tangle (refs/hidden/tangle)
1128 Merge-branch-side-early-part-into-tangle (refs/rewritten/merge, refs/heads/tangle)
1129 Merge-branch-main-early-part-into-tangle (refs/prefetch/merge)
1130 tangle-a (tag: refs/tags/tangle-a)
1131 side-2 (tag: refs/tags/side-2, refs/heads/side)
1132 side-1 (tag: refs/tags/side-1)
1133 initial
1134 EOF
1135
1136 git log --decorate=full --pretty="tformat:%f%d" \
1137 --simplify-by-decoration \
1138 --decorate-refs-exclude="heads/octopus*" \
1139 --decorate-refs="heads" \
1140 --clear-decorations >actual &&
1141 test_cmp expect.all actual &&
1142
1143 cat >expect.filtered <<-\EOF &&
1144 Merge-tags-octopus-a-and-octopus-b
1145 octopus-b (refs/heads/octopus-b)
1146 octopus-a (refs/heads/octopus-a)
1147 initial
1148 EOF
1149
1150 git log --decorate=full --pretty="tformat:%f%d" \
1151 --simplify-by-decoration \
1152 --decorate-refs-exclude="heads/octopus" \
1153 --decorate-refs="heads" \
1154 --clear-decorations \
1155 --decorate-refs-exclude="tags/" \
1156 --decorate-refs="heads/octopus*" >actual &&
1157 test_cmp expect.filtered actual
1158'
1159
brian m. carlsonc74271a2017-05-14 18:00:58 +00001160test_expect_success 'log.decorate config parsing' '
1161 git log --oneline --decorate=full >expect.full &&
1162 git log --oneline --decorate=short >expect.short &&
1163
1164 test_config log.decorate full &&
1165 test_config log.mailmap true &&
1166 git log --oneline >actual &&
1167 test_cmp expect.full actual &&
1168 git log --oneline --decorate=short >actual &&
1169 test_cmp expect.short actual
1170'
1171
Alex Henrie940a9112017-03-23 23:46:31 -06001172test_expect_success TTY 'log output on a TTY' '
Jeff Kinge4337492017-10-03 09:39:34 -04001173 git log --color --oneline --decorate >expect.short &&
Alex Henrie940a9112017-03-23 23:46:31 -06001174
1175 test_terminal git log --oneline >actual &&
1176 test_cmp expect.short actual
1177'
1178
Jay Soffian0c476952011-05-18 13:56:04 -04001179test_expect_success 'reflog is expected format' '
Jay Soffian0c476952011-05-18 13:56:04 -04001180 git log -g --abbrev-commit --pretty=oneline >expect &&
1181 git reflog >actual &&
1182 test_cmp expect actual
1183'
1184
1185test_expect_success 'whatchanged is expected format' '
1186 git log --no-merges --raw >expect &&
1187 git whatchanged >actual &&
1188 test_cmp expect actual
1189'
1190
1191test_expect_success 'log.abbrevCommit configuration' '
Jay Soffian0c476952011-05-18 13:56:04 -04001192 git log --abbrev-commit >expect.log.abbrev &&
1193 git log --no-abbrev-commit >expect.log.full &&
1194 git log --pretty=raw >expect.log.raw &&
1195 git reflog --abbrev-commit >expect.reflog.abbrev &&
1196 git reflog --no-abbrev-commit >expect.reflog.full &&
1197 git whatchanged --abbrev-commit >expect.whatchanged.abbrev &&
1198 git whatchanged --no-abbrev-commit >expect.whatchanged.full &&
1199
Yann Droneaud90e76b72013-03-24 22:06:06 +01001200 test_config log.abbrevCommit true &&
Jay Soffian0c476952011-05-18 13:56:04 -04001201
1202 git log >actual &&
1203 test_cmp expect.log.abbrev actual &&
1204 git log --no-abbrev-commit >actual &&
1205 test_cmp expect.log.full actual &&
1206
1207 git log --pretty=raw >actual &&
1208 test_cmp expect.log.raw actual &&
1209
1210 git reflog >actual &&
1211 test_cmp expect.reflog.abbrev actual &&
1212 git reflog --no-abbrev-commit >actual &&
1213 test_cmp expect.reflog.full actual &&
1214
1215 git whatchanged >actual &&
1216 test_cmp expect.whatchanged.abbrev actual &&
1217 git whatchanged --no-abbrev-commit >actual &&
1218 test_cmp expect.whatchanged.full actual
Junio C Hamano8a3d2032010-02-17 10:20:49 -08001219'
1220
Ævar Arnfjörð Bjarmason65113122010-08-15 10:16:25 +00001221test_expect_success 'show added path under "--follow -M"' '
1222 # This tests for a regression introduced in v1.7.2-rc0~103^2~2
1223 test_create_repo regression &&
1224 (
1225 cd regression &&
1226 test_commit needs-another-commit &&
1227 test_commit foo.bar &&
1228 git log -M --follow -p foo.bar.t &&
1229 git log -M --follow --stat foo.bar.t &&
1230 git log -M --follow --name-only foo.bar.t
1231 )
1232'
Brandon Caseyc65233f2008-07-22 16:23:31 -05001233
Clemens Buchacher46ec5102013-05-28 00:49:57 +02001234test_expect_success 'git log -c --follow' '
1235 test_create_repo follow-c &&
1236 (
1237 cd follow-c &&
1238 test_commit initial file original &&
1239 git rm file &&
1240 test_commit rename file2 original &&
1241 git reset --hard initial &&
1242 test_commit modify file foo &&
1243 git merge -m merge rename &&
1244 git log -c --follow file2
1245 )
1246'
1247
Lucian Postone2c59662012-03-20 01:05:34 -07001248cat >expect <<\EOF
1249* commit COMMIT_OBJECT_NAME
1250|\ Merge: MERGE_PARENTS
1251| | Author: A U Thor <author@example.com>
1252| |
1253| | Merge HEADS DESCRIPTION
1254| |
1255| * commit COMMIT_OBJECT_NAME
1256| | Author: A U Thor <author@example.com>
1257| |
1258| | reach
1259| | ---
Zbigniew Jędrzejewski-Szmekdc801e72012-04-30 22:38:58 +02001260| | reach.t | 1 +
Lucian Postone2c59662012-03-20 01:05:34 -07001261| | 1 file changed, 1 insertion(+)
1262| |
1263| | diff --git a/reach.t b/reach.t
1264| | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001265| | index BEFORE..AFTER
Lucian Postone2c59662012-03-20 01:05:34 -07001266| | --- /dev/null
1267| | +++ b/reach.t
1268| | @@ -0,0 +1 @@
1269| | +reach
1270| |
1271| \
1272*-. \ commit COMMIT_OBJECT_NAME
1273|\ \ \ Merge: MERGE_PARENTS
1274| | | | Author: A U Thor <author@example.com>
1275| | | |
1276| | | | Merge HEADS DESCRIPTION
1277| | | |
1278| | * | commit COMMIT_OBJECT_NAME
1279| | |/ Author: A U Thor <author@example.com>
1280| | |
1281| | | octopus-b
1282| | | ---
Zbigniew Jędrzejewski-Szmekdc801e72012-04-30 22:38:58 +02001283| | | octopus-b.t | 1 +
Lucian Postone2c59662012-03-20 01:05:34 -07001284| | | 1 file changed, 1 insertion(+)
1285| | |
1286| | | diff --git a/octopus-b.t b/octopus-b.t
1287| | | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001288| | | index BEFORE..AFTER
Lucian Postone2c59662012-03-20 01:05:34 -07001289| | | --- /dev/null
1290| | | +++ b/octopus-b.t
1291| | | @@ -0,0 +1 @@
1292| | | +octopus-b
1293| | |
1294| * | commit COMMIT_OBJECT_NAME
1295| |/ Author: A U Thor <author@example.com>
1296| |
1297| | octopus-a
1298| | ---
Zbigniew Jędrzejewski-Szmekdc801e72012-04-30 22:38:58 +02001299| | octopus-a.t | 1 +
Lucian Postone2c59662012-03-20 01:05:34 -07001300| | 1 file changed, 1 insertion(+)
1301| |
1302| | diff --git a/octopus-a.t b/octopus-a.t
1303| | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001304| | index BEFORE..AFTER
Lucian Postone2c59662012-03-20 01:05:34 -07001305| | --- /dev/null
1306| | +++ b/octopus-a.t
1307| | @@ -0,0 +1 @@
1308| | +octopus-a
1309| |
1310* | commit COMMIT_OBJECT_NAME
1311|/ Author: A U Thor <author@example.com>
1312|
1313| seventh
1314| ---
Zbigniew Jędrzejewski-Szmekdc801e72012-04-30 22:38:58 +02001315| seventh.t | 1 +
Lucian Postone2c59662012-03-20 01:05:34 -07001316| 1 file changed, 1 insertion(+)
1317|
1318| diff --git a/seventh.t b/seventh.t
1319| new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001320| index BEFORE..AFTER
Lucian Postone2c59662012-03-20 01:05:34 -07001321| --- /dev/null
1322| +++ b/seventh.t
1323| @@ -0,0 +1 @@
1324| +seventh
1325|
1326* commit COMMIT_OBJECT_NAME
1327|\ Merge: MERGE_PARENTS
1328| | Author: A U Thor <author@example.com>
1329| |
Junio C Hamano21531922020-07-30 10:06:42 -07001330| | Merge branch 'tangle'
Lucian Postone2c59662012-03-20 01:05:34 -07001331| |
1332| * commit COMMIT_OBJECT_NAME
1333| |\ Merge: MERGE_PARENTS
1334| | | Author: A U Thor <author@example.com>
1335| | |
1336| | | Merge branch 'side' (early part) into tangle
1337| | |
1338| * | commit COMMIT_OBJECT_NAME
1339| |\ \ Merge: MERGE_PARENTS
1340| | | | Author: A U Thor <author@example.com>
1341| | | |
Johannes Schindelin8f378542020-11-18 23:44:27 +00001342| | | | Merge branch 'main' (early part) into tangle
Lucian Postone2c59662012-03-20 01:05:34 -07001343| | | |
1344| * | | commit COMMIT_OBJECT_NAME
1345| | | | Author: A U Thor <author@example.com>
1346| | | |
1347| | | | tangle-a
1348| | | | ---
Zbigniew Jędrzejewski-Szmekdc801e72012-04-30 22:38:58 +02001349| | | | tangle-a | 1 +
Lucian Postone2c59662012-03-20 01:05:34 -07001350| | | | 1 file changed, 1 insertion(+)
1351| | | |
1352| | | | diff --git a/tangle-a b/tangle-a
1353| | | | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001354| | | | index BEFORE..AFTER
Lucian Postone2c59662012-03-20 01:05:34 -07001355| | | | --- /dev/null
1356| | | | +++ b/tangle-a
1357| | | | @@ -0,0 +1 @@
1358| | | | +a
1359| | | |
1360* | | | commit COMMIT_OBJECT_NAME
1361|\ \ \ \ Merge: MERGE_PARENTS
1362| | | | | Author: A U Thor <author@example.com>
1363| | | | |
Junio C Hamano21531922020-07-30 10:06:42 -07001364| | | | | Merge branch 'side'
Lucian Postone2c59662012-03-20 01:05:34 -07001365| | | | |
1366| * | | | commit COMMIT_OBJECT_NAME
1367| | |_|/ Author: A U Thor <author@example.com>
1368| |/| |
1369| | | | side-2
1370| | | | ---
Zbigniew Jędrzejewski-Szmekdc801e72012-04-30 22:38:58 +02001371| | | | 2 | 1 +
Lucian Postone2c59662012-03-20 01:05:34 -07001372| | | | 1 file changed, 1 insertion(+)
1373| | | |
1374| | | | diff --git a/2 b/2
1375| | | | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001376| | | | index BEFORE..AFTER
Lucian Postone2c59662012-03-20 01:05:34 -07001377| | | | --- /dev/null
1378| | | | +++ b/2
1379| | | | @@ -0,0 +1 @@
1380| | | | +2
1381| | | |
1382| * | | commit COMMIT_OBJECT_NAME
1383| | | | Author: A U Thor <author@example.com>
1384| | | |
1385| | | | side-1
1386| | | | ---
Zbigniew Jędrzejewski-Szmekdc801e72012-04-30 22:38:58 +02001387| | | | 1 | 1 +
Lucian Postone2c59662012-03-20 01:05:34 -07001388| | | | 1 file changed, 1 insertion(+)
1389| | | |
1390| | | | diff --git a/1 b/1
1391| | | | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001392| | | | index BEFORE..AFTER
Lucian Postone2c59662012-03-20 01:05:34 -07001393| | | | --- /dev/null
1394| | | | +++ b/1
1395| | | | @@ -0,0 +1 @@
1396| | | | +1
1397| | | |
1398* | | | commit COMMIT_OBJECT_NAME
1399| | | | Author: A U Thor <author@example.com>
1400| | | |
1401| | | | Second
1402| | | | ---
Zbigniew Jędrzejewski-Szmekdc801e72012-04-30 22:38:58 +02001403| | | | one | 1 +
Lucian Postone2c59662012-03-20 01:05:34 -07001404| | | | 1 file changed, 1 insertion(+)
1405| | | |
1406| | | | diff --git a/one b/one
1407| | | | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001408| | | | index BEFORE..AFTER
Lucian Postone2c59662012-03-20 01:05:34 -07001409| | | | --- /dev/null
1410| | | | +++ b/one
1411| | | | @@ -0,0 +1 @@
1412| | | | +case
1413| | | |
1414* | | | commit COMMIT_OBJECT_NAME
1415| |_|/ Author: A U Thor <author@example.com>
1416|/| |
1417| | | sixth
1418| | | ---
Zbigniew Jędrzejewski-Szmekdc801e72012-04-30 22:38:58 +02001419| | | a/two | 1 -
Lucian Postone2c59662012-03-20 01:05:34 -07001420| | | 1 file changed, 1 deletion(-)
1421| | |
1422| | | diff --git a/a/two b/a/two
1423| | | deleted file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001424| | | index BEFORE..AFTER
Lucian Postone2c59662012-03-20 01:05:34 -07001425| | | --- a/a/two
1426| | | +++ /dev/null
1427| | | @@ -1 +0,0 @@
1428| | | -ni
1429| | |
1430* | | commit COMMIT_OBJECT_NAME
1431| | | Author: A U Thor <author@example.com>
1432| | |
1433| | | fifth
1434| | | ---
Zbigniew Jędrzejewski-Szmekdc801e72012-04-30 22:38:58 +02001435| | | a/two | 1 +
Lucian Postone2c59662012-03-20 01:05:34 -07001436| | | 1 file changed, 1 insertion(+)
1437| | |
1438| | | diff --git a/a/two b/a/two
1439| | | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001440| | | index BEFORE..AFTER
Lucian Postone2c59662012-03-20 01:05:34 -07001441| | | --- /dev/null
1442| | | +++ b/a/two
1443| | | @@ -0,0 +1 @@
1444| | | +ni
1445| | |
1446* | | commit COMMIT_OBJECT_NAME
1447|/ / Author: A U Thor <author@example.com>
1448| |
1449| | fourth
1450| | ---
Zbigniew Jędrzejewski-Szmekdc801e72012-04-30 22:38:58 +02001451| | ein | 1 +
Lucian Postone2c59662012-03-20 01:05:34 -07001452| | 1 file changed, 1 insertion(+)
1453| |
1454| | diff --git a/ein b/ein
1455| | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001456| | index BEFORE..AFTER
Lucian Postone2c59662012-03-20 01:05:34 -07001457| | --- /dev/null
1458| | +++ b/ein
1459| | @@ -0,0 +1 @@
1460| | +ichi
1461| |
1462* | commit COMMIT_OBJECT_NAME
1463|/ Author: A U Thor <author@example.com>
1464|
1465| third
1466| ---
Zbigniew Jędrzejewski-Szmekdc801e72012-04-30 22:38:58 +02001467| ichi | 1 +
1468| one | 1 -
Lucian Postone2c59662012-03-20 01:05:34 -07001469| 2 files changed, 1 insertion(+), 1 deletion(-)
1470|
1471| diff --git a/ichi b/ichi
1472| new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001473| index BEFORE..AFTER
Lucian Postone2c59662012-03-20 01:05:34 -07001474| --- /dev/null
1475| +++ b/ichi
1476| @@ -0,0 +1 @@
1477| +ichi
1478| diff --git a/one b/one
1479| deleted file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001480| index BEFORE..AFTER
Lucian Postone2c59662012-03-20 01:05:34 -07001481| --- a/one
1482| +++ /dev/null
1483| @@ -1 +0,0 @@
1484| -ichi
1485|
1486* commit COMMIT_OBJECT_NAME
1487| Author: A U Thor <author@example.com>
1488|
1489| second
1490| ---
Zbigniew Jędrzejewski-Szmekdc801e72012-04-30 22:38:58 +02001491| one | 2 +-
Lucian Postone2c59662012-03-20 01:05:34 -07001492| 1 file changed, 1 insertion(+), 1 deletion(-)
1493|
1494| diff --git a/one b/one
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001495| index BEFORE..AFTER 100644
Lucian Postone2c59662012-03-20 01:05:34 -07001496| --- a/one
1497| +++ b/one
1498| @@ -1 +1 @@
1499| -one
1500| +ichi
1501|
1502* commit COMMIT_OBJECT_NAME
1503 Author: A U Thor <author@example.com>
1504
1505 initial
1506 ---
Zbigniew Jędrzejewski-Szmekdc801e72012-04-30 22:38:58 +02001507 one | 1 +
Lucian Postone2c59662012-03-20 01:05:34 -07001508 1 file changed, 1 insertion(+)
1509
1510 diff --git a/one b/one
1511 new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001512 index BEFORE..AFTER
Lucian Postone2c59662012-03-20 01:05:34 -07001513 --- /dev/null
1514 +++ b/one
1515 @@ -0,0 +1 @@
1516 +one
1517EOF
1518
Lucian Postone2c59662012-03-20 01:05:34 -07001519test_expect_success 'log --graph with diff and stats' '
Abhishek Kumar989eea92020-02-24 19:08:13 +05301520 lib_test_cmp_short_graph --no-renames --stat -p
Lucian Postone2c59662012-03-20 01:05:34 -07001521'
1522
Jacob Keller660e1132016-08-31 16:27:20 -07001523cat >expect <<\EOF
1524*** * commit COMMIT_OBJECT_NAME
1525*** |\ Merge: MERGE_PARENTS
1526*** | | Author: A U Thor <author@example.com>
1527*** | |
1528*** | | Merge HEADS DESCRIPTION
1529*** | |
1530*** | * commit COMMIT_OBJECT_NAME
1531*** | | Author: A U Thor <author@example.com>
1532*** | |
1533*** | | reach
1534*** | | ---
1535*** | | reach.t | 1 +
1536*** | | 1 file changed, 1 insertion(+)
1537*** | |
1538*** | | diff --git a/reach.t b/reach.t
1539*** | | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001540*** | | index BEFORE..AFTER
Jacob Keller660e1132016-08-31 16:27:20 -07001541*** | | --- /dev/null
1542*** | | +++ b/reach.t
1543*** | | @@ -0,0 +1 @@
1544*** | | +reach
1545*** | |
1546*** | \
1547*** *-. \ commit COMMIT_OBJECT_NAME
1548*** |\ \ \ Merge: MERGE_PARENTS
1549*** | | | | Author: A U Thor <author@example.com>
1550*** | | | |
1551*** | | | | Merge HEADS DESCRIPTION
1552*** | | | |
1553*** | | * | commit COMMIT_OBJECT_NAME
1554*** | | |/ Author: A U Thor <author@example.com>
1555*** | | |
1556*** | | | octopus-b
1557*** | | | ---
1558*** | | | octopus-b.t | 1 +
1559*** | | | 1 file changed, 1 insertion(+)
1560*** | | |
1561*** | | | diff --git a/octopus-b.t b/octopus-b.t
1562*** | | | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001563*** | | | index BEFORE..AFTER
Jacob Keller660e1132016-08-31 16:27:20 -07001564*** | | | --- /dev/null
1565*** | | | +++ b/octopus-b.t
1566*** | | | @@ -0,0 +1 @@
1567*** | | | +octopus-b
1568*** | | |
1569*** | * | commit COMMIT_OBJECT_NAME
1570*** | |/ Author: A U Thor <author@example.com>
1571*** | |
1572*** | | octopus-a
1573*** | | ---
1574*** | | octopus-a.t | 1 +
1575*** | | 1 file changed, 1 insertion(+)
1576*** | |
1577*** | | diff --git a/octopus-a.t b/octopus-a.t
1578*** | | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001579*** | | index BEFORE..AFTER
Jacob Keller660e1132016-08-31 16:27:20 -07001580*** | | --- /dev/null
1581*** | | +++ b/octopus-a.t
1582*** | | @@ -0,0 +1 @@
1583*** | | +octopus-a
1584*** | |
1585*** * | commit COMMIT_OBJECT_NAME
1586*** |/ Author: A U Thor <author@example.com>
1587*** |
1588*** | seventh
1589*** | ---
1590*** | seventh.t | 1 +
1591*** | 1 file changed, 1 insertion(+)
1592*** |
1593*** | diff --git a/seventh.t b/seventh.t
1594*** | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001595*** | index BEFORE..AFTER
Jacob Keller660e1132016-08-31 16:27:20 -07001596*** | --- /dev/null
1597*** | +++ b/seventh.t
1598*** | @@ -0,0 +1 @@
1599*** | +seventh
1600*** |
1601*** * commit COMMIT_OBJECT_NAME
1602*** |\ Merge: MERGE_PARENTS
1603*** | | Author: A U Thor <author@example.com>
1604*** | |
Junio C Hamano21531922020-07-30 10:06:42 -07001605*** | | Merge branch 'tangle'
Jacob Keller660e1132016-08-31 16:27:20 -07001606*** | |
1607*** | * commit COMMIT_OBJECT_NAME
1608*** | |\ Merge: MERGE_PARENTS
1609*** | | | Author: A U Thor <author@example.com>
1610*** | | |
1611*** | | | Merge branch 'side' (early part) into tangle
1612*** | | |
1613*** | * | commit COMMIT_OBJECT_NAME
1614*** | |\ \ Merge: MERGE_PARENTS
1615*** | | | | Author: A U Thor <author@example.com>
1616*** | | | |
Johannes Schindelin8f378542020-11-18 23:44:27 +00001617*** | | | | Merge branch 'main' (early part) into tangle
Jacob Keller660e1132016-08-31 16:27:20 -07001618*** | | | |
1619*** | * | | commit COMMIT_OBJECT_NAME
1620*** | | | | Author: A U Thor <author@example.com>
1621*** | | | |
1622*** | | | | tangle-a
1623*** | | | | ---
1624*** | | | | tangle-a | 1 +
1625*** | | | | 1 file changed, 1 insertion(+)
1626*** | | | |
1627*** | | | | diff --git a/tangle-a b/tangle-a
1628*** | | | | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001629*** | | | | index BEFORE..AFTER
Jacob Keller660e1132016-08-31 16:27:20 -07001630*** | | | | --- /dev/null
1631*** | | | | +++ b/tangle-a
1632*** | | | | @@ -0,0 +1 @@
1633*** | | | | +a
1634*** | | | |
1635*** * | | | commit COMMIT_OBJECT_NAME
1636*** |\ \ \ \ Merge: MERGE_PARENTS
1637*** | | | | | Author: A U Thor <author@example.com>
1638*** | | | | |
Junio C Hamano21531922020-07-30 10:06:42 -07001639*** | | | | | Merge branch 'side'
Jacob Keller660e1132016-08-31 16:27:20 -07001640*** | | | | |
1641*** | * | | | commit COMMIT_OBJECT_NAME
1642*** | | |_|/ Author: A U Thor <author@example.com>
1643*** | |/| |
1644*** | | | | side-2
1645*** | | | | ---
1646*** | | | | 2 | 1 +
1647*** | | | | 1 file changed, 1 insertion(+)
1648*** | | | |
1649*** | | | | diff --git a/2 b/2
1650*** | | | | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001651*** | | | | index BEFORE..AFTER
Jacob Keller660e1132016-08-31 16:27:20 -07001652*** | | | | --- /dev/null
1653*** | | | | +++ b/2
1654*** | | | | @@ -0,0 +1 @@
1655*** | | | | +2
1656*** | | | |
1657*** | * | | commit COMMIT_OBJECT_NAME
1658*** | | | | Author: A U Thor <author@example.com>
1659*** | | | |
1660*** | | | | side-1
1661*** | | | | ---
1662*** | | | | 1 | 1 +
1663*** | | | | 1 file changed, 1 insertion(+)
1664*** | | | |
1665*** | | | | diff --git a/1 b/1
1666*** | | | | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001667*** | | | | index BEFORE..AFTER
Jacob Keller660e1132016-08-31 16:27:20 -07001668*** | | | | --- /dev/null
1669*** | | | | +++ b/1
1670*** | | | | @@ -0,0 +1 @@
1671*** | | | | +1
1672*** | | | |
1673*** * | | | commit COMMIT_OBJECT_NAME
1674*** | | | | Author: A U Thor <author@example.com>
1675*** | | | |
1676*** | | | | Second
1677*** | | | | ---
1678*** | | | | one | 1 +
1679*** | | | | 1 file changed, 1 insertion(+)
1680*** | | | |
1681*** | | | | diff --git a/one b/one
1682*** | | | | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001683*** | | | | index BEFORE..AFTER
Jacob Keller660e1132016-08-31 16:27:20 -07001684*** | | | | --- /dev/null
1685*** | | | | +++ b/one
1686*** | | | | @@ -0,0 +1 @@
1687*** | | | | +case
1688*** | | | |
1689*** * | | | commit COMMIT_OBJECT_NAME
1690*** | |_|/ Author: A U Thor <author@example.com>
1691*** |/| |
1692*** | | | sixth
1693*** | | | ---
1694*** | | | a/two | 1 -
1695*** | | | 1 file changed, 1 deletion(-)
1696*** | | |
1697*** | | | diff --git a/a/two b/a/two
1698*** | | | deleted file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001699*** | | | index BEFORE..AFTER
Jacob Keller660e1132016-08-31 16:27:20 -07001700*** | | | --- a/a/two
1701*** | | | +++ /dev/null
1702*** | | | @@ -1 +0,0 @@
1703*** | | | -ni
1704*** | | |
1705*** * | | commit COMMIT_OBJECT_NAME
1706*** | | | Author: A U Thor <author@example.com>
1707*** | | |
1708*** | | | fifth
1709*** | | | ---
1710*** | | | a/two | 1 +
1711*** | | | 1 file changed, 1 insertion(+)
1712*** | | |
1713*** | | | diff --git a/a/two b/a/two
1714*** | | | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001715*** | | | index BEFORE..AFTER
Jacob Keller660e1132016-08-31 16:27:20 -07001716*** | | | --- /dev/null
1717*** | | | +++ b/a/two
1718*** | | | @@ -0,0 +1 @@
1719*** | | | +ni
1720*** | | |
1721*** * | | commit COMMIT_OBJECT_NAME
1722*** |/ / Author: A U Thor <author@example.com>
1723*** | |
1724*** | | fourth
1725*** | | ---
1726*** | | ein | 1 +
1727*** | | 1 file changed, 1 insertion(+)
1728*** | |
1729*** | | diff --git a/ein b/ein
1730*** | | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001731*** | | index BEFORE..AFTER
Jacob Keller660e1132016-08-31 16:27:20 -07001732*** | | --- /dev/null
1733*** | | +++ b/ein
1734*** | | @@ -0,0 +1 @@
1735*** | | +ichi
1736*** | |
1737*** * | commit COMMIT_OBJECT_NAME
1738*** |/ Author: A U Thor <author@example.com>
1739*** |
1740*** | third
1741*** | ---
1742*** | ichi | 1 +
1743*** | one | 1 -
1744*** | 2 files changed, 1 insertion(+), 1 deletion(-)
1745*** |
1746*** | diff --git a/ichi b/ichi
1747*** | new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001748*** | index BEFORE..AFTER
Jacob Keller660e1132016-08-31 16:27:20 -07001749*** | --- /dev/null
1750*** | +++ b/ichi
1751*** | @@ -0,0 +1 @@
1752*** | +ichi
1753*** | diff --git a/one b/one
1754*** | deleted file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001755*** | index BEFORE..AFTER
Jacob Keller660e1132016-08-31 16:27:20 -07001756*** | --- a/one
1757*** | +++ /dev/null
1758*** | @@ -1 +0,0 @@
1759*** | -ichi
1760*** |
1761*** * commit COMMIT_OBJECT_NAME
1762*** | Author: A U Thor <author@example.com>
1763*** |
1764*** | second
1765*** | ---
1766*** | one | 2 +-
1767*** | 1 file changed, 1 insertion(+), 1 deletion(-)
1768*** |
1769*** | diff --git a/one b/one
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001770*** | index BEFORE..AFTER 100644
Jacob Keller660e1132016-08-31 16:27:20 -07001771*** | --- a/one
1772*** | +++ b/one
1773*** | @@ -1 +1 @@
1774*** | -one
1775*** | +ichi
1776*** |
1777*** * commit COMMIT_OBJECT_NAME
1778*** Author: A U Thor <author@example.com>
1779***
1780*** initial
1781*** ---
1782*** one | 1 +
1783*** 1 file changed, 1 insertion(+)
1784***
1785*** diff --git a/one b/one
1786*** new file mode 100644
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00001787*** index BEFORE..AFTER
Jacob Keller660e1132016-08-31 16:27:20 -07001788*** --- /dev/null
1789*** +++ b/one
1790*** @@ -0,0 +1 @@
1791*** +one
1792EOF
1793
1794test_expect_success 'log --line-prefix="*** " --graph with diff and stats' '
Abhishek Kumar989eea92020-02-24 19:08:13 +05301795 lib_test_cmp_short_graph --line-prefix="*** " --no-renames --stat -p
Jacob Keller660e1132016-08-31 16:27:20 -07001796'
1797
Jeff Kingf5022b52017-02-08 15:31:15 -05001798cat >expect <<-\EOF
1799* reach
1800|
1801| A reach.t
Junio C Hamano21531922020-07-30 10:06:42 -07001802* Merge branch 'tangle'
1803* Merge branch 'side'
Jeff Kingf5022b52017-02-08 15:31:15 -05001804|\
1805| * side-2
1806|
1807| A 2
1808* Second
1809|
1810| A one
1811* sixth
1812
1813 D a/two
1814EOF
1815
1816test_expect_success 'log --graph with --name-status' '
Abhishek Kumar989eea92020-02-24 19:08:13 +05301817 test_cmp_graph --name-status tangle..reach
Jeff Kingf5022b52017-02-08 15:31:15 -05001818'
1819
1820cat >expect <<-\EOF
1821* reach
1822|
1823| reach.t
Junio C Hamano21531922020-07-30 10:06:42 -07001824* Merge branch 'tangle'
1825* Merge branch 'side'
Jeff Kingf5022b52017-02-08 15:31:15 -05001826|\
1827| * side-2
1828|
1829| 2
1830* Second
1831|
1832| one
1833* sixth
1834
1835 a/two
1836EOF
1837
1838test_expect_success 'log --graph with --name-only' '
Abhishek Kumar989eea92020-02-24 19:08:13 +05301839 test_cmp_graph --name-only tangle..reach
Jeff Kingf5022b52017-02-08 15:31:15 -05001840'
1841
Alex Henrie087c7452022-02-11 09:36:25 -07001842test_expect_success '--no-graph countermands --graph' '
1843 git log >expect &&
1844 git log --graph --no-graph >actual &&
1845 test_cmp expect actual
1846'
1847
1848test_expect_success '--graph countermands --no-graph' '
1849 git log --graph >expect &&
1850 git log --no-graph --graph >actual &&
1851 test_cmp expect actual
1852'
1853
1854test_expect_success '--no-graph does not unset --topo-order' '
1855 git log --topo-order >expect &&
1856 git log --topo-order --no-graph >actual &&
1857 test_cmp expect actual
1858'
1859
1860test_expect_success '--no-graph does not unset --parents' '
1861 git log --parents >expect &&
1862 git log --parents --no-graph >actual &&
1863 test_cmp expect actual
1864'
1865
1866test_expect_success '--reverse and --graph conflict' '
1867 test_must_fail git log --reverse --graph 2>stderr &&
1868 test_i18ngrep "cannot be used together" stderr
1869'
1870
1871test_expect_success '--reverse --graph --no-graph works' '
1872 git log --reverse >expect &&
1873 git log --reverse --graph --no-graph >actual &&
1874 test_cmp expect actual
1875'
1876
1877test_expect_success '--show-linear-break and --graph conflict' '
1878 test_must_fail git log --show-linear-break --graph 2>stderr &&
1879 test_i18ngrep "cannot be used together" stderr
1880'
1881
1882test_expect_success '--show-linear-break --graph --no-graph works' '
1883 git log --show-linear-break >expect &&
1884 git log --show-linear-break --graph --no-graph >actual &&
1885 test_cmp expect actual
1886'
1887
1888test_expect_success '--no-walk and --graph conflict' '
1889 test_must_fail git log --no-walk --graph 2>stderr &&
1890 test_i18ngrep "cannot be used together" stderr
1891'
1892
1893test_expect_success '--no-walk --graph --no-graph works' '
1894 git log --no-walk >expect &&
1895 git log --no-walk --graph --no-graph >actual &&
1896 test_cmp expect actual
1897'
1898
1899test_expect_success '--walk-reflogs and --graph conflict' '
1900 test_must_fail git log --walk-reflogs --graph 2>stderr &&
1901 (test_i18ngrep "cannot combine" stderr ||
1902 test_i18ngrep "cannot be used together" stderr)
1903'
1904
1905test_expect_success '--walk-reflogs --graph --no-graph works' '
1906 git log --walk-reflogs >expect &&
1907 git log --walk-reflogs --graph --no-graph >actual &&
1908 test_cmp expect actual
1909'
1910
Junio C Hamano003c84f2011-05-02 13:39:16 -07001911test_expect_success 'dotdot is a parent directory' '
1912 mkdir -p a/b &&
1913 ( echo sixth && echo fifth ) >expect &&
1914 ( cd a/b && git log --format=%s .. ) >actual &&
1915 test_cmp expect actual
1916'
1917
Mehul Jainaefc81a2016-06-24 19:42:34 +05301918test_expect_success GPG 'setup signed branch' '
Johannes Schindelin8f378542020-11-18 23:44:27 +00001919 test_when_finished "git reset --hard && git checkout main" &&
1920 git checkout -b signed main &&
Zoltan Klingercf3983d2014-07-09 12:10:21 +10001921 echo foo >foo &&
1922 git add foo &&
Mehul Jainaefc81a2016-06-24 19:42:34 +05301923 git commit -S -m signed_commit
1924'
1925
Hans Jerry Illikainen67a6ea62019-11-22 20:23:12 +00001926test_expect_success GPG 'setup signed branch with subkey' '
Johannes Schindelin8f378542020-11-18 23:44:27 +00001927 test_when_finished "git reset --hard && git checkout main" &&
1928 git checkout -b signed-subkey main &&
Hans Jerry Illikainen67a6ea62019-11-22 20:23:12 +00001929 echo foo >foo &&
1930 git add foo &&
1931 git commit -SB7227189 -m signed_commit
1932'
1933
Henning Schild53fc9992018-07-20 10:28:07 +02001934test_expect_success GPGSM 'setup signed branch x509' '
Johannes Schindelin8f378542020-11-18 23:44:27 +00001935 test_when_finished "git reset --hard && git checkout main" &&
1936 git checkout -b signed-x509 main &&
Henning Schild53fc9992018-07-20 10:28:07 +02001937 echo foo >foo &&
1938 git add foo &&
1939 test_config gpg.format x509 &&
1940 test_config user.signingkey $GIT_COMMITTER_EMAIL &&
1941 git commit -S -m signed_commit
1942'
1943
Fabian Stelzerf265f2d2021-09-10 20:07:41 +00001944test_expect_success GPGSSH 'setup sshkey signed branch' '
1945 test_config gpg.format ssh &&
1946 test_config user.signingkey "${GPGSSH_KEY_PRIMARY}" &&
1947 test_when_finished "git reset --hard && git checkout main" &&
1948 git checkout -b signed-ssh main &&
1949 echo foo >foo &&
1950 git add foo &&
1951 git commit -S -m signed_commit
1952'
1953
Fabian Stelzer4bbf3782021-12-09 09:52:46 +01001954test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed commits with keys having defined lifetimes' '
1955 test_config gpg.format ssh &&
1956 touch file &&
1957 git add file &&
1958
1959 echo expired >file && test_tick && git commit -a -m expired -S"${GPGSSH_KEY_EXPIRED}" &&
1960 git tag expired-signed &&
1961
1962 echo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S"${GPGSSH_KEY_NOTYETVALID}" &&
1963 git tag notyetvalid-signed &&
1964
1965 echo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S"${GPGSSH_KEY_TIMEBOXEDVALID}" &&
1966 git tag timeboxedvalid-signed &&
1967
1968 echo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S"${GPGSSH_KEY_TIMEBOXEDINVALID}" &&
1969 git tag timeboxedinvalid-signed
1970'
1971
Hans Jerry Illikainen67a6ea62019-11-22 20:23:12 +00001972test_expect_success GPGSM 'log x509 fingerprint' '
1973 echo "F8BF62E0693D0694816377099909C779FA23FD65 | " >expect &&
1974 git log -n1 --format="%GF | %GP" signed-x509 >actual &&
1975 test_cmp expect actual
1976'
1977
1978test_expect_success GPGSM 'log OpenPGP fingerprint' '
1979 echo "D4BE22311AD3131E5EDA29A461092E85B7227189" > expect &&
1980 git log -n1 --format="%GP" signed-subkey >actual &&
1981 test_cmp expect actual
1982'
1983
Fabian Stelzerf265f2d2021-09-10 20:07:41 +00001984test_expect_success GPGSSH 'log ssh key fingerprint' '
1985 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
1986 ssh-keygen -lf "${GPGSSH_KEY_PRIMARY}" | awk "{print \$2\" | \"}" >expect &&
1987 git log -n1 --format="%GF | %GP" signed-ssh >actual &&
1988 test_cmp expect actual
1989'
1990
Mehul Jainaefc81a2016-06-24 19:42:34 +05301991test_expect_success GPG 'log --graph --show-signature' '
Zoltan Klingercf3983d2014-07-09 12:10:21 +10001992 git log --graph --show-signature -n1 signed >actual &&
1993 grep "^| gpg: Signature made" actual &&
1994 grep "^| gpg: Good signature" actual
1995'
1996
Henning Schild53fc9992018-07-20 10:28:07 +02001997test_expect_success GPGSM 'log --graph --show-signature x509' '
1998 git log --graph --show-signature -n1 signed-x509 >actual &&
1999 grep "^| gpgsm: Signature made" actual &&
2000 grep "^| gpgsm: Good signature" actual
2001'
2002
Fabian Stelzerf265f2d2021-09-10 20:07:41 +00002003test_expect_success GPGSSH 'log --graph --show-signature ssh' '
2004 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
2005 git log --graph --show-signature -n1 signed-ssh >actual &&
2006 grep "${GOOD_SIGNATURE_TRUSTED}" actual
2007'
2008
Fabian Stelzer4bbf3782021-12-09 09:52:46 +01002009test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'log shows failure on expired signature key' '
2010 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
2011 git log --graph --show-signature -n1 expired-signed >actual &&
2012 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
2013'
2014
2015test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'log shows failure on not yet valid signature key' '
2016 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
2017 git log --graph --show-signature -n1 notyetvalid-signed >actual &&
2018 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
2019'
2020
2021test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'log show success with commit date and key validity matching' '
2022 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
2023 git log --graph --show-signature -n1 timeboxedvalid-signed >actual &&
2024 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
2025 ! grep "${GPGSSH_BAD_SIGNATURE}" actual
2026'
2027
2028test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'log shows failure with commit date outside of key validity' '
2029 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
2030 git log --graph --show-signature -n1 timeboxedinvalid-signed >actual &&
2031 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
2032'
2033
Zoltan Klingercf3983d2014-07-09 12:10:21 +10002034test_expect_success GPG 'log --graph --show-signature for merged tag' '
Johannes Schindelin8f378542020-11-18 23:44:27 +00002035 test_when_finished "git reset --hard && git checkout main" &&
2036 git checkout -b plain main &&
Zoltan Klingercf3983d2014-07-09 12:10:21 +10002037 echo aaa >bar &&
2038 git add bar &&
2039 git commit -m bar_commit &&
Johannes Schindelin8f378542020-11-18 23:44:27 +00002040 git checkout -b tagged main &&
Zoltan Klingercf3983d2014-07-09 12:10:21 +10002041 echo bbb >baz &&
2042 git add baz &&
2043 git commit -m baz_commit &&
2044 git tag -s -m signed_tag_msg signed_tag &&
2045 git checkout plain &&
2046 git merge --no-ff -m msg signed_tag &&
2047 git log --graph --show-signature -n1 plain >actual &&
2048 grep "^|\\\ merged tag" actual &&
2049 grep "^| | gpg: Signature made" actual &&
2050 grep "^| | gpg: Good signature" actual
2051'
2052
Harald van Dijk237a2812020-02-29 13:07:57 +00002053test_expect_success GPG 'log --graph --show-signature for merged tag in shallow clone' '
Johannes Schindelin8f378542020-11-18 23:44:27 +00002054 test_when_finished "git reset --hard && git checkout main" &&
2055 git checkout -b plain-shallow main &&
Harald van Dijk237a2812020-02-29 13:07:57 +00002056 echo aaa >bar &&
2057 git add bar &&
2058 git commit -m bar_commit &&
Johannes Schindelin8f378542020-11-18 23:44:27 +00002059 git checkout --detach main &&
Harald van Dijk237a2812020-02-29 13:07:57 +00002060 echo bbb >baz &&
2061 git add baz &&
2062 git commit -m baz_commit &&
2063 git tag -s -m signed_tag_msg signed_tag_shallow &&
2064 hash=$(git rev-parse HEAD) &&
2065 git checkout plain-shallow &&
2066 git merge --no-ff -m msg signed_tag_shallow &&
2067 git clone --depth 1 --no-local . shallow &&
2068 test_when_finished "rm -rf shallow" &&
2069 git -C shallow log --graph --show-signature -n1 plain-shallow >actual &&
2070 grep "tag signed_tag_shallow names a non-parent $hash" actual
2071'
2072
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002073test_expect_success GPG 'log --graph --show-signature for merged tag with missing key' '
Johannes Schindelin8f378542020-11-18 23:44:27 +00002074 test_when_finished "git reset --hard && git checkout main" &&
2075 git checkout -b plain-nokey main &&
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002076 echo aaa >bar &&
2077 git add bar &&
2078 git commit -m bar_commit &&
Johannes Schindelin8f378542020-11-18 23:44:27 +00002079 git checkout -b tagged-nokey main &&
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002080 echo bbb >baz &&
2081 git add baz &&
2082 git commit -m baz_commit &&
2083 git tag -s -m signed_tag_msg signed_tag_nokey &&
2084 git checkout plain-nokey &&
2085 git merge --no-ff -m msg signed_tag_nokey &&
2086 GNUPGHOME=. git log --graph --show-signature -n1 plain-nokey >actual &&
2087 grep "^|\\\ merged tag" actual &&
2088 grep "^| | gpg: Signature made" actual &&
Carlo Marcelo Arenas Belón46022ca2020-05-29 01:20:08 -07002089 grep -E "^| | gpg: Can'"'"'t check signature: (public key not found|No public key)" actual
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002090'
2091
2092test_expect_success GPG 'log --graph --show-signature for merged tag with bad signature' '
Johannes Schindelin8f378542020-11-18 23:44:27 +00002093 test_when_finished "git reset --hard && git checkout main" &&
2094 git checkout -b plain-bad main &&
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002095 echo aaa >bar &&
2096 git add bar &&
2097 git commit -m bar_commit &&
Johannes Schindelin8f378542020-11-18 23:44:27 +00002098 git checkout -b tagged-bad main &&
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002099 echo bbb >baz &&
2100 git add baz &&
2101 git commit -m baz_commit &&
2102 git tag -s -m signed_tag_msg signed_tag_bad &&
2103 git cat-file tag signed_tag_bad >raw &&
2104 sed -e "s/signed_tag_msg/forged/" raw >forged &&
2105 git hash-object -w -t tag forged >forged.tag &&
2106 git checkout plain-bad &&
2107 git merge --no-ff -m msg "$(cat forged.tag)" &&
2108 git log --graph --show-signature -n1 plain-bad >actual &&
2109 grep "^|\\\ merged tag" actual &&
2110 grep "^| | gpg: Signature made" actual &&
2111 grep "^| | gpg: BAD signature from" actual
2112'
2113
2114test_expect_success GPG 'log --show-signature for merged tag with GPG failure' '
Johannes Schindelin8f378542020-11-18 23:44:27 +00002115 test_when_finished "git reset --hard && git checkout main" &&
2116 git checkout -b plain-fail main &&
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002117 echo aaa >bar &&
2118 git add bar &&
2119 git commit -m bar_commit &&
Johannes Schindelin8f378542020-11-18 23:44:27 +00002120 git checkout -b tagged-fail main &&
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002121 echo bbb >baz &&
2122 git add baz &&
2123 git commit -m baz_commit &&
2124 git tag -s -m signed_tag_msg signed_tag_fail &&
2125 git checkout plain-fail &&
2126 git merge --no-ff -m msg signed_tag_fail &&
Ævar Arnfjörð Bjarmason29d8e212022-05-12 15:32:16 -07002127 if ! test_have_prereq VALGRIND
2128 then
2129 TMPDIR="$(pwd)/bogus" git log --show-signature -n1 plain-fail >actual &&
2130 grep "^merged tag" actual &&
2131 grep "^No signature" actual &&
2132 ! grep "^gpg: Signature made" actual
2133 fi
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002134'
2135
Henning Schild53fc9992018-07-20 10:28:07 +02002136test_expect_success GPGSM 'log --graph --show-signature for merged tag x509' '
Johannes Schindelin8f378542020-11-18 23:44:27 +00002137 test_when_finished "git reset --hard && git checkout main" &&
Henning Schild53fc9992018-07-20 10:28:07 +02002138 test_config gpg.format x509 &&
2139 test_config user.signingkey $GIT_COMMITTER_EMAIL &&
Johannes Schindelin8f378542020-11-18 23:44:27 +00002140 git checkout -b plain-x509 main &&
Henning Schild53fc9992018-07-20 10:28:07 +02002141 echo aaa >bar &&
2142 git add bar &&
2143 git commit -m bar_commit &&
Johannes Schindelin8f378542020-11-18 23:44:27 +00002144 git checkout -b tagged-x509 main &&
Henning Schild53fc9992018-07-20 10:28:07 +02002145 echo bbb >baz &&
2146 git add baz &&
2147 git commit -m baz_commit &&
2148 git tag -s -m signed_tag_msg signed_tag_x509 &&
2149 git checkout plain-x509 &&
2150 git merge --no-ff -m msg signed_tag_x509 &&
2151 git log --graph --show-signature -n1 plain-x509 >actual &&
2152 grep "^|\\\ merged tag" actual &&
2153 grep "^| | gpgsm: Signature made" actual &&
2154 grep "^| | gpgsm: Good signature" actual
2155'
2156
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002157test_expect_success GPGSM 'log --graph --show-signature for merged tag x509 missing key' '
Johannes Schindelin8f378542020-11-18 23:44:27 +00002158 test_when_finished "git reset --hard && git checkout main" &&
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002159 test_config gpg.format x509 &&
2160 test_config user.signingkey $GIT_COMMITTER_EMAIL &&
Johannes Schindelin8f378542020-11-18 23:44:27 +00002161 git checkout -b plain-x509-nokey main &&
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002162 echo aaa >bar &&
2163 git add bar &&
2164 git commit -m bar_commit &&
Johannes Schindelin8f378542020-11-18 23:44:27 +00002165 git checkout -b tagged-x509-nokey main &&
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002166 echo bbb >baz &&
2167 git add baz &&
2168 git commit -m baz_commit &&
2169 git tag -s -m signed_tag_msg signed_tag_x509_nokey &&
2170 git checkout plain-x509-nokey &&
2171 git merge --no-ff -m msg signed_tag_x509_nokey &&
2172 GNUPGHOME=. git log --graph --show-signature -n1 plain-x509-nokey >actual &&
2173 grep "^|\\\ merged tag" actual &&
Fabian Stelzera075e792022-03-04 11:25:17 +01002174 grep -e "^| | gpgsm: certificate not found" \
2175 -e "^| | gpgsm: failed to find the certificate: Not found" actual
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002176'
2177
2178test_expect_success GPGSM 'log --graph --show-signature for merged tag x509 bad signature' '
Johannes Schindelin8f378542020-11-18 23:44:27 +00002179 test_when_finished "git reset --hard && git checkout main" &&
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002180 test_config gpg.format x509 &&
2181 test_config user.signingkey $GIT_COMMITTER_EMAIL &&
Johannes Schindelin8f378542020-11-18 23:44:27 +00002182 git checkout -b plain-x509-bad main &&
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002183 echo aaa >bar &&
2184 git add bar &&
2185 git commit -m bar_commit &&
Johannes Schindelin8f378542020-11-18 23:44:27 +00002186 git checkout -b tagged-x509-bad main &&
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +00002187 echo bbb >baz &&
2188 git add baz &&
2189 git commit -m baz_commit &&
2190 git tag -s -m signed_tag_msg signed_tag_x509_bad &&
2191 git cat-file tag signed_tag_x509_bad >raw &&
2192 sed -e "s/signed_tag_msg/forged/" raw >forged &&
2193 git hash-object -w -t tag forged >forged.tag &&
2194 git checkout plain-x509-bad &&
2195 git merge --no-ff -m msg "$(cat forged.tag)" &&
2196 git log --graph --show-signature -n1 plain-x509-bad >actual &&
2197 grep "^|\\\ merged tag" actual &&
2198 grep "^| | gpgsm: Signature made" actual &&
2199 grep "^| | gpgsm: invalid signature" actual
2200'
2201
2202
Mehul Jainaa379992016-06-22 22:21:25 +05302203test_expect_success GPG '--no-show-signature overrides --show-signature' '
2204 git log -1 --show-signature --no-show-signature signed >actual &&
2205 ! grep "^gpg:" actual
2206'
2207
Mehul Jainfce04c32016-06-22 22:21:26 +05302208test_expect_success GPG 'log.showsignature=true behaves like --show-signature' '
2209 test_config log.showsignature true &&
2210 git log -1 signed >actual &&
2211 grep "gpg: Signature made" actual &&
2212 grep "gpg: Good signature" actual
2213'
2214
2215test_expect_success GPG '--no-show-signature overrides log.showsignature=true' '
2216 test_config log.showsignature true &&
2217 git log -1 --no-show-signature signed >actual &&
2218 ! grep "^gpg:" actual
2219'
2220
2221test_expect_success GPG '--show-signature overrides log.showsignature=false' '
2222 test_config log.showsignature false &&
2223 git log -1 --show-signature signed >actual &&
2224 grep "gpg: Signature made" actual &&
2225 grep "gpg: Good signature" actual
2226'
2227
Dongcan Jiang695985f2015-03-11 10:13:02 +08002228test_expect_success 'log --graph --no-walk is forbidden' '
2229 test_must_fail git log --graph --no-walk
2230'
2231
Han-Wen Nienhuysdc474892021-05-31 16:56:36 +00002232test_expect_success 'log on empty repo fails' '
Jeff Kingce113602015-08-29 01:04:18 -04002233 git init empty &&
Han-Wen Nienhuys230356b2021-05-31 16:56:16 +00002234 test_when_finished "rm -rf empty" &&
Jeff Kingce113602015-08-29 01:04:18 -04002235 test_must_fail git -C empty log 2>stderr &&
Han-Wen Nienhuysdc474892021-05-31 16:56:36 +00002236 test_i18ngrep does.not.have.any.commits stderr
2237'
2238
2239test_expect_success REFFILES 'log diagnoses bogus HEAD hash' '
2240 git init empty &&
2241 test_when_finished "rm -rf empty" &&
Johannes Schindelin8f378542020-11-18 23:44:27 +00002242 echo 1234abcd >empty/.git/refs/heads/main &&
Jeff Kingce113602015-08-29 01:04:18 -04002243 test_must_fail git -C empty log 2>stderr &&
Han-Wen Nienhuysdc474892021-05-31 16:56:36 +00002244 test_i18ngrep broken stderr
2245'
Han-Wen Nienhuys230356b2021-05-31 16:56:16 +00002246
Linus Torvalds04ede972022-08-01 14:15:19 -04002247test_expect_success REFFILES 'log diagnoses bogus HEAD symref' '
Han-Wen Nienhuys230356b2021-05-31 16:56:16 +00002248 git init empty &&
Linus Torvalds04ede972022-08-01 14:15:19 -04002249 echo "ref: refs/heads/invalid.lock" > empty/.git/HEAD &&
Jeff Kingce113602015-08-29 01:04:18 -04002250 test_must_fail git -C empty log 2>stderr &&
2251 test_i18ngrep broken stderr &&
2252 test_must_fail git -C empty log --default totally-bogus 2>stderr &&
2253 test_i18ngrep broken stderr
2254'
2255
Jeff King5d34d1a2017-08-02 18:30:19 -04002256test_expect_success 'log does not default to HEAD when rev input is given' '
Jeff King5d34d1a2017-08-02 18:30:19 -04002257 git log --branches=does-not-exist >actual &&
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +00002258 test_must_be_empty actual
Jeff King5d34d1a2017-08-02 18:30:19 -04002259'
2260
Jeff King04a0e982020-08-26 16:13:05 -04002261test_expect_success 'do not default to HEAD with ignored object on cmdline' '
2262 git log --ignore-missing $ZERO_OID >actual &&
2263 test_must_be_empty actual
2264'
2265
2266test_expect_success 'do not default to HEAD with ignored object on stdin' '
2267 echo $ZERO_OID | git log --ignore-missing --stdin >actual &&
2268 test_must_be_empty actual
2269'
2270
Jeff King728350b2015-12-17 01:47:07 -05002271test_expect_success 'set up --source tests' '
2272 git checkout --orphan source-a &&
2273 test_commit one &&
2274 test_commit two &&
2275 git checkout -b source-b HEAD^ &&
2276 test_commit three
2277'
2278
2279test_expect_success 'log --source paints branch names' '
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00002280 cat >expect <<-EOF &&
2281 $(git rev-parse --short :/three) source-b three
2282 $(git rev-parse --short :/two ) source-a two
2283 $(git rev-parse --short :/one ) source-b one
Jeff King728350b2015-12-17 01:47:07 -05002284 EOF
2285 git log --oneline --source source-a source-b >actual &&
2286 test_cmp expect actual
2287'
2288
2289test_expect_success 'log --source paints tag names' '
2290 git tag -m tagged source-tag &&
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00002291 cat >expect <<-EOF &&
2292 $(git rev-parse --short :/three) source-tag three
2293 $(git rev-parse --short :/two ) source-a two
2294 $(git rev-parse --short :/one ) source-tag one
Jeff King728350b2015-12-17 01:47:07 -05002295 EOF
2296 git log --oneline --source source-tag source-a >actual &&
2297 test_cmp expect actual
2298'
2299
Jeff Kinged79b2c2017-05-23 15:51:32 -04002300test_expect_success 'log --source paints symmetric ranges' '
brian m. carlsoncb78f4f2019-12-21 19:49:21 +00002301 cat >expect <<-EOF &&
2302 $(git rev-parse --short :/three) source-b three
2303 $(git rev-parse --short :/two ) source-a two
Jeff Kinged79b2c2017-05-23 15:51:32 -04002304 EOF
2305 git log --oneline --source source-a...source-b >actual &&
2306 test_cmp expect actual
2307'
2308
Matthew DeVore669b1d22018-10-22 18:13:42 -07002309test_expect_success '--exclude-promisor-objects does not BUG-crash' '
2310 test_must_fail git log --exclude-promisor-objects source-a
2311'
2312
Jeff Kingd1ed8d62021-07-14 12:31:36 -04002313test_expect_success 'log --decorate includes all levels of tag annotated tags' '
2314 git checkout -b branch &&
2315 git commit --allow-empty -m "new commit" &&
2316 git tag lightweight HEAD &&
2317 git tag -m annotated annotated HEAD &&
2318 git tag -m double-0 double-0 HEAD &&
2319 git tag -m double-1 double-1 double-0 &&
2320 cat >expect <<-\EOF &&
2321 HEAD -> branch, tag: lightweight, tag: double-1, tag: double-0, tag: annotated
2322 EOF
2323 git log -1 --format="%D" >actual &&
2324 test_cmp expect actual
2325'
2326
Derrick Stolee92156292022-08-05 17:58:39 +00002327test_expect_success 'log --decorate does not include things outside filter' '
2328 reflist="refs/prefetch refs/rebase-merge refs/bundle" &&
2329
2330 for ref in $reflist
2331 do
2332 git update-ref $ref/fake HEAD || return 1
2333 done &&
2334
2335 git log --decorate=full --oneline >actual &&
2336
2337 # None of the refs are visible:
2338 ! grep /fake actual
2339'
2340
Jeff King51b45942019-08-06 10:40:16 -04002341test_expect_success 'log --end-of-options' '
2342 git update-ref refs/heads/--source HEAD &&
2343 git log --end-of-options --source >actual &&
2344 git log >expect &&
2345 test_cmp expect actual
2346'
2347
René Scharfe794c0002021-12-17 17:48:49 +01002348test_expect_success 'set up commits with different authors' '
2349 git checkout --orphan authors &&
2350 test_commit --author "Jim <jim@example.com>" jim_1 &&
2351 test_commit --author "Val <val@example.com>" val_1 &&
2352 test_commit --author "Val <val@example.com>" val_2 &&
2353 test_commit --author "Jim <jim@example.com>" jim_2 &&
2354 test_commit --author "Val <val@example.com>" val_3 &&
2355 test_commit --author "Jim <jim@example.com>" jim_3
2356'
2357
2358test_expect_success 'log --invert-grep --grep --author' '
2359 cat >expect <<-\EOF &&
2360 val_3
2361 val_1
2362 EOF
2363 git log --format=%s --author=Val --grep 2 --invert-grep >actual &&
2364 test_cmp expect actual
2365'
2366
Ævar Arnfjörð Bjarmason65113122010-08-15 10:16:25 +00002367test_done