3 test_description
='Test diff indent heuristic.
6 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
7 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 .
"$TEST_DIRECTORY"/lib-diff.sh
12 # Compare two diff outputs. Ignore "index" lines, because we don't
13 # care about SHA-1s or file modes.
15 sed -e "/^index /d" <"$1" >.tmp-1
16 sed -e "/^index /d" <"$2" >.tmp-2
17 test_cmp .tmp-1 .tmp-2
&& rm -f .tmp-1 .tmp-2
20 # Compare blame output using the expectation for a diff as reference.
21 # Only look for the lines coming from non-boundary commits.
23 sed -n -e "1,4d" -e "s/^+//p" <"$1" >.tmp-1
24 sed -ne "s/^[^^][^)]*) *//p" <"$2" >.tmp-2
25 test_cmp .tmp-1 .tmp-2
&& rm -f .tmp-1 .tmp-2
28 test_expect_success
'prepare' '
29 cat <<-\EOF >spaces.txt &&
39 cat <<-\EOF >functions.c &&
51 git add spaces.txt functions.c &&
53 git commit -m initial &&
56 cat <<-\EOF >spaces.txt &&
69 cat <<-\EOF >functions.c &&
86 git add spaces.txt functions.c &&
88 git commit -m initial &&
91 tr "_" " " <<-\EOF >spaces-expect &&
92 diff --git a/spaces.txt b/spaces.txt
106 tr "_" " " <<-\EOF >spaces-compacted-expect &&
107 diff --git a/spaces.txt b/spaces.txt
122 tr "_" " " <<-\EOF >functions-expect &&
123 diff --git a/functions.c b/functions.c
140 tr "_" " " <<-\EOF >functions-compacted-expect
141 diff --git a/functions.c b/functions.c
158 # --- diff tests ----------------------------------------------------------
160 test_expect_success
'diff: ugly spaces' '
161 git diff --no-indent-heuristic old new -- spaces.txt >out &&
162 compare_diff spaces-expect out
165 test_expect_success
'diff: --no-indent-heuristic overrides config' '
166 git -c diff.indentHeuristic=true diff --no-indent-heuristic old new -- spaces.txt >out2 &&
167 compare_diff spaces-expect out2
170 test_expect_success
'diff: nice spaces with --indent-heuristic' '
171 git -c diff.indentHeuristic=false diff --indent-heuristic old new -- spaces.txt >out-compacted &&
172 compare_diff spaces-compacted-expect out-compacted
175 test_expect_success
'diff: nice spaces with diff.indentHeuristic=true' '
176 git -c diff.indentHeuristic=true diff old new -- spaces.txt >out-compacted2 &&
177 compare_diff spaces-compacted-expect out-compacted2
180 test_expect_success
'diff: --indent-heuristic with --patience' '
181 git diff --indent-heuristic --patience old new -- spaces.txt >out-compacted3 &&
182 compare_diff spaces-compacted-expect out-compacted3
185 test_expect_success
'diff: --indent-heuristic with --histogram' '
186 git diff --indent-heuristic --histogram old new -- spaces.txt >out-compacted4 &&
187 compare_diff spaces-compacted-expect out-compacted4
190 test_expect_success
'diff: ugly functions' '
191 git diff --no-indent-heuristic old new -- functions.c >out &&
192 compare_diff functions-expect out
195 test_expect_success
'diff: nice functions with --indent-heuristic' '
196 git diff --indent-heuristic old new -- functions.c >out-compacted &&
197 compare_diff functions-compacted-expect out-compacted
200 # --- blame tests ---------------------------------------------------------
202 test_expect_success
'blame: nice spaces with --indent-heuristic' '
203 git blame --indent-heuristic old..new -- spaces.txt >out-blame-compacted &&
204 compare_blame spaces-compacted-expect out-blame-compacted
207 test_expect_success
'blame: nice spaces with diff.indentHeuristic=true' '
208 git -c diff.indentHeuristic=true blame old..new -- spaces.txt >out-blame-compacted2 &&
209 compare_blame spaces-compacted-expect out-blame-compacted2
212 test_expect_success
'blame: ugly spaces with --no-indent-heuristic' '
213 git blame --no-indent-heuristic old..new -- spaces.txt >out-blame &&
214 compare_blame spaces-expect out-blame
217 test_expect_success
'blame: ugly spaces with diff.indentHeuristic=false' '
218 git -c diff.indentHeuristic=false blame old..new -- spaces.txt >out-blame2 &&
219 compare_blame spaces-expect out-blame2
222 test_expect_success
'blame: --no-indent-heuristic overrides config' '
223 git -c diff.indentHeuristic=true blame --no-indent-heuristic old..new -- spaces.txt >out-blame3 &&
224 git blame old..new -- spaces.txt >out-blame &&
225 compare_blame spaces-expect out-blame3
228 test_expect_success
'blame: --indent-heuristic overrides config' '
229 git -c diff.indentHeuristic=false blame --indent-heuristic old..new -- spaces.txt >out-blame-compacted3 &&
230 compare_blame spaces-compacted-expect out-blame-compacted2
233 # --- diff-tree tests -----------------------------------------------------
235 test_expect_success
'diff-tree: nice spaces with --indent-heuristic' '
236 git diff-tree --indent-heuristic -p old new -- spaces.txt >out-diff-tree-compacted &&
237 compare_diff spaces-compacted-expect out-diff-tree-compacted
240 test_expect_success
'diff-tree: nice spaces with diff.indentHeuristic=true' '
241 git -c diff.indentHeuristic=true diff-tree -p old new -- spaces.txt >out-diff-tree-compacted2 &&
242 compare_diff spaces-compacted-expect out-diff-tree-compacted2
245 test_expect_success
'diff-tree: ugly spaces with --no-indent-heuristic' '
246 git diff-tree --no-indent-heuristic -p old new -- spaces.txt >out-diff-tree &&
247 compare_diff spaces-expect out-diff-tree
250 test_expect_success
'diff-tree: ugly spaces with diff.indentHeuristic=false' '
251 git -c diff.indentHeuristic=false diff-tree -p old new -- spaces.txt >out-diff-tree2 &&
252 compare_diff spaces-expect out-diff-tree2
255 test_expect_success
'diff-tree: --indent-heuristic overrides config' '
256 git -c diff.indentHeuristic=false diff-tree --indent-heuristic -p old new -- spaces.txt >out-diff-tree-compacted3 &&
257 compare_diff spaces-compacted-expect out-diff-tree-compacted3
260 test_expect_success
'diff-tree: --no-indent-heuristic overrides config' '
261 git -c diff.indentHeuristic=true diff-tree --no-indent-heuristic -p old new -- spaces.txt >out-diff-tree3 &&
262 compare_diff spaces-expect out-diff-tree3
265 # --- diff-index tests ----------------------------------------------------
267 test_expect_success
'diff-index: nice spaces with --indent-heuristic' '
268 git checkout -B diff-index &&
269 git reset --soft HEAD~ &&
270 git diff-index --indent-heuristic -p old -- spaces.txt >out-diff-index-compacted &&
271 compare_diff spaces-compacted-expect out-diff-index-compacted &&
275 test_expect_success
'diff-index: nice spaces with diff.indentHeuristic=true' '
276 git checkout -B diff-index &&
277 git reset --soft HEAD~ &&
278 git -c diff.indentHeuristic=true diff-index -p old -- spaces.txt >out-diff-index-compacted2 &&
279 compare_diff spaces-compacted-expect out-diff-index-compacted2 &&
283 test_expect_success
'diff-index: ugly spaces with --no-indent-heuristic' '
284 git checkout -B diff-index &&
285 git reset --soft HEAD~ &&
286 git diff-index --no-indent-heuristic -p old -- spaces.txt >out-diff-index &&
287 compare_diff spaces-expect out-diff-index &&
291 test_expect_success
'diff-index: ugly spaces with diff.indentHeuristic=false' '
292 git checkout -B diff-index &&
293 git reset --soft HEAD~ &&
294 git -c diff.indentHeuristic=false diff-index -p old -- spaces.txt >out-diff-index2 &&
295 compare_diff spaces-expect out-diff-index2 &&
299 test_expect_success
'diff-index: --indent-heuristic overrides config' '
300 git checkout -B diff-index &&
301 git reset --soft HEAD~ &&
302 git -c diff.indentHeuristic=false diff-index --indent-heuristic -p old -- spaces.txt >out-diff-index-compacted3 &&
303 compare_diff spaces-compacted-expect out-diff-index-compacted3 &&
307 test_expect_success
'diff-index: --no-indent-heuristic overrides config' '
308 git checkout -B diff-index &&
309 git reset --soft HEAD~ &&
310 git -c diff.indentHeuristic=true diff-index --no-indent-heuristic -p old -- spaces.txt >out-diff-index3 &&
311 compare_diff spaces-expect out-diff-index3 &&
315 # --- diff-files tests ----------------------------------------------------
317 test_expect_success
'diff-files: nice spaces with --indent-heuristic' '
318 git checkout -B diff-files &&
320 git diff-files --indent-heuristic -p spaces.txt >out-diff-files-raw &&
321 grep -v index out-diff-files-raw >out-diff-files-compacted &&
322 compare_diff spaces-compacted-expect out-diff-files-compacted &&
326 test_expect_success
'diff-files: nice spaces with diff.indentHeuristic=true' '
327 git checkout -B diff-files &&
329 git -c diff.indentHeuristic=true diff-files -p spaces.txt >out-diff-files-raw2 &&
330 grep -v index out-diff-files-raw2 >out-diff-files-compacted2 &&
331 compare_diff spaces-compacted-expect out-diff-files-compacted2 &&
335 test_expect_success
'diff-files: ugly spaces with --no-indent-heuristic' '
336 git checkout -B diff-files &&
338 git diff-files --no-indent-heuristic -p spaces.txt >out-diff-files-raw &&
339 grep -v index out-diff-files-raw >out-diff-files &&
340 compare_diff spaces-expect out-diff-files &&
344 test_expect_success
'diff-files: ugly spaces with diff.indentHeuristic=false' '
345 git checkout -B diff-files &&
347 git -c diff.indentHeuristic=false diff-files -p spaces.txt >out-diff-files-raw2 &&
348 grep -v index out-diff-files-raw2 >out-diff-files &&
349 compare_diff spaces-expect out-diff-files &&
353 test_expect_success
'diff-files: --indent-heuristic overrides config' '
354 git checkout -B diff-files &&
356 git -c diff.indentHeuristic=false diff-files --indent-heuristic -p spaces.txt >out-diff-files-raw3 &&
357 grep -v index out-diff-files-raw3 >out-diff-files-compacted &&
358 compare_diff spaces-compacted-expect out-diff-files-compacted &&
362 test_expect_success
'diff-files: --no-indent-heuristic overrides config' '
363 git checkout -B diff-files &&
365 git -c diff.indentHeuristic=true diff-files --no-indent-heuristic -p spaces.txt >out-diff-files-raw4 &&
366 grep -v index out-diff-files-raw4 >out-diff-files &&
367 compare_diff spaces-expect out-diff-files &&