Skip to content

Commit 5404c11

Browse files
moygitster
authored andcommitted
diff: activate diff.renames by default
Rename detection is a very convenient feature, and new users shouldn't have to dig in the documentation to benefit from it. Potential objections to activating rename detection are that it sometimes fail, and it is sometimes slow. But rename detection is already activated by default in several cases like "git status" and "git merge", so activating diff.renames does not fundamentally change the situation. When the rename detection fails, it now fails consistently between "git diff" and "git status". This setting does not affect plumbing commands, hence well-written scripts will not be affected. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 9501d19 commit 5404c11

File tree

12 files changed

+22
-9
lines changed

12 files changed

+22
-9
lines changed

Documentation/diff-config.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ diff.renames::
111111
Whether and how Git detects renames. If set to "false",
112112
rename detection is disabled. If set to "true", basic rename
113113
detection is enabled. If set to "copies" or "copy", Git will
114-
detect copies, as well. Defaults to false. Note that this
114+
detect copies, as well. Defaults to true. Note that this
115115
affects only 'git diff' Porcelain like linkgit:git-diff[1] and
116116
linkgit:git-log[1], and not lower level commands such as
117117
linkgit:git-diff-files[1].

builtin/commit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ static void status_init_config(struct wt_status *s, config_fn_t fn)
186186
gitmodules_config();
187187
git_config(fn, s);
188188
determine_whence(s);
189+
init_diff_ui_defaults();
189190
s->hints = advice_status_hints; /* must come after git_config() */
190191
}
191192

builtin/diff.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
318318

319319
if (!no_index)
320320
gitmodules_config();
321+
init_diff_ui_defaults();
321322
git_config(git_diff_ui_config, NULL);
322323

323324
init_revisions(&rev, prefix);

builtin/log.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ static int log_line_range_callback(const struct option *option, const char *arg,
103103
static void init_log_defaults(void)
104104
{
105105
init_grep_defaults();
106+
init_diff_ui_defaults();
106107
}
107108

108109
static void cmd_log_init_defaults(struct rev_info *rev)

builtin/merge.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
11871187
else
11881188
head_commit = lookup_commit_or_die(head_sha1, "HEAD");
11891189

1190+
init_diff_ui_defaults();
11901191
git_config(git_merge_config, NULL);
11911192

11921193
if (branch_mergeoptions)

diff.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ long parse_algorithm_value(const char *value)
168168
* never be affected by the setting of diff.renames
169169
* the user happens to have in the configuration file.
170170
*/
171+
void init_diff_ui_defaults(void)
172+
{
173+
diff_detect_rename_default = 1;
174+
}
175+
171176
int git_diff_ui_config(const char *var, const char *value, void *cb)
172177
{
173178
if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {

diff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ extern int parse_long_opt(const char *opt, const char **argv,
266266
const char **optarg);
267267

268268
extern int git_diff_basic_config(const char *var, const char *value, void *cb);
269+
extern void init_diff_ui_defaults(void);
269270
extern int git_diff_ui_config(const char *var, const char *value, void *cb);
270271
extern void diff_setup(struct diff_options *);
271272
extern int diff_opt_parse(struct diff_options *, const char **, int, const char *);

t/t4001-diff-rename.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ test_expect_success 'test diff.renames=false' '
124124

125125
test_expect_success 'test diff.renames unset' '
126126
git diff --cached $tree >current &&
127-
compare_diff_patch current no-rename
127+
compare_diff_patch current expected
128128
'
129129

130130
test_expect_success 'favour same basenames over different ones' '

t/t4013-diff-various.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ test_expect_success setup '
9090
git commit -m "Rearranged lines in dir/sub" &&
9191
git checkout master &&
9292
93+
git config diff.renames false &&
94+
9395
git show-branch
9496
'
9597

t/t4014-format-patch.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ test_expect_success 'cover-letter inherits diff options' '
549549
550550
git mv file foo &&
551551
git commit -m foo &&
552-
git format-patch --cover-letter -1 &&
552+
git format-patch --no-renames --cover-letter -1 &&
553553
check_patch 0000-cover-letter.patch &&
554554
! grep "file => foo .* 0 *\$" 0000-cover-letter.patch &&
555555
git format-patch --cover-letter -1 -M &&
@@ -703,7 +703,7 @@ test_expect_success 'options no longer allowed for format-patch' '
703703

704704
test_expect_success 'format-patch --numstat should produce a patch' '
705705
git format-patch --numstat --stdout master..side > output &&
706-
test 6 = $(grep "^diff --git a/" output | wc -l)'
706+
test 5 = $(grep "^diff --git a/" output | wc -l)'
707707

708708
test_expect_success 'format-patch -- <path>' '
709709
git format-patch master..side -- file 2>error &&

0 commit comments

Comments
 (0)