Merge branch 'vn/revision-shorthand-for-side-branch-log'
[git/raj.git] / t / t4061-diff-indent.sh
blob556450609b91873efc966d36f20b84f33425b4dc
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_done