Skip to content

Commit 5d2a30d

Browse files
committed
Merge branch 'mm/diff-renames-default'
The end-user facing Porcelain level commands like "diff" and "log" now enables the rename detection by default. * mm/diff-renames-default: diff: activate diff.renames by default log: introduce init_log_defaults() t: add tests for diff.renames (true/false/unset) t4001-diff-rename: wrap file creations in a test Documentation/diff-config: fix description of diff.renames
2 parents f66a5bd + 5404c11 commit 5d2a30d

File tree

12 files changed

+131
-46
lines changed

12 files changed

+131
-46
lines changed

Documentation/diff-config.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,13 @@ diff.renameLimit::
108108
detection; equivalent to the 'git diff' option '-l'.
109109

110110
diff.renames::
111-
Tells Git to detect renames. If set to any boolean value, it
112-
will enable basic rename detection. If set to "copies" or
113-
"copy", it will detect copies, as well.
111+
Whether and how Git detects renames. If set to "false",
112+
rename detection is disabled. If set to "true", basic rename
113+
detection is enabled. If set to "copies" or "copy", Git will
114+
detect copies, as well. Defaults to true. Note that this
115+
affects only 'git diff' Porcelain like linkgit:git-diff[1] and
116+
linkgit:git-log[1], and not lower level commands such as
117+
linkgit:git-diff-files[1].
114118

115119
diff.suppressBlankEmpty::
116120
A boolean to inhibit the standard behavior of printing a space

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: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ static int log_line_range_callback(const struct option *option, const char *arg,
100100
return 0;
101101
}
102102

103+
static void init_log_defaults(void)
104+
{
105+
init_grep_defaults();
106+
init_diff_ui_defaults();
107+
}
108+
103109
static void cmd_log_init_defaults(struct rev_info *rev)
104110
{
105111
if (fmt_pretty)
@@ -416,7 +422,7 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
416422
struct rev_info rev;
417423
struct setup_revision_opt opt;
418424

419-
init_grep_defaults();
425+
init_log_defaults();
420426
git_config(git_log_config, NULL);
421427

422428
init_revisions(&rev, prefix);
@@ -527,7 +533,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
527533
struct pathspec match_all;
528534
int i, count, ret = 0;
529535

530-
init_grep_defaults();
536+
init_log_defaults();
531537
git_config(git_log_config, NULL);
532538

533539
memset(&match_all, 0, sizeof(match_all));
@@ -608,7 +614,7 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
608614
struct rev_info rev;
609615
struct setup_revision_opt opt;
610616

611-
init_grep_defaults();
617+
init_log_defaults();
612618
git_config(git_log_config, NULL);
613619

614620
init_revisions(&rev, prefix);
@@ -647,7 +653,7 @@ int cmd_log(int argc, const char **argv, const char *prefix)
647653
struct rev_info rev;
648654
struct setup_revision_opt opt;
649655

650-
init_grep_defaults();
656+
init_log_defaults();
651657
git_config(git_log_config, NULL);
652658

653659
init_revisions(&rev, prefix);
@@ -1280,7 +1286,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
12801286
extra_hdr.strdup_strings = 1;
12811287
extra_to.strdup_strings = 1;
12821288
extra_cc.strdup_strings = 1;
1283-
init_grep_defaults();
1289+
init_log_defaults();
12841290
git_config(git_format_config, NULL);
12851291
init_revisions(&rev, prefix);
12861292
rev.commit_format = CMIT_FMT_EMAIL;

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: 94 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,84 @@ test_description='Test rename detection in diff engine.
99
. ./test-lib.sh
1010
. "$TEST_DIRECTORY"/diff-lib.sh
1111

12-
echo >path0 'Line 1
13-
Line 2
14-
Line 3
15-
Line 4
16-
Line 5
17-
Line 6
18-
Line 7
19-
Line 8
20-
Line 9
21-
Line 10
22-
line 11
23-
Line 12
24-
Line 13
25-
Line 14
26-
Line 15
12+
test_expect_success 'setup' '
13+
cat >path0 <<-\EOF &&
14+
Line 1
15+
Line 2
16+
Line 3
17+
Line 4
18+
Line 5
19+
Line 6
20+
Line 7
21+
Line 8
22+
Line 9
23+
Line 10
24+
line 11
25+
Line 12
26+
Line 13
27+
Line 14
28+
Line 15
29+
EOF
30+
cat >expected <<-\EOF &&
31+
diff --git a/path0 b/path1
32+
rename from path0
33+
rename to path1
34+
--- a/path0
35+
+++ b/path1
36+
@@ -8,7 +8,7 @@ Line 7
37+
Line 8
38+
Line 9
39+
Line 10
40+
-line 11
41+
+Line 11
42+
Line 12
43+
Line 13
44+
Line 14
45+
EOF
46+
cat >no-rename <<-\EOF
47+
diff --git a/path0 b/path0
48+
deleted file mode 100644
49+
index fdbec44..0000000
50+
--- a/path0
51+
+++ /dev/null
52+
@@ -1,15 +0,0 @@
53+
-Line 1
54+
-Line 2
55+
-Line 3
56+
-Line 4
57+
-Line 5
58+
-Line 6
59+
-Line 7
60+
-Line 8
61+
-Line 9
62+
-Line 10
63+
-line 11
64+
-Line 12
65+
-Line 13
66+
-Line 14
67+
-Line 15
68+
diff --git a/path1 b/path1
69+
new file mode 100644
70+
index 0000000..752c50e
71+
--- /dev/null
72+
+++ b/path1
73+
@@ -0,0 +1,15 @@
74+
+Line 1
75+
+Line 2
76+
+Line 3
77+
+Line 4
78+
+Line 5
79+
+Line 6
80+
+Line 7
81+
+Line 8
82+
+Line 9
83+
+Line 10
84+
+Line 11
85+
+Line 12
86+
+Line 13
87+
+Line 14
88+
+Line 15
89+
EOF
2790
'
2891

2992
test_expect_success \
@@ -43,27 +106,27 @@ test_expect_success \
43106
test_expect_success \
44107
'git diff-index -p -M after rename and editing.' \
45108
'git diff-index -p -M $tree >current'
46-
cat >expected <<\EOF
47-
diff --git a/path0 b/path1
48-
rename from path0
49-
rename to path1
50-
--- a/path0
51-
+++ b/path1
52-
@@ -8,7 +8,7 @@ Line 7
53-
Line 8
54-
Line 9
55-
Line 10
56-
-line 11
57-
+Line 11
58-
Line 12
59-
Line 13
60-
Line 14
61-
EOF
109+
62110

63111
test_expect_success \
64112
'validate the output.' \
65113
'compare_diff_patch current expected'
66114

115+
test_expect_success 'test diff.renames=true' '
116+
git -c diff.renames=true diff --cached $tree >current &&
117+
compare_diff_patch current expected
118+
'
119+
120+
test_expect_success 'test diff.renames=false' '
121+
git -c diff.renames=false diff --cached $tree >current &&
122+
compare_diff_patch current no-rename
123+
'
124+
125+
test_expect_success 'test diff.renames unset' '
126+
git diff --cached $tree >current &&
127+
compare_diff_patch current expected
128+
'
129+
67130
test_expect_success 'favour same basenames over different ones' '
68131
cp path1 another-path &&
69132
git add another-path &&

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)