Merge remote-tracking branch 'git-po/master' into git-po-master
[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         # 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
104         git config diff.renames false &&
105
106         git show-branch
107 '
108
109 : <<\EOF
110 ! [initial] Initial
111  * [master] Merge branch 'side'
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
121 EOF
122
123 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
124 while read magic cmd
125 do
126         case "$magic" in
127         '' | '#'*)
128                 continue ;;
129         :*)
130                 magic=${magic#:}
131                 label="$magic-$cmd"
132                 case "$magic" in
133                 noellipses) ;;
134                 *)
135                         BUG "unknown magic $magic" ;;
136                 esac ;;
137         *)
138                 cmd="$magic $cmd" magic=
139                 label="$cmd" ;;
140         esac
141         test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
142         pfx=$(printf "%04d" $test_count)
143         expect="$TEST_DIRECTORY/t4013/diff.$test"
144         actual="$pfx-diff.$test"
145
146         test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
147                 {
148                         echo "$ git $cmd"
149                         case "$magic" in
150                         "")
151                                 GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
152                         noellipses)
153                                 git $cmd ;;
154                         esac |
155                         sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
156                             -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
157                         echo "\$"
158                 } >"$actual" &&
159                 if test -f "$expect"
160                 then
161                         case $cmd in
162                         *format-patch* | *-stat*)
163                                 test_i18ncmp "$expect" "$actual";;
164                         *)
165                                 test_cmp "$expect" "$actual";;
166                         esac &&
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
181 :noellipses diff-tree --root --abbrev initial
182 diff-tree --root -r initial
183 diff-tree --root -r --abbrev initial
184 :noellipses diff-tree --root -r --abbrev initial
185 diff-tree --root -r --abbrev=4 initial
186 :noellipses diff-tree --root -r --abbrev=4 initial
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
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
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
217 # improved by Timo's patch
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
226 diff-tree initial mode
227 diff-tree --stat initial mode
228 diff-tree --summary initial mode
229
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
235 :noellipses diff-tree -c --abbrev master
236 diff-tree --cc master
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
245 diff-tree --cc --shortstat master
246 diff-tree --cc --summary REVERSE
247 # improved by Timo's patch
248 diff-tree --cc --patch-with-stat master
249 # improved by Timo's patch
250 diff-tree --cc --patch-with-stat --summary master
251 # this is correct
252 diff-tree --cc --patch-with-stat --summary side
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
260 log --root --patch-with-stat --summary master
261 # improved by Timo's patch
262 log --root -c --patch-with-stat --summary master
263 # improved by Timo's patch
264 log --root --cc --patch-with-stat --summary master
265 log -p --first-parent master
266 log -m -p --first-parent master
267 log -m -p master
268 log -SF master
269 log -S F master
270 log -SF -p master
271 log -SF master --max-count=0
272 log -SF master --max-count=1
273 log -SF master --max-count=2
274 log -GF master
275 log -GF -p master
276 log -GF -p --pickaxe-all master
277 log --decorate --all
278 log --decorate=full --all
279
280 rev-list --parents HEAD
281 rev-list --children HEAD
282
283 whatchanged master
284 :noellipses whatchanged master
285 whatchanged -p master
286 whatchanged --root master
287 :noellipses whatchanged --root master
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
292 # improved by Timo's patch
293 whatchanged --root -c --patch-with-stat --summary master
294 # improved by Timo's patch
295 whatchanged --root --cc --patch-with-stat --summary master
296 whatchanged -SF master
297 :noellipses whatchanged -SF master
298 whatchanged -SF -p master
299
300 log --patch-with-stat master -- dir/
301 whatchanged --patch-with-stat master -- dir/
302 log --patch-with-stat --summary master -- dir/
303 whatchanged --patch-with-stat --summary master -- dir/
304
305 show initial
306 show --root initial
307 show side
308 show master
309 show -c master
310 show -m master
311 show --first-parent master
312 show --stat side
313 show --stat --summary side
314 show --patch-with-stat side
315 show --patch-with-raw side
316 :noellipses show --patch-with-raw side
317 show --patch-with-stat --summary side
318
319 format-patch --stdout initial..side
320 format-patch --stdout initial..master^
321 format-patch --stdout initial..master
322 format-patch --stdout --no-numbered initial..master
323 format-patch --stdout --numbered initial..master
324 format-patch --attach --stdout initial..side
325 format-patch --attach --stdout --suffix=.diff initial..side
326 format-patch --attach --stdout initial..master^
327 format-patch --attach --stdout initial..master
328 format-patch --inline --stdout initial..side
329 format-patch --inline --stdout initial..master^
330 format-patch --inline --stdout --numbered-files initial..master
331 format-patch --inline --stdout initial..master
332 format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
333 config format.subjectprefix DIFFERENT_PREFIX
334 format-patch --inline --stdout initial..master^^
335 format-patch --stdout --cover-letter -n initial..master^
336
337 diff --abbrev initial..side
338 diff -U initial..side
339 diff -U1 initial..side
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
346 :noellipses diff --patch-with-raw initial..side
347 diff --patch-with-stat -r initial..side
348 diff --patch-with-raw -r initial..side
349 :noellipses diff --patch-with-raw -r initial..side
350 diff --name-status dir2 dir
351 diff --no-index --name-status dir2 dir
352 diff --no-index --name-status -- dir2 dir
353 diff --no-index dir dir3
354 diff master master^ side
355 # Can't use spaces...
356 diff --line-prefix=abc master master^ side
357 diff --dirstat master~1 master~2
358 diff --dirstat initial rearrange
359 diff --dirstat-by-file initial rearrange
360 diff --dirstat --cc master~1 master
361 # No-index --abbrev and --no-abbrev
362 diff --raw initial
363 :noellipses diff --raw initial
364 diff --raw --abbrev=4 initial
365 :noellipses diff --raw --abbrev=4 initial
366 diff --raw --no-abbrev initial
367 diff --no-index --raw dir2 dir
368 :noellipses diff --no-index --raw dir2 dir
369 diff --no-index --raw --abbrev=4 dir2 dir
370 :noellipses diff --no-index --raw --abbrev=4 dir2 dir
371 diff --no-index --raw --no-abbrev dir2 dir
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
377 EOF
378
379 test_expect_success 'log -S requires an argument' '
380         test_must_fail git log -S
381 '
382
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 '
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 '
397
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
408 test_done