]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4013-diff-various.sh
Merge branch 'js/cmake-vs'
[thirdparty/git.git] / t / t4013-diff-various.sh
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 &&
17 mkdir dir2 &&
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 &&
35 git commit -m "Second${LF}${LF}This is the second commit." &&
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
74 mkdir dir3 &&
75 cp dir/sub dir3/sub &&
76 test-tool chmtime +1 dir3/sub &&
77
78 git config log.showroot false &&
79 git commit --amend &&
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
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
98 GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
99 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
100 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
101 git checkout -b note initial &&
102 git update-index --chmod=+x file2 &&
103 git commit -m "update mode (file2)" &&
104 git notes add -m "note" &&
105 git checkout -f master &&
106
107 # Same merge as master, but with parents reversed. Hide it in a
108 # pseudo-ref to avoid impacting tests with --all.
109 commit=$(echo reverse |
110 git commit-tree -p master^2 -p master^1 master^{tree}) &&
111 git update-ref REVERSE $commit &&
112
113 git config diff.renames false &&
114
115 git show-branch
116 '
117
118 : <<\EOF
119 ! [initial] Initial
120 * [master] Merge branch 'side'
121 ! [rearrange] Rearranged lines in dir/sub
122 ! [side] Side
123 ----
124 + [rearrange] Rearranged lines in dir/sub
125 - [master] Merge branch 'side'
126 * + [side] Side
127 * [master^] Third
128 * [master~2] Second
129 +*++ [initial] Initial
130 EOF
131
132 process_diffs () {
133 perl -e '
134 my $oid_length = length($ARGV[0]);
135 my $x40 = "[0-9a-f]{40}";
136 my $xab = "[0-9a-f]{4,16}";
137 my $orx = "[0-9a-f]" x $oid_length;
138
139 sub munge_oid {
140 my ($oid) = @_;
141 my $x;
142
143 return "" unless length $oid;
144
145 if ($oid =~ /^(100644|100755|120000)$/) {
146 return $oid;
147 }
148
149 if ($oid =~ /^0*$/) {
150 $x = "0";
151 } else {
152 $x = "f";
153 }
154
155 if (length($oid) == 40) {
156 return $x x $oid_length;
157 } else {
158 return $x x length($oid);
159 }
160 }
161
162 while (<STDIN>) {
163 s/($orx)/munge_oid($1)/ge;
164 s/From ($x40)( |\))/"From " . munge_oid($1) . $2/ge;
165 s/commit ($x40)($| \(from )($x40?)/"commit " . munge_oid($1) . $2 . munge_oid($3)/ge;
166 s/\b($x40)( |\.\.|$)/munge_oid($1) . $2/ge;
167 s/^($x40)($| )/munge_oid($1) . $2/e;
168 s/($xab)(\.\.|,| |\.\.\.|$)/munge_oid($1) . $2/ge;
169 print;
170 }
171 ' "$ZERO_OID" <"$1"
172 }
173
174 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
175 while read magic cmd
176 do
177 case "$magic" in
178 '' | '#'*)
179 continue ;;
180 :*)
181 magic=${magic#:}
182 label="$magic-$cmd"
183 case "$magic" in
184 noellipses) ;;
185 *)
186 BUG "unknown magic $magic" ;;
187 esac ;;
188 *)
189 cmd="$magic $cmd" magic=
190 label="$cmd" ;;
191 esac
192 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
193 pfx=$(printf "%04d" $test_count)
194 expect="$TEST_DIRECTORY/t4013/diff.$test"
195 actual="$pfx-diff.$test"
196
197 test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
198 {
199 echo "$ git $cmd"
200 case "$magic" in
201 "")
202 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
203 noellipses)
204 git $cmd ;;
205 esac |
206 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
207 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
208 echo "\$"
209 } >"$actual" &&
210 if test -f "$expect"
211 then
212 process_diffs "$actual" >actual &&
213 process_diffs "$expect" >expect &&
214 case $cmd in
215 *format-patch* | *-stat*)
216 test_i18ncmp expect actual;;
217 *)
218 test_cmp expect actual;;
219 esac &&
220 rm -f "$actual" actual expect
221 else
222 # this is to help developing new tests.
223 cp "$actual" "$expect"
224 false
225 fi
226 '
227 done <<\EOF
228 diff-tree initial
229 diff-tree -r initial
230 diff-tree -r --abbrev initial
231 diff-tree -r --abbrev=4 initial
232 diff-tree --root initial
233 diff-tree --root --abbrev initial
234 :noellipses diff-tree --root --abbrev initial
235 diff-tree --root -r initial
236 diff-tree --root -r --abbrev initial
237 :noellipses diff-tree --root -r --abbrev initial
238 diff-tree --root -r --abbrev=4 initial
239 :noellipses diff-tree --root -r --abbrev=4 initial
240 diff-tree -p initial
241 diff-tree --root -p initial
242 diff-tree --root -p --abbrev=10 initial
243 diff-tree --root -p --full-index initial
244 diff-tree --root -p --full-index --abbrev=10 initial
245 diff-tree --patch-with-stat initial
246 diff-tree --root --patch-with-stat initial
247 diff-tree --patch-with-raw initial
248 diff-tree --root --patch-with-raw initial
249
250 diff-tree --pretty initial
251 diff-tree --pretty --root initial
252 diff-tree --pretty -p initial
253 diff-tree --pretty --stat initial
254 diff-tree --pretty --summary initial
255 diff-tree --pretty --stat --summary initial
256 diff-tree --pretty --root -p initial
257 diff-tree --pretty --root --stat initial
258 # improved by Timo's patch
259 diff-tree --pretty --root --summary initial
260 # improved by Timo's patch
261 diff-tree --pretty --root --summary -r initial
262 diff-tree --pretty --root --stat --summary initial
263 diff-tree --pretty --patch-with-stat initial
264 diff-tree --pretty --root --patch-with-stat initial
265 diff-tree --pretty --patch-with-raw initial
266 diff-tree --pretty --root --patch-with-raw initial
267
268 diff-tree --pretty=oneline initial
269 diff-tree --pretty=oneline --root initial
270 diff-tree --pretty=oneline -p initial
271 diff-tree --pretty=oneline --root -p initial
272 diff-tree --pretty=oneline --patch-with-stat initial
273 # improved by Timo's patch
274 diff-tree --pretty=oneline --root --patch-with-stat initial
275 diff-tree --pretty=oneline --patch-with-raw initial
276 diff-tree --pretty=oneline --root --patch-with-raw initial
277
278 diff-tree --pretty side
279 diff-tree --pretty -p side
280 diff-tree --pretty --patch-with-stat side
281
282 diff-tree initial mode
283 diff-tree --stat initial mode
284 diff-tree --summary initial mode
285
286 diff-tree master
287 diff-tree -p master
288 diff-tree -p -m master
289 diff-tree -c master
290 diff-tree -c --abbrev master
291 :noellipses diff-tree -c --abbrev master
292 diff-tree --cc master
293 # stat only should show the diffstat with the first parent
294 diff-tree -c --stat master
295 diff-tree --cc --stat master
296 diff-tree -c --stat --summary master
297 diff-tree --cc --stat --summary master
298 # stat summary should show the diffstat and summary with the first parent
299 diff-tree -c --stat --summary side
300 diff-tree --cc --stat --summary side
301 diff-tree --cc --shortstat master
302 diff-tree --cc --summary REVERSE
303 # improved by Timo's patch
304 diff-tree --cc --patch-with-stat master
305 # improved by Timo's patch
306 diff-tree --cc --patch-with-stat --summary master
307 # this is correct
308 diff-tree --cc --patch-with-stat --summary side
309
310 log master
311 log -p master
312 log --root master
313 log --root -p master
314 log --patch-with-stat master
315 log --root --patch-with-stat master
316 log --root --patch-with-stat --summary master
317 # improved by Timo's patch
318 log --root -c --patch-with-stat --summary master
319 # improved by Timo's patch
320 log --root --cc --patch-with-stat --summary master
321 log --no-diff-merges -p --first-parent master
322 log --diff-merges=off -p --first-parent master
323 log --first-parent --diff-merges=off -p master
324 log -p --first-parent master
325 log -m -p --first-parent master
326 log -m -p master
327 log -SF master
328 log -S F master
329 log -SF -p master
330 log -SF master --max-count=0
331 log -SF master --max-count=1
332 log -SF master --max-count=2
333 log -GF master
334 log -GF -p master
335 log -GF -p --pickaxe-all master
336 log --decorate --all
337 log --decorate=full --all
338
339 rev-list --parents HEAD
340 rev-list --children HEAD
341
342 whatchanged master
343 :noellipses whatchanged master
344 whatchanged -p master
345 whatchanged --root master
346 :noellipses whatchanged --root master
347 whatchanged --root -p master
348 whatchanged --patch-with-stat master
349 whatchanged --root --patch-with-stat master
350 whatchanged --root --patch-with-stat --summary master
351 # improved by Timo's patch
352 whatchanged --root -c --patch-with-stat --summary master
353 # improved by Timo's patch
354 whatchanged --root --cc --patch-with-stat --summary master
355 whatchanged -SF master
356 :noellipses whatchanged -SF master
357 whatchanged -SF -p master
358
359 log --patch-with-stat master -- dir/
360 whatchanged --patch-with-stat master -- dir/
361 log --patch-with-stat --summary master -- dir/
362 whatchanged --patch-with-stat --summary master -- dir/
363
364 show initial
365 show --root initial
366 show side
367 show master
368 show -c master
369 show -m master
370 show --first-parent master
371 show --stat side
372 show --stat --summary side
373 show --patch-with-stat side
374 show --patch-with-raw side
375 :noellipses show --patch-with-raw side
376 show --patch-with-stat --summary side
377
378 format-patch --stdout initial..side
379 format-patch --stdout initial..master^
380 format-patch --stdout initial..master
381 format-patch --stdout --no-numbered initial..master
382 format-patch --stdout --numbered initial..master
383 format-patch --attach --stdout initial..side
384 format-patch --attach --stdout --suffix=.diff initial..side
385 format-patch --attach --stdout initial..master^
386 format-patch --attach --stdout initial..master
387 format-patch --inline --stdout initial..side
388 format-patch --inline --stdout initial..master^
389 format-patch --inline --stdout --numbered-files initial..master
390 format-patch --inline --stdout initial..master
391 format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
392 config format.subjectprefix DIFFERENT_PREFIX
393 format-patch --inline --stdout initial..master^^
394 format-patch --stdout --cover-letter -n initial..master^
395
396 diff --abbrev initial..side
397 diff -U initial..side
398 diff -U1 initial..side
399 diff -r initial..side
400 diff --stat initial..side
401 diff -r --stat initial..side
402 diff initial..side
403 diff --patch-with-stat initial..side
404 diff --patch-with-raw initial..side
405 :noellipses diff --patch-with-raw initial..side
406 diff --patch-with-stat -r initial..side
407 diff --patch-with-raw -r initial..side
408 :noellipses diff --patch-with-raw -r initial..side
409 diff --name-status dir2 dir
410 diff --no-index --name-status dir2 dir
411 diff --no-index --name-status -- dir2 dir
412 diff --no-index dir dir3
413 diff master master^ side
414 # Can't use spaces...
415 diff --line-prefix=abc master master^ side
416 diff --dirstat master~1 master~2
417 diff --dirstat initial rearrange
418 diff --dirstat-by-file initial rearrange
419 diff --dirstat --cc master~1 master
420 # No-index --abbrev and --no-abbrev
421 diff --raw initial
422 :noellipses diff --raw initial
423 diff --raw --abbrev=4 initial
424 :noellipses diff --raw --abbrev=4 initial
425 diff --raw --no-abbrev initial
426 diff --no-index --raw dir2 dir
427 :noellipses diff --no-index --raw dir2 dir
428 diff --no-index --raw --abbrev=4 dir2 dir
429 :noellipses diff --no-index --raw --abbrev=4 dir2 dir
430 diff --no-index --raw --no-abbrev dir2 dir
431
432 diff-tree --pretty --root --stat --compact-summary initial
433 diff-tree --pretty -R --root --stat --compact-summary initial
434 diff-tree --pretty note
435 diff-tree --pretty --notes note
436 diff-tree --format=%N note
437 diff-tree --stat --compact-summary initial mode
438 diff-tree -R --stat --compact-summary initial mode
439 EOF
440
441 test_expect_success 'log -S requires an argument' '
442 test_must_fail git log -S
443 '
444
445 test_expect_success 'diff --cached on unborn branch' '
446 echo ref: refs/heads/unborn >.git/HEAD &&
447 git diff --cached >result &&
448 process_diffs result >actual &&
449 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
450 test_cmp expected actual
451 '
452
453 test_expect_success 'diff --cached -- file on unborn branch' '
454 git diff --cached -- file0 >result &&
455 process_diffs result >actual &&
456 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
457 test_cmp expected actual
458 '
459 test_expect_success 'diff --line-prefix with spaces' '
460 git diff --line-prefix="| | | " --cached -- file0 >result &&
461 process_diffs result >actual &&
462 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
463 test_cmp expected actual
464 '
465
466 test_expect_success 'diff-tree --stdin with log formatting' '
467 cat >expect <<-\EOF &&
468 Side
469 Third
470 Second
471 EOF
472 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
473 test_cmp expect actual
474 '
475
476 test_done