]>
Commit | Line | Data |
---|---|---|
3c2f75b5 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2006 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='Various diff formatting options' | |
7 | ||
8 | . ./test-lib.sh | |
9 | ||
10 | test_expect_success setup ' | |
11 | ||
12 | GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" && | |
13 | GIT_COMMITTER_DATE="2006-06-26 00:00:00 +0000" && | |
14 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && | |
15 | ||
16 | mkdir dir && | |
3cb56738 | 17 | mkdir dir2 && |
3c2f75b5 JH |
18 | for i in 1 2 3; do echo $i; done >file0 && |
19 | for i in A B; do echo $i; done >dir/sub && | |
20 | cat file0 >file2 && | |
21 | git add file0 file2 dir/sub && | |
22 | git commit -m Initial && | |
23 | ||
24 | git branch initial && | |
25 | git branch side && | |
26 | ||
27 | GIT_AUTHOR_DATE="2006-06-26 00:01:00 +0000" && | |
28 | GIT_COMMITTER_DATE="2006-06-26 00:01:00 +0000" && | |
29 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && | |
30 | ||
31 | for i in 4 5 6; do echo $i; done >>file0 && | |
32 | for i in C D; do echo $i; done >>dir/sub && | |
33 | rm -f file2 && | |
34 | git update-index --remove file0 file2 dir/sub && | |
a40d384c | 35 | git commit -m "Second${LF}${LF}This is the second commit." && |
3c2f75b5 JH |
36 | |
37 | GIT_AUTHOR_DATE="2006-06-26 00:02:00 +0000" && | |
38 | GIT_COMMITTER_DATE="2006-06-26 00:02:00 +0000" && | |
39 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && | |
40 | ||
41 | for i in A B C; do echo $i; done >file1 && | |
42 | git add file1 && | |
43 | for i in E F; do echo $i; done >>dir/sub && | |
44 | git update-index dir/sub && | |
45 | git commit -m Third && | |
46 | ||
47 | GIT_AUTHOR_DATE="2006-06-26 00:03:00 +0000" && | |
48 | GIT_COMMITTER_DATE="2006-06-26 00:03:00 +0000" && | |
49 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && | |
50 | ||
51 | git checkout side && | |
52 | for i in A B C; do echo $i; done >>file0 && | |
53 | for i in 1 2; do echo $i; done >>dir/sub && | |
54 | cat dir/sub >file3 && | |
55 | git add file3 && | |
56 | git update-index file0 dir/sub && | |
57 | git commit -m Side && | |
58 | ||
59 | GIT_AUTHOR_DATE="2006-06-26 00:04:00 +0000" && | |
60 | GIT_COMMITTER_DATE="2006-06-26 00:04:00 +0000" && | |
61 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && | |
62 | ||
63 | git checkout master && | |
64 | git pull -s ours . side && | |
65 | ||
66 | GIT_AUTHOR_DATE="2006-06-26 00:05:00 +0000" && | |
67 | GIT_COMMITTER_DATE="2006-06-26 00:05:00 +0000" && | |
68 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && | |
69 | ||
70 | for i in A B C; do echo $i; done >>file0 && | |
71 | for i in 1 2; do echo $i; done >>dir/sub && | |
72 | git update-index file0 dir/sub && | |
73 | ||
d61027b2 MS |
74 | mkdir dir3 && |
75 | cp dir/sub dir3/sub && | |
0e496492 | 76 | test-tool chmtime +1 dir3/sub && |
d61027b2 | 77 | |
e0d10e1c | 78 | git config log.showroot false && |
8ff99e74 | 79 | git commit --amend && |
204f01a2 JH |
80 | |
81 | GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" && | |
82 | GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" && | |
83 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && | |
84 | git checkout -b rearrange initial && | |
85 | for i in B A; do echo $i; done >dir/sub && | |
86 | git add dir/sub && | |
87 | git commit -m "Rearranged lines in dir/sub" && | |
88 | git checkout master && | |
89 | ||
58aaced4 SB |
90 | GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" && |
91 | GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" && | |
92 | export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && | |
93 | git checkout -b mode initial && | |
94 | git update-index --chmod=+x file0 && | |
95 | git commit -m "update mode" && | |
96 | git checkout -f master && | |
97 | ||
04b19fca JK |
98 | # Same merge as master, but with parents reversed. Hide it in a |
99 | # pseudo-ref to avoid impacting tests with --all. | |
100 | commit=$(echo reverse | | |
101 | git commit-tree -p master^2 -p master^1 master^{tree}) && | |
102 | git update-ref REVERSE $commit && | |
103 | ||
5404c116 MM |
104 | git config diff.renames false && |
105 | ||
3c2f75b5 JH |
106 | git show-branch |
107 | ' | |
108 | ||
109 | : <<\EOF | |
110 | ! [initial] Initial | |
111 | * [master] Merge branch 'side' | |
204f01a2 JH |
112 | ! [rearrange] Rearranged lines in dir/sub |
113 | ! [side] Side | |
114 | ---- | |
115 | + [rearrange] Rearranged lines in dir/sub | |
116 | - [master] Merge branch 'side' | |
117 | * + [side] Side | |
118 | * [master^] Third | |
119 | * [master~2] Second | |
120 | +*++ [initial] Initial | |
3c2f75b5 JH |
121 | EOF |
122 | ||
72f936b1 | 123 | process_diffs () { |
124 | _x04="[0-9a-f][0-9a-f][0-9a-f][0-9a-f]" && | |
125 | _x07="$_x05[0-9a-f][0-9a-f]" && | |
126 | sed -e "s/$OID_REGEX/$ZERO_OID/g" \ | |
127 | -e "s/From $_x40 /From $ZERO_OID /" \ | |
128 | -e "s/from $_x40)/from $ZERO_OID)/" \ | |
129 | -e "s/commit $_x40\$/commit $ZERO_OID/" \ | |
130 | -e "s/commit $_x40 (/commit $ZERO_OID (/" \ | |
131 | -e "s/$_x40 $_x40 $_x40/$ZERO_OID $ZERO_OID $ZERO_OID/" \ | |
132 | -e "s/$_x40 $_x40 /$ZERO_OID $ZERO_OID /" \ | |
133 | -e "s/^$_x40 $_x40$/$ZERO_OID $ZERO_OID/" \ | |
134 | -e "s/^$_x40 /$ZERO_OID /" \ | |
135 | -e "s/^$_x40$/$ZERO_OID/" \ | |
136 | -e "s/$_x07\.\.$_x07/fffffff..fffffff/g" \ | |
137 | -e "s/$_x07,$_x07\.\.$_x07/fffffff,fffffff..fffffff/g" \ | |
138 | -e "s/$_x07 $_x07 $_x07/fffffff fffffff fffffff/g" \ | |
139 | -e "s/$_x07 $_x07 /fffffff fffffff /g" \ | |
140 | -e "s/Merge: $_x07 $_x07/Merge: fffffff fffffff/g" \ | |
141 | -e "s/$_x07\.\.\./fffffff.../g" \ | |
142 | -e "s/ $_x04\.\.\./ ffff.../g" \ | |
143 | -e "s/ $_x04/ ffff/g" \ | |
144 | "$1" | |
145 | } | |
146 | ||
4ff03347 | 147 | V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g') |
b4c02c30 | 148 | while read magic cmd |
3c2f75b5 | 149 | do |
b4c02c30 AR |
150 | case "$magic" in |
151 | '' | '#'*) | |
152 | continue ;; | |
153 | :*) | |
154 | magic=${magic#:} | |
155 | label="$magic-$cmd" | |
156 | case "$magic" in | |
157 | noellipses) ;; | |
158 | *) | |
165293af | 159 | BUG "unknown magic $magic" ;; |
b4c02c30 AR |
160 | esac ;; |
161 | *) | |
162 | cmd="$magic $cmd" magic= | |
163 | label="$cmd" ;; | |
3c2f75b5 | 164 | esac |
b4c02c30 | 165 | test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g') |
4ff03347 | 166 | pfx=$(printf "%04d" $test_count) |
bfdbee98 | 167 | expect="$TEST_DIRECTORY/t4013/diff.$test" |
3c2f75b5 JH |
168 | actual="$pfx-diff.$test" |
169 | ||
de231e57 | 170 | test_expect_success "git $cmd # magic is ${magic:-(not used)}" ' |
3c2f75b5 | 171 | { |
b4c02c30 AR |
172 | echo "$ git $cmd" |
173 | case "$magic" in | |
174 | "") | |
175 | GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;; | |
176 | noellipses) | |
177 | git $cmd ;; | |
178 | esac | | |
6c7f4ceb | 179 | sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \ |
33ee4cfb | 180 | -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/" |
3c2f75b5 JH |
181 | echo "\$" |
182 | } >"$actual" && | |
183 | if test -f "$expect" | |
184 | then | |
72f936b1 | 185 | process_diffs "$actual" >actual && |
186 | process_diffs "$expect" >expect && | |
6dd88832 JN |
187 | case $cmd in |
188 | *format-patch* | *-stat*) | |
72f936b1 | 189 | test_i18ncmp expect actual;; |
6dd88832 | 190 | *) |
72f936b1 | 191 | test_cmp expect actual;; |
6dd88832 | 192 | esac && |
72f936b1 | 193 | rm -f "$actual" actual expect |
3c2f75b5 JH |
194 | else |
195 | # this is to help developing new tests. | |
196 | cp "$actual" "$expect" | |
197 | false | |
198 | fi | |
199 | ' | |
200 | done <<\EOF | |
201 | diff-tree initial | |
202 | diff-tree -r initial | |
203 | diff-tree -r --abbrev initial | |
204 | diff-tree -r --abbrev=4 initial | |
205 | diff-tree --root initial | |
206 | diff-tree --root --abbrev initial | |
c2f1d398 | 207 | :noellipses diff-tree --root --abbrev initial |
3c2f75b5 JH |
208 | diff-tree --root -r initial |
209 | diff-tree --root -r --abbrev initial | |
c2f1d398 | 210 | :noellipses diff-tree --root -r --abbrev initial |
3c2f75b5 | 211 | diff-tree --root -r --abbrev=4 initial |
c2f1d398 | 212 | :noellipses diff-tree --root -r --abbrev=4 initial |
3c2f75b5 JH |
213 | diff-tree -p initial |
214 | diff-tree --root -p initial | |
215 | diff-tree --patch-with-stat initial | |
216 | diff-tree --root --patch-with-stat initial | |
217 | diff-tree --patch-with-raw initial | |
218 | diff-tree --root --patch-with-raw initial | |
219 | ||
220 | diff-tree --pretty initial | |
221 | diff-tree --pretty --root initial | |
222 | diff-tree --pretty -p initial | |
223 | diff-tree --pretty --stat initial | |
224 | diff-tree --pretty --summary initial | |
225 | diff-tree --pretty --stat --summary initial | |
226 | diff-tree --pretty --root -p initial | |
227 | diff-tree --pretty --root --stat initial | |
026625e7 JH |
228 | # improved by Timo's patch |
229 | diff-tree --pretty --root --summary initial | |
230 | # improved by Timo's patch | |
231 | diff-tree --pretty --root --summary -r initial | |
3c2f75b5 JH |
232 | diff-tree --pretty --root --stat --summary initial |
233 | diff-tree --pretty --patch-with-stat initial | |
234 | diff-tree --pretty --root --patch-with-stat initial | |
235 | diff-tree --pretty --patch-with-raw initial | |
236 | diff-tree --pretty --root --patch-with-raw initial | |
237 | ||
238 | diff-tree --pretty=oneline initial | |
239 | diff-tree --pretty=oneline --root initial | |
240 | diff-tree --pretty=oneline -p initial | |
241 | diff-tree --pretty=oneline --root -p initial | |
242 | diff-tree --pretty=oneline --patch-with-stat initial | |
026625e7 | 243 | # improved by Timo's patch |
3c2f75b5 JH |
244 | diff-tree --pretty=oneline --root --patch-with-stat initial |
245 | diff-tree --pretty=oneline --patch-with-raw initial | |
246 | diff-tree --pretty=oneline --root --patch-with-raw initial | |
247 | ||
248 | diff-tree --pretty side | |
249 | diff-tree --pretty -p side | |
250 | diff-tree --pretty --patch-with-stat side | |
251 | ||
58aaced4 SB |
252 | diff-tree initial mode |
253 | diff-tree --stat initial mode | |
254 | diff-tree --summary initial mode | |
255 | ||
3c2f75b5 JH |
256 | diff-tree master |
257 | diff-tree -p master | |
258 | diff-tree -p -m master | |
259 | diff-tree -c master | |
260 | diff-tree -c --abbrev master | |
c2f1d398 | 261 | :noellipses diff-tree -c --abbrev master |
3c2f75b5 | 262 | diff-tree --cc master |
47979d5d JH |
263 | # stat only should show the diffstat with the first parent |
264 | diff-tree -c --stat master | |
265 | diff-tree --cc --stat master | |
266 | diff-tree -c --stat --summary master | |
267 | diff-tree --cc --stat --summary master | |
268 | # stat summary should show the diffstat and summary with the first parent | |
269 | diff-tree -c --stat --summary side | |
270 | diff-tree --cc --stat --summary side | |
8290faa0 | 271 | diff-tree --cc --shortstat master |
04b19fca | 272 | diff-tree --cc --summary REVERSE |
026625e7 JH |
273 | # improved by Timo's patch |
274 | diff-tree --cc --patch-with-stat master | |
275 | # improved by Timo's patch | |
47979d5d JH |
276 | diff-tree --cc --patch-with-stat --summary master |
277 | # this is correct | |
278 | diff-tree --cc --patch-with-stat --summary side | |
3c2f75b5 JH |
279 | |
280 | log master | |
281 | log -p master | |
282 | log --root master | |
283 | log --root -p master | |
284 | log --patch-with-stat master | |
285 | log --root --patch-with-stat master | |
47979d5d | 286 | log --root --patch-with-stat --summary master |
026625e7 | 287 | # improved by Timo's patch |
47979d5d | 288 | log --root -c --patch-with-stat --summary master |
026625e7 | 289 | # improved by Timo's patch |
47979d5d | 290 | log --root --cc --patch-with-stat --summary master |
126f431a JH |
291 | log -p --first-parent master |
292 | log -m -p --first-parent master | |
293 | log -m -p master | |
3c2f75b5 | 294 | log -SF master |
dea007fb | 295 | log -S F master |
47979d5d | 296 | log -SF -p master |
251df09b MM |
297 | log -SF master --max-count=0 |
298 | log -SF master --max-count=1 | |
299 | log -SF master --max-count=2 | |
bf1dfc31 JH |
300 | log -GF master |
301 | log -GF -p master | |
302 | log -GF -p --pickaxe-all master | |
28fd76bd | 303 | log --decorate --all |
33e7018c | 304 | log --decorate=full --all |
3c2f75b5 | 305 | |
fcbc6efc TR |
306 | rev-list --parents HEAD |
307 | rev-list --children HEAD | |
3c2f75b5 JH |
308 | |
309 | whatchanged master | |
c2f1d398 | 310 | :noellipses whatchanged master |
3c2f75b5 JH |
311 | whatchanged -p master |
312 | whatchanged --root master | |
c2f1d398 | 313 | :noellipses whatchanged --root master |
3c2f75b5 JH |
314 | whatchanged --root -p master |
315 | whatchanged --patch-with-stat master | |
316 | whatchanged --root --patch-with-stat master | |
317 | whatchanged --root --patch-with-stat --summary master | |
026625e7 | 318 | # improved by Timo's patch |
47979d5d | 319 | whatchanged --root -c --patch-with-stat --summary master |
026625e7 | 320 | # improved by Timo's patch |
47979d5d | 321 | whatchanged --root --cc --patch-with-stat --summary master |
3c2f75b5 | 322 | whatchanged -SF master |
c2f1d398 | 323 | :noellipses whatchanged -SF master |
47979d5d | 324 | whatchanged -SF -p master |
3c2f75b5 JH |
325 | |
326 | log --patch-with-stat master -- dir/ | |
327 | whatchanged --patch-with-stat master -- dir/ | |
47979d5d JH |
328 | log --patch-with-stat --summary master -- dir/ |
329 | whatchanged --patch-with-stat --summary master -- dir/ | |
3c2f75b5 JH |
330 | |
331 | show initial | |
332 | show --root initial | |
333 | show side | |
334 | show master | |
b4490059 | 335 | show -c master |
2bf65873 JH |
336 | show -m master |
337 | show --first-parent master | |
3c2f75b5 JH |
338 | show --stat side |
339 | show --stat --summary side | |
340 | show --patch-with-stat side | |
341 | show --patch-with-raw side | |
c2f1d398 | 342 | :noellipses show --patch-with-raw side |
3c2f75b5 JH |
343 | show --patch-with-stat --summary side |
344 | ||
d410e43b JH |
345 | format-patch --stdout initial..side |
346 | format-patch --stdout initial..master^ | |
347 | format-patch --stdout initial..master | |
a567fdcb BG |
348 | format-patch --stdout --no-numbered initial..master |
349 | format-patch --stdout --numbered initial..master | |
d410e43b | 350 | format-patch --attach --stdout initial..side |
108dab28 | 351 | format-patch --attach --stdout --suffix=.diff initial..side |
d410e43b JH |
352 | format-patch --attach --stdout initial..master^ |
353 | format-patch --attach --stdout initial..master | |
c112f689 JS |
354 | format-patch --inline --stdout initial..side |
355 | format-patch --inline --stdout initial..master^ | |
747e2505 | 356 | format-patch --inline --stdout --numbered-files initial..master |
a567fdcb | 357 | format-patch --inline --stdout initial..master |
171ddd91 | 358 | format-patch --inline --stdout --subject-prefix=TESTCASE initial..master |
dbd21447 AR |
359 | config format.subjectprefix DIFFERENT_PREFIX |
360 | format-patch --inline --stdout initial..master^^ | |
a5a27c79 | 361 | format-patch --stdout --cover-letter -n initial..master^ |
d410e43b | 362 | |
b319b02e | 363 | diff --abbrev initial..side |
8ef05193 NTND |
364 | diff -U initial..side |
365 | diff -U1 initial..side | |
b319b02e JH |
366 | diff -r initial..side |
367 | diff --stat initial..side | |
368 | diff -r --stat initial..side | |
369 | diff initial..side | |
370 | diff --patch-with-stat initial..side | |
371 | diff --patch-with-raw initial..side | |
c2f1d398 | 372 | :noellipses diff --patch-with-raw initial..side |
b319b02e JH |
373 | diff --patch-with-stat -r initial..side |
374 | diff --patch-with-raw -r initial..side | |
c2f1d398 | 375 | :noellipses diff --patch-with-raw -r initial..side |
3cb56738 | 376 | diff --name-status dir2 dir |
0569e9b8 | 377 | diff --no-index --name-status dir2 dir |
e423ffd8 | 378 | diff --no-index --name-status -- dir2 dir |
d61027b2 | 379 | diff --no-index dir dir3 |
b75271d9 | 380 | diff master master^ side |
660e113c JK |
381 | # Can't use spaces... |
382 | diff --line-prefix=abc master master^ side | |
f37bfb7a | 383 | diff --dirstat master~1 master~2 |
204f01a2 | 384 | diff --dirstat initial rearrange |
0133dab7 | 385 | diff --dirstat-by-file initial rearrange |
dac03b55 | 386 | diff --dirstat --cc master~1 master |
43d1948b JB |
387 | # No-index --abbrev and --no-abbrev |
388 | diff --raw initial | |
c2f1d398 | 389 | :noellipses diff --raw initial |
43d1948b | 390 | diff --raw --abbrev=4 initial |
c2f1d398 | 391 | :noellipses diff --raw --abbrev=4 initial |
43d1948b JB |
392 | diff --raw --no-abbrev initial |
393 | diff --no-index --raw dir2 dir | |
c2f1d398 | 394 | :noellipses diff --no-index --raw dir2 dir |
43d1948b | 395 | diff --no-index --raw --abbrev=4 dir2 dir |
c2f1d398 | 396 | :noellipses diff --no-index --raw --abbrev=4 dir2 dir |
43d1948b | 397 | diff --no-index --raw --no-abbrev dir2 dir |
ddf88fa6 NTND |
398 | |
399 | diff-tree --pretty --root --stat --compact-summary initial | |
400 | diff-tree --pretty -R --root --stat --compact-summary initial | |
401 | diff-tree --stat --compact-summary initial mode | |
402 | diff-tree -R --stat --compact-summary initial mode | |
3c2f75b5 JH |
403 | EOF |
404 | ||
dea007fb MM |
405 | test_expect_success 'log -S requires an argument' ' |
406 | test_must_fail git log -S | |
407 | ' | |
408 | ||
a2b7a3b3 NTND |
409 | test_expect_success 'diff --cached on unborn branch' ' |
410 | echo ref: refs/heads/unborn >.git/HEAD && | |
411 | git diff --cached >result && | |
72f936b1 | 412 | process_diffs result >actual && |
413 | process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected && | |
414 | test_cmp expected actual | |
a2b7a3b3 NTND |
415 | ' |
416 | ||
417 | test_expect_success 'diff --cached -- file on unborn branch' ' | |
418 | git diff --cached -- file0 >result && | |
72f936b1 | 419 | process_diffs result >actual && |
420 | process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected && | |
421 | test_cmp expected actual | |
a2b7a3b3 | 422 | ' |
660e113c JK |
423 | test_expect_success 'diff --line-prefix with spaces' ' |
424 | git diff --line-prefix="| | | " --cached -- file0 >result && | |
72f936b1 | 425 | process_diffs result >actual && |
426 | process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected && | |
427 | test_cmp expected actual | |
660e113c | 428 | ' |
a2b7a3b3 | 429 | |
d299e9e5 JK |
430 | test_expect_success 'diff-tree --stdin with log formatting' ' |
431 | cat >expect <<-\EOF && | |
432 | Side | |
433 | Third | |
434 | Second | |
435 | EOF | |
436 | git rev-list master | git diff-tree --stdin --format=%s -s >actual && | |
437 | test_cmp expect actual | |
438 | ' | |
439 | ||
3c2f75b5 | 440 | test_done |