diff: add an internal option to dual-color diffs of diffs
[alt-git.git] / t / t4013-diff-various.sh
blobf8d853595b99bfff64521a502ee062b7e5f35e5f
1 #!/bin/sh
3 # Copyright (c) 2006 Junio C Hamano
6 test_description='Various diff formatting options'
8 . ./test-lib.sh
10 LF='
13 test_expect_success setup '
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 &&
19 mkdir dir &&
20 mkdir dir2 &&
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 &&
27 git branch initial &&
28 git branch side &&
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 &&
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 &&
38 git commit -m "Second${LF}${LF}This is the second commit." &&
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 &&
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 &&
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 &&
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 &&
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 &&
66 git checkout master &&
67 git pull -s ours . side &&
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 &&
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 &&
77 mkdir dir3 &&
78 cp dir/sub dir3/sub &&
79 test-tool chmtime +1 dir3/sub &&
81 git config log.showroot false &&
82 git commit --amend &&
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 &&
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 &&
101 git config diff.renames false &&
103 git show-branch
106 : <<\EOF
107 ! [initial] Initial
108 * [master] Merge branch 'side'
109 ! [rearrange] Rearranged lines in dir/sub
110 ! [side] Side
111 ----
112 + [rearrange] Rearranged lines in dir/sub
113 - [master] Merge branch 'side'
114 * + [side] Side
115 * [master^] Third
116 * [master~2] Second
117 +*++ [initial] Initial
120 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
121 while read magic cmd
123 case "$magic" in
124 '' | '#'*)
125 continue ;;
127 magic=${magic#:}
128 label="$magic-$cmd"
129 case "$magic" in
130 noellipses) ;;
132 die "bug in t4103: unknown magic $magic" ;;
133 esac ;;
135 cmd="$magic $cmd" magic=
136 label="$cmd" ;;
137 esac
138 test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
139 pfx=$(printf "%04d" $test_count)
140 expect="$TEST_DIRECTORY/t4013/diff.$test"
141 actual="$pfx-diff.$test"
143 test_expect_success "git $cmd # magic is ${magic:-"(not used)"}" '
145 echo "$ git $cmd"
146 case "$magic" in
148 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
149 noellipses)
150 git $cmd ;;
151 esac |
152 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
153 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
154 echo "\$"
155 } >"$actual" &&
156 if test -f "$expect"
157 then
158 case $cmd in
159 *format-patch* | *-stat*)
160 test_i18ncmp "$expect" "$actual";;
162 test_cmp "$expect" "$actual";;
163 esac &&
164 rm -f "$actual"
165 else
166 # this is to help developing new tests.
167 cp "$actual" "$expect"
168 false
171 done <<\EOF
172 diff-tree initial
173 diff-tree -r initial
174 diff-tree -r --abbrev initial
175 diff-tree -r --abbrev=4 initial
176 diff-tree --root initial
177 diff-tree --root --abbrev initial
178 :noellipses diff-tree --root --abbrev initial
179 diff-tree --root -r initial
180 diff-tree --root -r --abbrev initial
181 :noellipses diff-tree --root -r --abbrev initial
182 diff-tree --root -r --abbrev=4 initial
183 :noellipses diff-tree --root -r --abbrev=4 initial
184 diff-tree -p initial
185 diff-tree --root -p initial
186 diff-tree --patch-with-stat initial
187 diff-tree --root --patch-with-stat initial
188 diff-tree --patch-with-raw initial
189 diff-tree --root --patch-with-raw initial
191 diff-tree --pretty initial
192 diff-tree --pretty --root initial
193 diff-tree --pretty -p initial
194 diff-tree --pretty --stat initial
195 diff-tree --pretty --summary initial
196 diff-tree --pretty --stat --summary initial
197 diff-tree --pretty --root -p initial
198 diff-tree --pretty --root --stat initial
199 # improved by Timo's patch
200 diff-tree --pretty --root --summary initial
201 # improved by Timo's patch
202 diff-tree --pretty --root --summary -r initial
203 diff-tree --pretty --root --stat --summary initial
204 diff-tree --pretty --patch-with-stat initial
205 diff-tree --pretty --root --patch-with-stat initial
206 diff-tree --pretty --patch-with-raw initial
207 diff-tree --pretty --root --patch-with-raw initial
209 diff-tree --pretty=oneline initial
210 diff-tree --pretty=oneline --root initial
211 diff-tree --pretty=oneline -p initial
212 diff-tree --pretty=oneline --root -p initial
213 diff-tree --pretty=oneline --patch-with-stat initial
214 # improved by Timo's patch
215 diff-tree --pretty=oneline --root --patch-with-stat initial
216 diff-tree --pretty=oneline --patch-with-raw initial
217 diff-tree --pretty=oneline --root --patch-with-raw initial
219 diff-tree --pretty side
220 diff-tree --pretty -p side
221 diff-tree --pretty --patch-with-stat side
223 diff-tree initial mode
224 diff-tree --stat initial mode
225 diff-tree --summary initial mode
227 diff-tree master
228 diff-tree -p master
229 diff-tree -p -m master
230 diff-tree -c master
231 diff-tree -c --abbrev master
232 :noellipses diff-tree -c --abbrev master
233 diff-tree --cc master
234 # stat only should show the diffstat with the first parent
235 diff-tree -c --stat master
236 diff-tree --cc --stat master
237 diff-tree -c --stat --summary master
238 diff-tree --cc --stat --summary master
239 # stat summary should show the diffstat and summary with the first parent
240 diff-tree -c --stat --summary side
241 diff-tree --cc --stat --summary side
242 # improved by Timo's patch
243 diff-tree --cc --patch-with-stat master
244 # improved by Timo's patch
245 diff-tree --cc --patch-with-stat --summary master
246 # this is correct
247 diff-tree --cc --patch-with-stat --summary side
249 log master
250 log -p master
251 log --root master
252 log --root -p master
253 log --patch-with-stat master
254 log --root --patch-with-stat master
255 log --root --patch-with-stat --summary master
256 # improved by Timo's patch
257 log --root -c --patch-with-stat --summary master
258 # improved by Timo's patch
259 log --root --cc --patch-with-stat --summary master
260 log -p --first-parent master
261 log -m -p --first-parent master
262 log -m -p master
263 log -SF master
264 log -S F master
265 log -SF -p master
266 log -SF master --max-count=0
267 log -SF master --max-count=1
268 log -SF master --max-count=2
269 log -GF master
270 log -GF -p master
271 log -GF -p --pickaxe-all master
272 log --decorate --all
273 log --decorate=full --all
275 rev-list --parents HEAD
276 rev-list --children HEAD
278 whatchanged master
279 :noellipses whatchanged master
280 whatchanged -p master
281 whatchanged --root master
282 :noellipses whatchanged --root master
283 whatchanged --root -p master
284 whatchanged --patch-with-stat master
285 whatchanged --root --patch-with-stat master
286 whatchanged --root --patch-with-stat --summary master
287 # improved by Timo's patch
288 whatchanged --root -c --patch-with-stat --summary master
289 # improved by Timo's patch
290 whatchanged --root --cc --patch-with-stat --summary master
291 whatchanged -SF master
292 :noellipses whatchanged -SF master
293 whatchanged -SF -p master
295 log --patch-with-stat master -- dir/
296 whatchanged --patch-with-stat master -- dir/
297 log --patch-with-stat --summary master -- dir/
298 whatchanged --patch-with-stat --summary master -- dir/
300 show initial
301 show --root initial
302 show side
303 show master
304 show -c master
305 show -m master
306 show --first-parent master
307 show --stat side
308 show --stat --summary side
309 show --patch-with-stat side
310 show --patch-with-raw side
311 :noellipses show --patch-with-raw side
312 show --patch-with-stat --summary side
314 format-patch --stdout initial..side
315 format-patch --stdout initial..master^
316 format-patch --stdout initial..master
317 format-patch --stdout --no-numbered initial..master
318 format-patch --stdout --numbered initial..master
319 format-patch --attach --stdout initial..side
320 format-patch --attach --stdout --suffix=.diff initial..side
321 format-patch --attach --stdout initial..master^
322 format-patch --attach --stdout initial..master
323 format-patch --inline --stdout initial..side
324 format-patch --inline --stdout initial..master^
325 format-patch --inline --stdout --numbered-files initial..master
326 format-patch --inline --stdout initial..master
327 format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
328 config format.subjectprefix DIFFERENT_PREFIX
329 format-patch --inline --stdout initial..master^^
330 format-patch --stdout --cover-letter -n initial..master^
332 diff --abbrev initial..side
333 diff -r initial..side
334 diff --stat initial..side
335 diff -r --stat initial..side
336 diff initial..side
337 diff --patch-with-stat initial..side
338 diff --patch-with-raw initial..side
339 :noellipses diff --patch-with-raw initial..side
340 diff --patch-with-stat -r initial..side
341 diff --patch-with-raw -r initial..side
342 :noellipses diff --patch-with-raw -r initial..side
343 diff --name-status dir2 dir
344 diff --no-index --name-status dir2 dir
345 diff --no-index --name-status -- dir2 dir
346 diff --no-index dir dir3
347 diff master master^ side
348 # Can't use spaces...
349 diff --line-prefix=abc master master^ side
350 diff --dirstat master~1 master~2
351 diff --dirstat initial rearrange
352 diff --dirstat-by-file initial rearrange
353 # No-index --abbrev and --no-abbrev
354 diff --raw initial
355 :noellipses diff --raw initial
356 diff --raw --abbrev=4 initial
357 :noellipses diff --raw --abbrev=4 initial
358 diff --raw --no-abbrev initial
359 diff --no-index --raw dir2 dir
360 :noellipses diff --no-index --raw dir2 dir
361 diff --no-index --raw --abbrev=4 dir2 dir
362 :noellipses diff --no-index --raw --abbrev=4 dir2 dir
363 diff --no-index --raw --no-abbrev dir2 dir
365 diff-tree --pretty --root --stat --compact-summary initial
366 diff-tree --pretty -R --root --stat --compact-summary initial
367 diff-tree --stat --compact-summary initial mode
368 diff-tree -R --stat --compact-summary initial mode
371 test_expect_success 'log -S requires an argument' '
372 test_must_fail git log -S
375 test_expect_success 'diff --cached on unborn branch' '
376 echo ref: refs/heads/unborn >.git/HEAD &&
377 git diff --cached >result &&
378 test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached" result
381 test_expect_success 'diff --cached -- file on unborn branch' '
382 git diff --cached -- file0 >result &&
383 test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" result
385 test_expect_success 'diff --line-prefix with spaces' '
386 git diff --line-prefix="| | | " --cached -- file0 >result &&
387 test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" result
390 test_expect_success 'diff-tree --stdin with log formatting' '
391 cat >expect <<-\EOF &&
392 Side
393 Third
394 Second
396 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
397 test_cmp expect actual
400 test_done