unpack-trees: release oid_array after use in check_updates()
[alt-git.git] / t / t4013-diff-various.sh
blobc515e3e53feef29fd6c7434e13d52b3ea913e167
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-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 cmd
123 case "$cmd" in
124 '' | '#'*) continue ;;
125 esac
126 test=$(echo "$cmd" | sed -e 's|[/ ][/ ]*|_|g')
127 pfx=$(printf "%04d" $test_count)
128 expect="$TEST_DIRECTORY/t4013/diff.$test"
129 actual="$pfx-diff.$test"
131 test_expect_success "git $cmd" '
133 echo "\$ git $cmd"
134 git $cmd |
135 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
136 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
137 echo "\$"
138 } >"$actual" &&
139 if test -f "$expect"
140 then
141 case $cmd in
142 *format-patch* | *-stat*)
143 test_i18ncmp "$expect" "$actual";;
145 test_cmp "$expect" "$actual";;
146 esac &&
147 rm -f "$actual"
148 else
149 # this is to help developing new tests.
150 cp "$actual" "$expect"
151 false
154 done <<\EOF
155 diff-tree initial
156 diff-tree -r initial
157 diff-tree -r --abbrev initial
158 diff-tree -r --abbrev=4 initial
159 diff-tree --root initial
160 diff-tree --root --abbrev initial
161 diff-tree --root -r initial
162 diff-tree --root -r --abbrev initial
163 diff-tree --root -r --abbrev=4 initial
164 diff-tree -p initial
165 diff-tree --root -p initial
166 diff-tree --patch-with-stat initial
167 diff-tree --root --patch-with-stat initial
168 diff-tree --patch-with-raw initial
169 diff-tree --root --patch-with-raw initial
171 diff-tree --pretty initial
172 diff-tree --pretty --root initial
173 diff-tree --pretty -p initial
174 diff-tree --pretty --stat initial
175 diff-tree --pretty --summary initial
176 diff-tree --pretty --stat --summary initial
177 diff-tree --pretty --root -p initial
178 diff-tree --pretty --root --stat initial
179 # improved by Timo's patch
180 diff-tree --pretty --root --summary initial
181 # improved by Timo's patch
182 diff-tree --pretty --root --summary -r initial
183 diff-tree --pretty --root --stat --summary initial
184 diff-tree --pretty --patch-with-stat initial
185 diff-tree --pretty --root --patch-with-stat initial
186 diff-tree --pretty --patch-with-raw initial
187 diff-tree --pretty --root --patch-with-raw initial
189 diff-tree --pretty=oneline initial
190 diff-tree --pretty=oneline --root initial
191 diff-tree --pretty=oneline -p initial
192 diff-tree --pretty=oneline --root -p initial
193 diff-tree --pretty=oneline --patch-with-stat initial
194 # improved by Timo's patch
195 diff-tree --pretty=oneline --root --patch-with-stat initial
196 diff-tree --pretty=oneline --patch-with-raw initial
197 diff-tree --pretty=oneline --root --patch-with-raw initial
199 diff-tree --pretty side
200 diff-tree --pretty -p side
201 diff-tree --pretty --patch-with-stat side
203 diff-tree initial mode
204 diff-tree --stat initial mode
205 diff-tree --summary initial mode
207 diff-tree master
208 diff-tree -p master
209 diff-tree -p -m master
210 diff-tree -c master
211 diff-tree -c --abbrev master
212 diff-tree --cc master
213 # stat only should show the diffstat with the first parent
214 diff-tree -c --stat master
215 diff-tree --cc --stat master
216 diff-tree -c --stat --summary master
217 diff-tree --cc --stat --summary master
218 # stat summary should show the diffstat and summary with the first parent
219 diff-tree -c --stat --summary side
220 diff-tree --cc --stat --summary side
221 # improved by Timo's patch
222 diff-tree --cc --patch-with-stat master
223 # improved by Timo's patch
224 diff-tree --cc --patch-with-stat --summary master
225 # this is correct
226 diff-tree --cc --patch-with-stat --summary side
228 log master
229 log -p master
230 log --root master
231 log --root -p master
232 log --patch-with-stat master
233 log --root --patch-with-stat master
234 log --root --patch-with-stat --summary master
235 # improved by Timo's patch
236 log --root -c --patch-with-stat --summary master
237 # improved by Timo's patch
238 log --root --cc --patch-with-stat --summary master
239 log -p --first-parent master
240 log -m -p --first-parent master
241 log -m -p master
242 log -SF master
243 log -S F master
244 log -SF -p master
245 log -SF master --max-count=0
246 log -SF master --max-count=1
247 log -SF master --max-count=2
248 log -GF master
249 log -GF -p master
250 log -GF -p --pickaxe-all master
251 log --decorate --all
252 log --decorate=full --all
254 rev-list --parents HEAD
255 rev-list --children HEAD
257 whatchanged master
258 whatchanged -p master
259 whatchanged --root master
260 whatchanged --root -p master
261 whatchanged --patch-with-stat master
262 whatchanged --root --patch-with-stat master
263 whatchanged --root --patch-with-stat --summary master
264 # improved by Timo's patch
265 whatchanged --root -c --patch-with-stat --summary master
266 # improved by Timo's patch
267 whatchanged --root --cc --patch-with-stat --summary master
268 whatchanged -SF master
269 whatchanged -SF -p master
271 log --patch-with-stat master -- dir/
272 whatchanged --patch-with-stat master -- dir/
273 log --patch-with-stat --summary master -- dir/
274 whatchanged --patch-with-stat --summary master -- dir/
276 show initial
277 show --root initial
278 show side
279 show master
280 show -c master
281 show -m master
282 show --first-parent master
283 show --stat side
284 show --stat --summary side
285 show --patch-with-stat side
286 show --patch-with-raw side
287 show --patch-with-stat --summary side
289 format-patch --stdout initial..side
290 format-patch --stdout initial..master^
291 format-patch --stdout initial..master
292 format-patch --stdout --no-numbered initial..master
293 format-patch --stdout --numbered initial..master
294 format-patch --attach --stdout initial..side
295 format-patch --attach --stdout --suffix=.diff initial..side
296 format-patch --attach --stdout initial..master^
297 format-patch --attach --stdout initial..master
298 format-patch --inline --stdout initial..side
299 format-patch --inline --stdout initial..master^
300 format-patch --inline --stdout --numbered-files initial..master
301 format-patch --inline --stdout initial..master
302 format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
303 config format.subjectprefix DIFFERENT_PREFIX
304 format-patch --inline --stdout initial..master^^
305 format-patch --stdout --cover-letter -n initial..master^
307 diff --abbrev initial..side
308 diff -r initial..side
309 diff --stat initial..side
310 diff -r --stat initial..side
311 diff initial..side
312 diff --patch-with-stat initial..side
313 diff --patch-with-raw initial..side
314 diff --patch-with-stat -r initial..side
315 diff --patch-with-raw -r initial..side
316 diff --name-status dir2 dir
317 diff --no-index --name-status dir2 dir
318 diff --no-index --name-status -- dir2 dir
319 diff --no-index dir dir3
320 diff master master^ side
321 # Can't use spaces...
322 diff --line-prefix=abc master master^ side
323 diff --dirstat master~1 master~2
324 diff --dirstat initial rearrange
325 diff --dirstat-by-file initial rearrange
326 # No-index --abbrev and --no-abbrev
327 diff --raw initial
328 diff --raw --abbrev=4 initial
329 diff --raw --no-abbrev initial
330 diff --no-index --raw dir2 dir
331 diff --no-index --raw --abbrev=4 dir2 dir
332 diff --no-index --raw --no-abbrev dir2 dir
335 test_expect_success 'log -S requires an argument' '
336 test_must_fail git log -S
339 test_expect_success 'diff --cached on unborn branch' '
340 echo ref: refs/heads/unborn >.git/HEAD &&
341 git diff --cached >result &&
342 test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached" result
345 test_expect_success 'diff --cached -- file on unborn branch' '
346 git diff --cached -- file0 >result &&
347 test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" result
349 test_expect_success 'diff --line-prefix with spaces' '
350 git diff --line-prefix="| | | " --cached -- file0 >result &&
351 test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" result
354 test_expect_success 'diff-tree --stdin with log formatting' '
355 cat >expect <<-\EOF &&
356 Side
357 Third
358 Second
360 git rev-list master | git diff-tree --stdin --format=%s -s >actual &&
361 test_cmp expect actual
364 test_done