]>
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 | ||
4ff03347 | 123 | V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g') |
b4c02c30 | 124 | while read magic cmd |
3c2f75b5 | 125 | do |
b4c02c30 AR |
126 | case "$magic" in |
127 | '' | '#'*) | |
128 | continue ;; | |
129 | :*) | |
130 | magic=${magic#:} | |
131 | label="$magic-$cmd" | |
132 | case "$magic" in | |
133 | noellipses) ;; | |
134 | *) | |
165293af | 135 | BUG "unknown magic $magic" ;; |
b4c02c30 AR |
136 | esac ;; |
137 | *) | |
138 | cmd="$magic $cmd" magic= | |
139 | label="$cmd" ;; | |
3c2f75b5 | 140 | esac |
b4c02c30 | 141 | test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g') |
4ff03347 | 142 | pfx=$(printf "%04d" $test_count) |
bfdbee98 | 143 | expect="$TEST_DIRECTORY/t4013/diff.$test" |
3c2f75b5 JH |
144 | actual="$pfx-diff.$test" |
145 | ||
de231e57 | 146 | test_expect_success "git $cmd # magic is ${magic:-(not used)}" ' |
3c2f75b5 | 147 | { |
b4c02c30 AR |
148 | echo "$ git $cmd" |
149 | case "$magic" in | |
150 | "") | |
151 | GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;; | |
152 | noellipses) | |
153 | git $cmd ;; | |
154 | esac | | |
6c7f4ceb | 155 | sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \ |
33ee4cfb | 156 | -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/" |
3c2f75b5 JH |
157 | echo "\$" |
158 | } >"$actual" && | |
159 | if test -f "$expect" | |
160 | then | |
6dd88832 JN |
161 | case $cmd in |
162 | *format-patch* | *-stat*) | |
163 | test_i18ncmp "$expect" "$actual";; | |
164 | *) | |
165 | test_cmp "$expect" "$actual";; | |
166 | esac && | |
3c2f75b5 JH |
167 | rm -f "$actual" |
168 | else | |
169 | # this is to help developing new tests. | |
170 | cp "$actual" "$expect" | |
171 | false | |
172 | fi | |
173 | ' | |
174 | done <<\EOF | |
175 | diff-tree initial | |
176 | diff-tree -r initial | |
177 | diff-tree -r --abbrev initial | |
178 | diff-tree -r --abbrev=4 initial | |
179 | diff-tree --root initial | |
180 | diff-tree --root --abbrev initial | |
c2f1d398 | 181 | :noellipses diff-tree --root --abbrev initial |
3c2f75b5 JH |
182 | diff-tree --root -r initial |
183 | diff-tree --root -r --abbrev initial | |
c2f1d398 | 184 | :noellipses diff-tree --root -r --abbrev initial |
3c2f75b5 | 185 | diff-tree --root -r --abbrev=4 initial |
c2f1d398 | 186 | :noellipses diff-tree --root -r --abbrev=4 initial |
3c2f75b5 JH |
187 | diff-tree -p initial |
188 | diff-tree --root -p initial | |
189 | diff-tree --patch-with-stat initial | |
190 | diff-tree --root --patch-with-stat initial | |
191 | diff-tree --patch-with-raw initial | |
192 | diff-tree --root --patch-with-raw initial | |
193 | ||
194 | diff-tree --pretty initial | |
195 | diff-tree --pretty --root initial | |
196 | diff-tree --pretty -p initial | |
197 | diff-tree --pretty --stat initial | |
198 | diff-tree --pretty --summary initial | |
199 | diff-tree --pretty --stat --summary initial | |
200 | diff-tree --pretty --root -p initial | |
201 | diff-tree --pretty --root --stat initial | |
026625e7 JH |
202 | # improved by Timo's patch |
203 | diff-tree --pretty --root --summary initial | |
204 | # improved by Timo's patch | |
205 | diff-tree --pretty --root --summary -r initial | |
3c2f75b5 JH |
206 | diff-tree --pretty --root --stat --summary initial |
207 | diff-tree --pretty --patch-with-stat initial | |
208 | diff-tree --pretty --root --patch-with-stat initial | |
209 | diff-tree --pretty --patch-with-raw initial | |
210 | diff-tree --pretty --root --patch-with-raw initial | |
211 | ||
212 | diff-tree --pretty=oneline initial | |
213 | diff-tree --pretty=oneline --root initial | |
214 | diff-tree --pretty=oneline -p initial | |
215 | diff-tree --pretty=oneline --root -p initial | |
216 | diff-tree --pretty=oneline --patch-with-stat initial | |
026625e7 | 217 | # improved by Timo's patch |
3c2f75b5 JH |
218 | diff-tree --pretty=oneline --root --patch-with-stat initial |
219 | diff-tree --pretty=oneline --patch-with-raw initial | |
220 | diff-tree --pretty=oneline --root --patch-with-raw initial | |
221 | ||
222 | diff-tree --pretty side | |
223 | diff-tree --pretty -p side | |
224 | diff-tree --pretty --patch-with-stat side | |
225 | ||
58aaced4 SB |
226 | diff-tree initial mode |
227 | diff-tree --stat initial mode | |
228 | diff-tree --summary initial mode | |
229 | ||
3c2f75b5 JH |
230 | diff-tree master |
231 | diff-tree -p master | |
232 | diff-tree -p -m master | |
233 | diff-tree -c master | |
234 | diff-tree -c --abbrev master | |
c2f1d398 | 235 | :noellipses diff-tree -c --abbrev master |
3c2f75b5 | 236 | diff-tree --cc master |
47979d5d JH |
237 | # stat only should show the diffstat with the first parent |
238 | diff-tree -c --stat master | |
239 | diff-tree --cc --stat master | |
240 | diff-tree -c --stat --summary master | |
241 | diff-tree --cc --stat --summary master | |
242 | # stat summary should show the diffstat and summary with the first parent | |
243 | diff-tree -c --stat --summary side | |
244 | diff-tree --cc --stat --summary side | |
8290faa0 | 245 | diff-tree --cc --shortstat master |
04b19fca | 246 | diff-tree --cc --summary REVERSE |
026625e7 JH |
247 | # improved by Timo's patch |
248 | diff-tree --cc --patch-with-stat master | |
249 | # improved by Timo's patch | |
47979d5d JH |
250 | diff-tree --cc --patch-with-stat --summary master |
251 | # this is correct | |
252 | diff-tree --cc --patch-with-stat --summary side | |
3c2f75b5 JH |
253 | |
254 | log master | |
255 | log -p master | |
256 | log --root master | |
257 | log --root -p master | |
258 | log --patch-with-stat master | |
259 | log --root --patch-with-stat master | |
47979d5d | 260 | log --root --patch-with-stat --summary master |
026625e7 | 261 | # improved by Timo's patch |
47979d5d | 262 | log --root -c --patch-with-stat --summary master |
026625e7 | 263 | # improved by Timo's patch |
47979d5d | 264 | log --root --cc --patch-with-stat --summary master |
126f431a JH |
265 | log -p --first-parent master |
266 | log -m -p --first-parent master | |
267 | log -m -p master | |
3c2f75b5 | 268 | log -SF master |
dea007fb | 269 | log -S F master |
47979d5d | 270 | log -SF -p master |
251df09b MM |
271 | log -SF master --max-count=0 |
272 | log -SF master --max-count=1 | |
273 | log -SF master --max-count=2 | |
bf1dfc31 JH |
274 | log -GF master |
275 | log -GF -p master | |
276 | log -GF -p --pickaxe-all master | |
28fd76bd | 277 | log --decorate --all |
33e7018c | 278 | log --decorate=full --all |
3c2f75b5 | 279 | |
fcbc6efc TR |
280 | rev-list --parents HEAD |
281 | rev-list --children HEAD | |
3c2f75b5 JH |
282 | |
283 | whatchanged master | |
c2f1d398 | 284 | :noellipses whatchanged master |
3c2f75b5 JH |
285 | whatchanged -p master |
286 | whatchanged --root master | |
c2f1d398 | 287 | :noellipses whatchanged --root master |
3c2f75b5 JH |
288 | whatchanged --root -p master |
289 | whatchanged --patch-with-stat master | |
290 | whatchanged --root --patch-with-stat master | |
291 | whatchanged --root --patch-with-stat --summary master | |
026625e7 | 292 | # improved by Timo's patch |
47979d5d | 293 | whatchanged --root -c --patch-with-stat --summary master |
026625e7 | 294 | # improved by Timo's patch |
47979d5d | 295 | whatchanged --root --cc --patch-with-stat --summary master |
3c2f75b5 | 296 | whatchanged -SF master |
c2f1d398 | 297 | :noellipses whatchanged -SF master |
47979d5d | 298 | whatchanged -SF -p master |
3c2f75b5 JH |
299 | |
300 | log --patch-with-stat master -- dir/ | |
301 | whatchanged --patch-with-stat master -- dir/ | |
47979d5d JH |
302 | log --patch-with-stat --summary master -- dir/ |
303 | whatchanged --patch-with-stat --summary master -- dir/ | |
3c2f75b5 JH |
304 | |
305 | show initial | |
306 | show --root initial | |
307 | show side | |
308 | show master | |
b4490059 | 309 | show -c master |
2bf65873 JH |
310 | show -m master |
311 | show --first-parent master | |
3c2f75b5 JH |
312 | show --stat side |
313 | show --stat --summary side | |
314 | show --patch-with-stat side | |
315 | show --patch-with-raw side | |
c2f1d398 | 316 | :noellipses show --patch-with-raw side |
3c2f75b5 JH |
317 | show --patch-with-stat --summary side |
318 | ||
d410e43b JH |
319 | format-patch --stdout initial..side |
320 | format-patch --stdout initial..master^ | |
321 | format-patch --stdout initial..master | |
a567fdcb BG |
322 | format-patch --stdout --no-numbered initial..master |
323 | format-patch --stdout --numbered initial..master | |
d410e43b | 324 | format-patch --attach --stdout initial..side |
108dab28 | 325 | format-patch --attach --stdout --suffix=.diff initial..side |
d410e43b JH |
326 | format-patch --attach --stdout initial..master^ |
327 | format-patch --attach --stdout initial..master | |
c112f689 JS |
328 | format-patch --inline --stdout initial..side |
329 | format-patch --inline --stdout initial..master^ | |
747e2505 | 330 | format-patch --inline --stdout --numbered-files initial..master |
a567fdcb | 331 | format-patch --inline --stdout initial..master |
171ddd91 | 332 | format-patch --inline --stdout --subject-prefix=TESTCASE initial..master |
dbd21447 AR |
333 | config format.subjectprefix DIFFERENT_PREFIX |
334 | format-patch --inline --stdout initial..master^^ | |
a5a27c79 | 335 | format-patch --stdout --cover-letter -n initial..master^ |
d410e43b | 336 | |
b319b02e | 337 | diff --abbrev initial..side |
8ef05193 NTND |
338 | diff -U initial..side |
339 | diff -U1 initial..side | |
b319b02e JH |
340 | diff -r initial..side |
341 | diff --stat initial..side | |
342 | diff -r --stat initial..side | |
343 | diff initial..side | |
344 | diff --patch-with-stat initial..side | |
345 | diff --patch-with-raw initial..side | |
c2f1d398 | 346 | :noellipses diff --patch-with-raw initial..side |
b319b02e JH |
347 | diff --patch-with-stat -r initial..side |
348 | diff --patch-with-raw -r initial..side | |
c2f1d398 | 349 | :noellipses diff --patch-with-raw -r initial..side |
3cb56738 | 350 | diff --name-status dir2 dir |
0569e9b8 | 351 | diff --no-index --name-status dir2 dir |
e423ffd8 | 352 | diff --no-index --name-status -- dir2 dir |
d61027b2 | 353 | diff --no-index dir dir3 |
b75271d9 | 354 | diff master master^ side |
660e113c JK |
355 | # Can't use spaces... |
356 | diff --line-prefix=abc master master^ side | |
f37bfb7a | 357 | diff --dirstat master~1 master~2 |
204f01a2 | 358 | diff --dirstat initial rearrange |
0133dab7 | 359 | diff --dirstat-by-file initial rearrange |
dac03b55 | 360 | diff --dirstat --cc master~1 master |
43d1948b JB |
361 | # No-index --abbrev and --no-abbrev |
362 | diff --raw initial | |
c2f1d398 | 363 | :noellipses diff --raw initial |
43d1948b | 364 | diff --raw --abbrev=4 initial |
c2f1d398 | 365 | :noellipses diff --raw --abbrev=4 initial |
43d1948b JB |
366 | diff --raw --no-abbrev initial |
367 | diff --no-index --raw dir2 dir | |
c2f1d398 | 368 | :noellipses diff --no-index --raw dir2 dir |
43d1948b | 369 | diff --no-index --raw --abbrev=4 dir2 dir |
c2f1d398 | 370 | :noellipses diff --no-index --raw --abbrev=4 dir2 dir |
43d1948b | 371 | diff --no-index --raw --no-abbrev dir2 dir |
ddf88fa6 NTND |
372 | |
373 | diff-tree --pretty --root --stat --compact-summary initial | |
374 | diff-tree --pretty -R --root --stat --compact-summary initial | |
375 | diff-tree --stat --compact-summary initial mode | |
376 | diff-tree -R --stat --compact-summary initial mode | |
3c2f75b5 JH |
377 | EOF |
378 | ||
dea007fb MM |
379 | test_expect_success 'log -S requires an argument' ' |
380 | test_must_fail git log -S | |
381 | ' | |
382 | ||
a2b7a3b3 NTND |
383 | test_expect_success 'diff --cached on unborn branch' ' |
384 | echo ref: refs/heads/unborn >.git/HEAD && | |
385 | git diff --cached >result && | |
386 | test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached" result | |
387 | ' | |
388 | ||
389 | test_expect_success 'diff --cached -- file on unborn branch' ' | |
390 | git diff --cached -- file0 >result && | |
391 | test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" result | |
392 | ' | |
660e113c JK |
393 | test_expect_success 'diff --line-prefix with spaces' ' |
394 | git diff --line-prefix="| | | " --cached -- file0 >result && | |
395 | test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" result | |
396 | ' | |
a2b7a3b3 | 397 | |
d299e9e5 JK |
398 | test_expect_success 'diff-tree --stdin with log formatting' ' |
399 | cat >expect <<-\EOF && | |
400 | Side | |
401 | Third | |
402 | Second | |
403 | EOF | |
404 | git rev-list master | git diff-tree --stdin --format=%s -s >actual && | |
405 | test_cmp expect actual | |
406 | ' | |
407 | ||
3c2f75b5 | 408 | test_done |