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