diff: have the diff-* builtins configure diff before initializing revisions
[git.git] / t / t4061-diff-indent.sh
blob13d3dc96a009755838c424ac9ade3ccfaba0a51d
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 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
216 test_expect_success 'diff-tree: nice spaces with --indent-heuristic' '
217 git diff-tree --indent-heuristic -p old new -- spaces.txt >out-diff-tree-compacted &&
218 compare_diff spaces-compacted-expect out-diff-tree-compacted
221 test_expect_success 'diff-tree: nice spaces with diff.indentHeuristic' '
222 git -c diff.indentHeuristic=true diff-tree -p old new -- spaces.txt >out-diff-tree-compacted2 &&
223 compare_diff spaces-compacted-expect out-diff-tree-compacted2
226 test_expect_success 'diff-tree: --no-indent-heuristic overrides config' '
227 git -c diff.indentHeuristic=true diff-tree --no-indent-heuristic -p old new -- spaces.txt >out-diff-tree &&
228 compare_diff spaces-expect out-diff-tree
231 test_expect_success 'diff-index: nice spaces with --indent-heuristic' '
232 git checkout -B diff-index &&
233 git reset --soft HEAD~ &&
234 git diff-index --indent-heuristic -p old -- spaces.txt >out-diff-index-compacted &&
235 compare_diff spaces-compacted-expect out-diff-index-compacted &&
236 git checkout -f master
239 test_expect_success 'diff-index: nice spaces with diff.indentHeuristic' '
240 git checkout -B diff-index &&
241 git reset --soft HEAD~ &&
242 git -c diff.indentHeuristic=true diff-index -p old -- spaces.txt >out-diff-index-compacted2 &&
243 compare_diff spaces-compacted-expect out-diff-index-compacted2 &&
244 git checkout -f master
247 test_expect_success 'diff-index: --no-indent-heuristic overrides config' '
248 git checkout -B diff-index &&
249 git reset --soft HEAD~ &&
250 git -c diff.indentHeuristic=true diff-index --no-indent-heuristic -p old -- spaces.txt >out-diff-index &&
251 compare_diff spaces-expect out-diff-index &&
252 git checkout -f master
255 test_expect_success 'diff-files: nice spaces with diff.indentHeuristic' '
256 git checkout -B diff-files &&
257 git reset HEAD~ &&
258 git -c diff.indentHeuristic=true diff-files -p spaces.txt >out-diff-files-raw &&
259 grep -v index out-diff-files-raw >out-diff-files-compacted &&
260 compare_diff spaces-compacted-expect out-diff-files-compacted &&
261 git checkout -f master
264 test_expect_success 'diff-files: nice spaces with diff.indentHeuristic' '
265 git checkout -B diff-files &&
266 git reset HEAD~ &&
267 git -c diff.indentHeuristic=true diff-files -p spaces.txt >out-diff-files-raw2 &&
268 grep -v index out-diff-files-raw2 >out-diff-files-compacted2 &&
269 compare_diff spaces-compacted-expect out-diff-files-compacted2 &&
270 git checkout -f master
273 test_expect_success 'diff-files: --no-indent-heuristic overrides config' '
274 git checkout -B diff-files &&
275 git reset HEAD~ &&
276 git -c diff.indentHeuristic=true diff-files --no-indent-heuristic -p spaces.txt >out-diff-files-raw3 &&
277 grep -v index out-diff-files-raw3 >out-diff-files &&
278 compare_diff spaces-expect out-diff-files &&
279 git checkout -f master
282 test_done