3 test_description='Test diff indent heuristic.
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.
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.
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 &&
36 cat <<-\EOF >functions.c &&
48 git add spaces.txt functions.c &&
50 git commit -m initial &&
53 cat <<-\EOF >spaces.txt &&
66 cat <<-\EOF >functions.c &&
83 git add spaces.txt functions.c &&
85 git commit -m initial &&
88 tr "_" " " <<-\EOF >spaces-expect &&
89 diff --git a/spaces.txt b/spaces.txt
103 tr "_" " " <<-\EOF >spaces-compacted-expect &&
104 diff --git a/spaces.txt b/spaces.txt
119 tr "_" " " <<-\EOF >functions-expect &&
120 diff --git a/functions.c b/functions.c
137 tr "_" " " <<-\EOF >functions-compacted-expect
138 diff --git a/functions.c b/functions.c
155 test_expect_success 'diff: ugly spaces' '
156 git diff old new -- spaces.txt >out &&
157 compare_diff spaces-expect out
160 test_expect_success 'diff: nice spaces with --indent-heuristic' '
161 git diff --indent-heuristic old new -- spaces.txt >out-compacted &&
162 compare_diff spaces-compacted-expect out-compacted
165 test_expect_success 'diff: nice spaces with diff.indentHeuristic' '
166 git -c diff.indentHeuristic=true diff old new -- spaces.txt >out-compacted2 &&
167 compare_diff spaces-compacted-expect out-compacted2
170 test_expect_success 'diff: --no-indent-heuristic overrides config' '
171 git -c diff.indentHeuristic=true diff --no-indent-heuristic old new -- spaces.txt >out2 &&
172 compare_diff spaces-expect out2
175 test_expect_success 'diff: --indent-heuristic with --patience' '
176 git diff --indent-heuristic --patience old new -- spaces.txt >out-compacted3 &&
177 compare_diff spaces-compacted-expect out-compacted3
180 test_expect_success 'diff: --indent-heuristic with --histogram' '
181 git diff --indent-heuristic --histogram old new -- spaces.txt >out-compacted4 &&
182 compare_diff spaces-compacted-expect out-compacted4
185 test_expect_success 'diff: ugly functions' '
186 git diff old new -- functions.c >out &&
187 compare_diff functions-expect out
190 test_expect_success 'diff: nice functions with --indent-heuristic' '
191 git diff --indent-heuristic old new -- functions.c >out-compacted &&
192 compare_diff functions-compacted-expect out-compacted
195 test_expect_success 'blame: ugly spaces' '
196 git blame old..new -- spaces.txt >out-blame &&
197 compare_blame spaces-expect out-blame
200 test_expect_success 'blame: nice spaces with --indent-heuristic' '
201 git blame --indent-heuristic old..new -- spaces.txt >out-blame-compacted &&
202 compare_blame spaces-compacted-expect out-blame-compacted
205 test_expect_success 'blame: nice spaces with diff.indentHeuristic' '
206 git -c diff.indentHeuristic=true blame old..new -- spaces.txt >out-blame-compacted2 &&
207 compare_blame spaces-compacted-expect out-blame-compacted2
210 test_expect_success 'blame: --no-indent-heuristic overrides config' '
211 git -c diff.indentHeuristic=true blame --no-indent-heuristic old..new -- spaces.txt >out-blame2 &&
212 git blame old..new -- spaces.txt >out-blame &&
213 compare_blame spaces-expect out-blame2