diff: parse separate options like -S foo
[git.git] / t / t4202-log.sh
1 #!/bin/sh
2
3 test_description='git log'
4
5 . ./test-lib.sh
6
7 test_expect_success setup '
8
9         echo one >one &&
10         git add one &&
11         test_tick &&
12         git commit -m initial &&
13
14         echo ichi >one &&
15         git add one &&
16         test_tick &&
17         git commit -m second &&
18
19         git mv one ichi &&
20         test_tick &&
21         git commit -m third &&
22
23         cp ichi ein &&
24         git add ein &&
25         test_tick &&
26         git commit -m fourth &&
27
28         mkdir a &&
29         echo ni >a/two &&
30         git add a/two &&
31         test_tick &&
32         git commit -m fifth  &&
33
34         git rm a/two &&
35         test_tick &&
36         git commit -m sixth
37
38 '
39
40 printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial" > expect
41 test_expect_success 'pretty' '
42
43         git log --pretty="format:%s" > actual &&
44         test_cmp expect actual
45 '
46
47 printf "sixth\nfifth\nfourth\nthird\nsecond\ninitial\n" > expect
48 test_expect_success 'pretty (tformat)' '
49
50         git log --pretty="tformat:%s" > actual &&
51         test_cmp expect actual
52 '
53
54 test_expect_success 'pretty (shortcut)' '
55
56         git log --pretty="%s" > actual &&
57         test_cmp expect actual
58 '
59
60 test_expect_success 'format' '
61
62         git log --format="%s" > actual &&
63         test_cmp expect actual
64 '
65
66 cat > expect << EOF
67  This is
68   the sixth
69   commit.
70  This is
71   the fifth
72   commit.
73 EOF
74
75 test_expect_success 'format %w(12,1,2)' '
76
77         git log -2 --format="%w(12,1,2)This is the %s commit." > actual &&
78         test_cmp expect actual
79 '
80
81 test_expect_success 'format %w(,1,2)' '
82
83         git log -2 --format="%w(,1,2)This is%nthe %s%ncommit." > actual &&
84         test_cmp expect actual
85 '
86
87 cat > expect << EOF
88 804a787 sixth
89 394ef78 fifth
90 5d31159 fourth
91 2fbe8c0 third
92 f7dab8e second
93 3a2fdcb initial
94 EOF
95 test_expect_success 'oneline' '
96
97         git log --oneline > actual &&
98         test_cmp expect actual
99 '
100
101 test_expect_success 'diff-filter=A' '
102
103         git log --pretty="format:%s" --diff-filter=A HEAD > actual &&
104         git log --pretty="format:%s" --diff-filter A HEAD > actual-separate &&
105         printf "fifth\nfourth\nthird\ninitial" > expect &&
106         test_cmp expect actual &&
107         test_cmp expect actual-separate
108
109 '
110
111 test_expect_success 'diff-filter=M' '
112
113         actual=$(git log --pretty="format:%s" --diff-filter=M HEAD) &&
114         expect=$(echo second) &&
115         test "$actual" = "$expect" || {
116                 echo Oops
117                 echo "Actual: $actual"
118                 false
119         }
120
121 '
122
123 test_expect_success 'diff-filter=D' '
124
125         actual=$(git log --pretty="format:%s" --diff-filter=D HEAD) &&
126         expect=$(echo sixth ; echo third) &&
127         test "$actual" = "$expect" || {
128                 echo Oops
129                 echo "Actual: $actual"
130                 false
131         }
132
133 '
134
135 test_expect_success 'diff-filter=R' '
136
137         actual=$(git log -M --pretty="format:%s" --diff-filter=R HEAD) &&
138         expect=$(echo third) &&
139         test "$actual" = "$expect" || {
140                 echo Oops
141                 echo "Actual: $actual"
142                 false
143         }
144
145 '
146
147 test_expect_success 'diff-filter=C' '
148
149         actual=$(git log -C -C --pretty="format:%s" --diff-filter=C HEAD) &&
150         expect=$(echo fourth) &&
151         test "$actual" = "$expect" || {
152                 echo Oops
153                 echo "Actual: $actual"
154                 false
155         }
156
157 '
158
159 test_expect_success 'git log --follow' '
160
161         actual=$(git log --follow --pretty="format:%s" ichi) &&
162         expect=$(echo third ; echo second ; echo initial) &&
163         test "$actual" = "$expect" || {
164                 echo Oops
165                 echo "Actual: $actual"
166                 false
167         }
168
169 '
170
171 cat > expect << EOF
172 804a787 sixth
173 394ef78 fifth
174 5d31159 fourth
175 EOF
176 test_expect_success 'git log --no-walk <commits> sorts by commit time' '
177         git log --no-walk --oneline 5d31159 804a787 394ef78 > actual &&
178         test_cmp expect actual
179 '
180
181 cat > expect << EOF
182 5d31159 fourth
183 804a787 sixth
184 394ef78 fifth
185 EOF
186 test_expect_success 'git show <commits> leaves list of commits as given' '
187         git show --oneline -s 5d31159 804a787 394ef78 > actual &&
188         test_cmp expect actual
189 '
190
191 test_expect_success 'setup case sensitivity tests' '
192         echo case >one &&
193         test_tick &&
194         git add one
195         git commit -a -m Second
196 '
197
198 test_expect_success 'log --grep' '
199         echo second >expect &&
200         git log -1 --pretty="tformat:%s" --grep=sec >actual &&
201         test_cmp expect actual
202 '
203
204 test_expect_success 'log -i --grep' '
205         echo Second >expect &&
206         git log -1 --pretty="tformat:%s" -i --grep=sec >actual &&
207         test_cmp expect actual
208 '
209
210 test_expect_success 'log --grep -i' '
211         echo Second >expect &&
212         git log -1 --pretty="tformat:%s" --grep=sec -i >actual &&
213         test_cmp expect actual
214 '
215
216 cat > expect <<EOF
217 * Second
218 * sixth
219 * fifth
220 * fourth
221 * third
222 * second
223 * initial
224 EOF
225
226 test_expect_success 'simple log --graph' '
227         git log --graph --pretty=tformat:%s >actual &&
228         test_cmp expect actual
229 '
230
231 test_expect_success 'set up merge history' '
232         git checkout -b side HEAD~4 &&
233         test_commit side-1 1 1 &&
234         test_commit side-2 2 2 &&
235         git checkout master &&
236         git merge side
237 '
238
239 cat > expect <<\EOF
240 *   Merge branch 'side'
241 |\
242 | * side-2
243 | * side-1
244 * | Second
245 * | sixth
246 * | fifth
247 * | fourth
248 |/
249 * third
250 * second
251 * initial
252 EOF
253
254 test_expect_success 'log --graph with merge' '
255         git log --graph --date-order --pretty=tformat:%s |
256                 sed "s/ *\$//" >actual &&
257         test_cmp expect actual
258 '
259
260 cat > expect <<\EOF
261 *   commit master
262 |\  Merge: A B
263 | | Author: A U Thor <author@example.com>
264 | |
265 | |     Merge branch 'side'
266 | |
267 | * commit side
268 | | Author: A U Thor <author@example.com>
269 | |
270 | |     side-2
271 | |
272 | * commit tags/side-1
273 | | Author: A U Thor <author@example.com>
274 | |
275 | |     side-1
276 | |
277 * | commit master~1
278 | | Author: A U Thor <author@example.com>
279 | |
280 | |     Second
281 | |
282 * | commit master~2
283 | | Author: A U Thor <author@example.com>
284 | |
285 | |     sixth
286 | |
287 * | commit master~3
288 | | Author: A U Thor <author@example.com>
289 | |
290 | |     fifth
291 | |
292 * | commit master~4
293 |/  Author: A U Thor <author@example.com>
294 |
295 |       fourth
296 |
297 * commit tags/side-1~1
298 | Author: A U Thor <author@example.com>
299 |
300 |     third
301 |
302 * commit tags/side-1~2
303 | Author: A U Thor <author@example.com>
304 |
305 |     second
306 |
307 * commit tags/side-1~3
308   Author: A U Thor <author@example.com>
309
310       initial
311 EOF
312
313 test_expect_success 'log --graph with full output' '
314         git log --graph --date-order --pretty=short |
315                 git name-rev --name-only --stdin |
316                 sed "s/Merge:.*/Merge: A B/;s/ *\$//" >actual &&
317         test_cmp expect actual
318 '
319
320 test_expect_success 'set up more tangled history' '
321         git checkout -b tangle HEAD~6 &&
322         test_commit tangle-a tangle-a a &&
323         git merge master~3 &&
324         git merge side~1 &&
325         git checkout master &&
326         git merge tangle &&
327         git checkout -b reach &&
328         test_commit reach &&
329         git checkout master &&
330         git checkout -b octopus-a &&
331         test_commit octopus-a &&
332         git checkout master &&
333         git checkout -b octopus-b &&
334         test_commit octopus-b &&
335         git checkout master &&
336         test_commit seventh &&
337         git merge octopus-a octopus-b
338         git merge reach
339 '
340
341 cat > expect <<\EOF
342 *   Merge commit 'reach'
343 |\
344 | \
345 |  \
346 *-. \   Merge commit 'octopus-a'; commit 'octopus-b'
347 |\ \ \
348 * | | | seventh
349 | | * | octopus-b
350 | |/ /
351 |/| |
352 | * | octopus-a
353 |/ /
354 | * reach
355 |/
356 *   Merge branch 'tangle'
357 |\
358 | *   Merge branch 'side' (early part) into tangle
359 | |\
360 | * \   Merge branch 'master' (early part) into tangle
361 | |\ \
362 | * | | tangle-a
363 * | | |   Merge branch 'side'
364 |\ \ \ \
365 | * | | | side-2
366 | | |_|/
367 | |/| |
368 | * | | side-1
369 * | | | Second
370 * | | | sixth
371 | |_|/
372 |/| |
373 * | | fifth
374 * | | fourth
375 |/ /
376 * | third
377 |/
378 * second
379 * initial
380 EOF
381
382 test_expect_success 'log --graph with merge' '
383         git log --graph --date-order --pretty=tformat:%s |
384                 sed "s/ *\$//" >actual &&
385         test_cmp expect actual
386 '
387
388 test_expect_success 'log.decorate configuration' '
389         git config --unset-all log.decorate || :
390
391         git log --oneline >expect.none &&
392         git log --oneline --decorate >expect.short &&
393         git log --oneline --decorate=full >expect.full &&
394
395         echo "[log] decorate" >>.git/config &&
396         git log --oneline >actual &&
397         test_cmp expect.short actual &&
398
399         git config --unset-all log.decorate &&
400         git config log.decorate true &&
401         git log --oneline >actual &&
402         test_cmp expect.short actual &&
403         git log --oneline --decorate=full >actual &&
404         test_cmp expect.full actual &&
405         git log --oneline --decorate=no >actual &&
406         test_cmp expect.none actual &&
407
408         git config --unset-all log.decorate &&
409         git config log.decorate no &&
410         git log --oneline >actual &&
411         test_cmp expect.none actual &&
412         git log --oneline --decorate >actual &&
413         test_cmp expect.short actual &&
414         git log --oneline --decorate=full >actual &&
415         test_cmp expect.full actual &&
416
417         git config --unset-all log.decorate &&
418         git config log.decorate short &&
419         git log --oneline >actual &&
420         test_cmp expect.short actual &&
421         git log --oneline --no-decorate >actual &&
422         test_cmp expect.none actual &&
423         git log --oneline --decorate=full >actual &&
424         test_cmp expect.full actual &&
425
426         git config --unset-all log.decorate &&
427         git config log.decorate full &&
428         git log --oneline >actual &&
429         test_cmp expect.full actual &&
430         git log --oneline --no-decorate >actual &&
431         test_cmp expect.none actual &&
432         git log --oneline --decorate >actual &&
433         test_cmp expect.short actual
434
435 '
436
437 test_done
438