Skip to content

Commit 37590ce

Browse files
marcnarcgitster
authored andcommitted
diff: have the diff-* builtins configure diff before initializing revisions
This matches how the diff Porcelain works. It makes the plumbing commands respect diff's configuration options, such as indentHeuristic, because init_revisions() calls diff_setup() which fills in the diff_options struct. Signed-off-by: Marc Branchaud <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cf5e772 commit 37590ce

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

builtin/diff-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
2020
int result;
2121
unsigned options = 0;
2222

23+
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
2324
init_revisions(&rev, prefix);
2425
gitmodules_config();
25-
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
2626
rev.abbrev = 0;
2727
precompose_argv(argc, argv);
2828

builtin/diff-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
1717
int i;
1818
int result;
1919

20+
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
2021
init_revisions(&rev, prefix);
2122
gitmodules_config();
22-
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
2323
rev.abbrev = 0;
2424
precompose_argv(argc, argv);
2525

builtin/diff-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
105105
struct setup_revision_opt s_r_opt;
106106
int read_stdin = 0;
107107

108+
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
108109
init_revisions(opt, prefix);
109110
gitmodules_config();
110-
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
111111
opt->abbrev = 0;
112112
opt->diff = 1;
113113
opt->disable_stdin = 1;

t/t4061-diff-indent.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,70 @@ test_expect_success 'blame: --no-indent-heuristic overrides config' '
213213
compare_blame spaces-expect out-blame2
214214
'
215215

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
219+
'
220+
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
224+
'
225+
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
229+
'
230+
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
237+
'
238+
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
245+
'
246+
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
253+
'
254+
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
262+
'
263+
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
271+
'
272+
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
280+
'
281+
216282
test_done

0 commit comments

Comments
 (0)