Skip to content

Commit 0cdca13

Browse files
byanggitster
authored andcommitted
Make git log --follow find copies among unmodified files.
'git log --follow <path>' don't track copies from unmodified files, and this patch fix it. Signed-off-by: Bo Yang <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1da6175 commit 0cdca13

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

Documentation/git-log.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ include::diff-options.txt[]
5656
commits, and doesn't limit diff for those commits.
5757

5858
--follow::
59-
Continue listing the history of a file beyond renames.
59+
Continue listing the history of a file beyond renames/copies.
6060

6161
--log-size::
6262
Before the log message print out its size in bytes. Intended

t/t4205-log-follow-harder-copies.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2010 Bo Yang
4+
#
5+
6+
test_description='Test --follow should always find copies hard in git log.
7+
8+
'
9+
. ./test-lib.sh
10+
. "$TEST_DIRECTORY"/diff-lib.sh
11+
12+
echo >path0 'Line 1
13+
Line 2
14+
Line 3
15+
'
16+
17+
test_expect_success \
18+
'add a file path0 and commit.' \
19+
'git add path0 &&
20+
git commit -m "Add path0"'
21+
22+
echo >path0 'New line 1
23+
New line 2
24+
New line 3
25+
'
26+
test_expect_success \
27+
'Change path0.' \
28+
'git add path0 &&
29+
git commit -m "Change path0"'
30+
31+
cat <path0 >path1
32+
test_expect_success \
33+
'copy path0 to path1.' \
34+
'git add path1 &&
35+
git commit -m "Copy path1 from path0"'
36+
37+
test_expect_success \
38+
'find the copy path0 -> path1 harder' \
39+
'git log --follow --name-status --pretty="format:%s" path1 > current'
40+
41+
cat >expected <<\EOF
42+
Copy path1 from path0
43+
C100 path0 path1
44+
45+
Change path0
46+
M path0
47+
48+
Add path0
49+
A path0
50+
EOF
51+
52+
test_expect_success \
53+
'validate the output.' \
54+
'compare_diff_patch current expected'
55+
56+
test_done

tree-diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
346346

347347
diff_setup(&diff_opts);
348348
DIFF_OPT_SET(&diff_opts, RECURSIVE);
349-
diff_opts.detect_rename = DIFF_DETECT_RENAME;
349+
DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);
350350
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
351351
diff_opts.single_follow = opt->paths[0];
352352
diff_opts.break_opt = opt->break_opt;

0 commit comments

Comments
 (0)