refs: convert peel_ref to struct object_id
[git.git] / t / t4061-diff-indent.sh
blob2affd7a100996f93839eec682e4d7381e3ac0b2a
1 #!/bin/sh
3 test_description='Test diff indent heuristic.
6 . ./test-lib.sh
7 . "$TEST_DIRECTORY"/diff-lib.sh
9 # Compare two diff outputs. Ignore "index" lines, because we don't
10 # care about SHA-1s or file modes.
11 compare_diff () {
12 sed -e "/^index /d" <"$1" >.tmp-1
13 sed -e "/^index /d" <"$2" >.tmp-2
14 test_cmp .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
17 # Compare blame output using the expectation for a diff as reference.
18 # Only look for the lines coming from non-boundary commits.
19 compare_blame () {
20 sed -n -e "1,4d" -e "s/^\+//p" <"$1" >.tmp-1
21 sed -ne "s/^[^^][^)]*) *//p" <"$2" >.tmp-2
22 test_cmp .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
25 test_expect_success 'prepare' '
26 cat <<-\EOF >spaces.txt &&
34 EOF
36 cat <<-\EOF >functions.c &&
39 /* function */
40 foo() {
41 foo
46 EOF
48 git add spaces.txt functions.c &&
49 test_tick &&
50 git commit -m initial &&
51 git branch old &&
53 cat <<-\EOF >spaces.txt &&
64 EOF
66 cat <<-\EOF >functions.c &&
69 /* function */
70 bar() {
71 foo
74 /* function */
75 foo() {
76 foo
81 EOF
83 git add spaces.txt functions.c &&
84 test_tick &&
85 git commit -m initial &&
86 git branch new &&
88 tr "_" " " <<-\EOF >spaces-expect &&
89 diff --git a/spaces.txt b/spaces.txt
90 --- a/spaces.txt
91 +++ b/spaces.txt
92 @@ -3,5 +3,8 @@
103 tr "_" " " <<-\EOF >spaces-compacted-expect &&
104 diff --git a/spaces.txt b/spaces.txt
105 --- a/spaces.txt
106 +++ b/spaces.txt
107 @@ -2,6 +2,9 @@
119 tr "_" " " <<-\EOF >functions-expect &&
120 diff --git a/functions.c b/functions.c
121 --- a/functions.c
122 +++ b/functions.c
123 @@ -1,6 +1,11 @@
126 /* function */
127 +bar() {
128 + foo
131 +/* function */
132 foo() {
137 tr "_" " " <<-\EOF >functions-compacted-expect
138 diff --git a/functions.c b/functions.c
139 --- a/functions.c
140 +++ b/functions.c
141 @@ -1,5 +1,10 @@
144 +/* function */
145 +bar() {
146 + foo
149 /* function */
150 foo() {
155 # --- diff tests ----------------------------------------------------------
157 test_expect_success 'diff: ugly spaces' '
158 git diff --no-indent-heuristic old new -- spaces.txt >out &&
159 compare_diff spaces-expect out
162 test_expect_success 'diff: --no-indent-heuristic overrides config' '
163 git -c diff.indentHeuristic=true diff --no-indent-heuristic old new -- spaces.txt >out2 &&
164 compare_diff spaces-expect out2
167 test_expect_success 'diff: nice spaces with --indent-heuristic' '
168 git -c diff.indentHeuristic=false diff --indent-heuristic old new -- spaces.txt >out-compacted &&
169 compare_diff spaces-compacted-expect out-compacted
172 test_expect_success 'diff: nice spaces with diff.indentHeuristic=true' '
173 git -c diff.indentHeuristic=true diff old new -- spaces.txt >out-compacted2 &&
174 compare_diff spaces-compacted-expect out-compacted2
177 test_expect_success 'diff: --indent-heuristic with --patience' '
178 git diff --indent-heuristic --patience old new -- spaces.txt >out-compacted3 &&
179 compare_diff spaces-compacted-expect out-compacted3
182 test_expect_success 'diff: --indent-heuristic with --histogram' '
183 git diff --indent-heuristic --histogram old new -- spaces.txt >out-compacted4 &&
184 compare_diff spaces-compacted-expect out-compacted4
187 test_expect_success 'diff: ugly functions' '
188 git diff --no-indent-heuristic old new -- functions.c >out &&
189 compare_diff functions-expect out
192 test_expect_success 'diff: nice functions with --indent-heuristic' '
193 git diff --indent-heuristic old new -- functions.c >out-compacted &&
194 compare_diff functions-compacted-expect out-compacted
197 # --- blame tests ---------------------------------------------------------
199 test_expect_success 'blame: nice spaces with --indent-heuristic' '
200 git blame --indent-heuristic old..new -- spaces.txt >out-blame-compacted &&
201 compare_blame spaces-compacted-expect out-blame-compacted
204 test_expect_success 'blame: nice spaces with diff.indentHeuristic=true' '
205 git -c diff.indentHeuristic=true blame old..new -- spaces.txt >out-blame-compacted2 &&
206 compare_blame spaces-compacted-expect out-blame-compacted2
209 test_expect_success 'blame: ugly spaces with --no-indent-heuristic' '
210 git blame --no-indent-heuristic old..new -- spaces.txt >out-blame &&
211 compare_blame spaces-expect out-blame
214 test_expect_success 'blame: ugly spaces with diff.indentHeuristic=false' '
215 git -c diff.indentHeuristic=false blame old..new -- spaces.txt >out-blame2 &&
216 compare_blame spaces-expect out-blame2
219 test_expect_success 'blame: --no-indent-heuristic overrides config' '
220 git -c diff.indentHeuristic=true blame --no-indent-heuristic old..new -- spaces.txt >out-blame3 &&
221 git blame old..new -- spaces.txt >out-blame &&
222 compare_blame spaces-expect out-blame3
225 test_expect_success 'blame: --indent-heuristic overrides config' '
226 git -c diff.indentHeuristic=false blame --indent-heuristic old..new -- spaces.txt >out-blame-compacted3 &&
227 compare_blame spaces-compacted-expect out-blame-compacted2
230 # --- diff-tree tests -----------------------------------------------------
232 test_expect_success 'diff-tree: nice spaces with --indent-heuristic' '
233 git diff-tree --indent-heuristic -p old new -- spaces.txt >out-diff-tree-compacted &&
234 compare_diff spaces-compacted-expect out-diff-tree-compacted
237 test_expect_success 'diff-tree: nice spaces with diff.indentHeuristic=true' '
238 git -c diff.indentHeuristic=true diff-tree -p old new -- spaces.txt >out-diff-tree-compacted2 &&
239 compare_diff spaces-compacted-expect out-diff-tree-compacted2
242 test_expect_success 'diff-tree: ugly spaces with --no-indent-heuristic' '
243 git diff-tree --no-indent-heuristic -p old new -- spaces.txt >out-diff-tree &&
244 compare_diff spaces-expect out-diff-tree
247 test_expect_success 'diff-tree: ugly spaces with diff.indentHeuristic=false' '
248 git -c diff.indentHeuristic=false diff-tree -p old new -- spaces.txt >out-diff-tree2 &&
249 compare_diff spaces-expect out-diff-tree2
252 test_expect_success 'diff-tree: --indent-heuristic overrides config' '
253 git -c diff.indentHeuristic=false diff-tree --indent-heuristic -p old new -- spaces.txt >out-diff-tree-compacted3 &&
254 compare_diff spaces-compacted-expect out-diff-tree-compacted3
257 test_expect_success 'diff-tree: --no-indent-heuristic overrides config' '
258 git -c diff.indentHeuristic=true diff-tree --no-indent-heuristic -p old new -- spaces.txt >out-diff-tree3 &&
259 compare_diff spaces-expect out-diff-tree3
262 # --- diff-index tests ----------------------------------------------------
264 test_expect_success 'diff-index: nice spaces with --indent-heuristic' '
265 git checkout -B diff-index &&
266 git reset --soft HEAD~ &&
267 git diff-index --indent-heuristic -p old -- spaces.txt >out-diff-index-compacted &&
268 compare_diff spaces-compacted-expect out-diff-index-compacted &&
269 git checkout -f master
272 test_expect_success 'diff-index: nice spaces with diff.indentHeuristic=true' '
273 git checkout -B diff-index &&
274 git reset --soft HEAD~ &&
275 git -c diff.indentHeuristic=true diff-index -p old -- spaces.txt >out-diff-index-compacted2 &&
276 compare_diff spaces-compacted-expect out-diff-index-compacted2 &&
277 git checkout -f master
280 test_expect_success 'diff-index: ugly spaces with --no-indent-heuristic' '
281 git checkout -B diff-index &&
282 git reset --soft HEAD~ &&
283 git diff-index --no-indent-heuristic -p old -- spaces.txt >out-diff-index &&
284 compare_diff spaces-expect out-diff-index &&
285 git checkout -f master
288 test_expect_success 'diff-index: ugly spaces with diff.indentHeuristic=false' '
289 git checkout -B diff-index &&
290 git reset --soft HEAD~ &&
291 git -c diff.indentHeuristic=false diff-index -p old -- spaces.txt >out-diff-index2 &&
292 compare_diff spaces-expect out-diff-index2 &&
293 git checkout -f master
296 test_expect_success 'diff-index: --indent-heuristic overrides config' '
297 git checkout -B diff-index &&
298 git reset --soft HEAD~ &&
299 git -c diff.indentHeuristic=false diff-index --indent-heuristic -p old -- spaces.txt >out-diff-index-compacted3 &&
300 compare_diff spaces-compacted-expect out-diff-index-compacted3 &&
301 git checkout -f master
304 test_expect_success 'diff-index: --no-indent-heuristic overrides config' '
305 git checkout -B diff-index &&
306 git reset --soft HEAD~ &&
307 git -c diff.indentHeuristic=true diff-index --no-indent-heuristic -p old -- spaces.txt >out-diff-index3 &&
308 compare_diff spaces-expect out-diff-index3 &&
309 git checkout -f master
312 # --- diff-files tests ----------------------------------------------------
314 test_expect_success 'diff-files: nice spaces with --indent-heuristic' '
315 git checkout -B diff-files &&
316 git reset HEAD~ &&
317 git diff-files --indent-heuristic -p spaces.txt >out-diff-files-raw &&
318 grep -v index out-diff-files-raw >out-diff-files-compacted &&
319 compare_diff spaces-compacted-expect out-diff-files-compacted &&
320 git checkout -f master
323 test_expect_success 'diff-files: nice spaces with diff.indentHeuristic=true' '
324 git checkout -B diff-files &&
325 git reset HEAD~ &&
326 git -c diff.indentHeuristic=true diff-files -p spaces.txt >out-diff-files-raw2 &&
327 grep -v index out-diff-files-raw2 >out-diff-files-compacted2 &&
328 compare_diff spaces-compacted-expect out-diff-files-compacted2 &&
329 git checkout -f master
332 test_expect_success 'diff-files: ugly spaces with --no-indent-heuristic' '
333 git checkout -B diff-files &&
334 git reset HEAD~ &&
335 git diff-files --no-indent-heuristic -p spaces.txt >out-diff-files-raw &&
336 grep -v index out-diff-files-raw >out-diff-files &&
337 compare_diff spaces-expect out-diff-files &&
338 git checkout -f master
341 test_expect_success 'diff-files: ugly spaces with diff.indentHeuristic=false' '
342 git checkout -B diff-files &&
343 git reset HEAD~ &&
344 git -c diff.indentHeuristic=false diff-files -p spaces.txt >out-diff-files-raw2 &&
345 grep -v index out-diff-files-raw2 >out-diff-files &&
346 compare_diff spaces-expect out-diff-files &&
347 git checkout -f master
350 test_expect_success 'diff-files: --indent-heuristic overrides config' '
351 git checkout -B diff-files &&
352 git reset HEAD~ &&
353 git -c diff.indentHeuristic=false diff-files --indent-heuristic -p spaces.txt >out-diff-files-raw3 &&
354 grep -v index out-diff-files-raw3 >out-diff-files-compacted &&
355 compare_diff spaces-compacted-expect out-diff-files-compacted &&
356 git checkout -f master
359 test_expect_success 'diff-files: --no-indent-heuristic overrides config' '
360 git checkout -B diff-files &&
361 git reset HEAD~ &&
362 git -c diff.indentHeuristic=true diff-files --no-indent-heuristic -p spaces.txt >out-diff-files-raw4 &&
363 grep -v index out-diff-files-raw4 >out-diff-files &&
364 compare_diff spaces-expect out-diff-files &&
365 git checkout -f master
368 test_done