3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='Test rename detection in diff engine.
10 .
"$TEST_DIRECTORY"/diff-lib.sh
12 test_expect_success
'setup' '
31 diff --git a/path0 b/path1
36 @@ -8,7 +8,7 @@ Line 7
49 'update-index --add a file.' \
50 'git update-index --add path0'
54 'tree=$(git write-tree) && echo $tree'
56 sed -e 's/line/Line/' <path0
>path1
59 'renamed and edited the file.' \
60 'git update-index --add --remove path0 path1'
63 'git diff-index -p -M after rename and editing.' \
64 'git diff-index -p -M $tree >current'
68 'validate the output.' \
69 'compare_diff_patch current expected'
71 test_expect_success
'favour same basenames over different ones' '
72 cp path1 another-path &&
73 git add another-path &&
77 git mv another-path subdir/path1 &&
78 git status | test_i18ngrep "renamed: .*path1 -> subdir/path1"'
80 test_expect_success
'favour same basenames even with minor differences' '
81 git show HEAD:path1 | sed "s/15/16/" > subdir/path1 &&
82 git status | test_i18ngrep "renamed: .*path1 -> subdir/path1"'
84 test_expect_success
'setup for many rename source candidates' '
86 for i in 0 1 2 3 4 5 6 7 8 9;
88 for j in 0 1 2 3 4 5 6 7 8 9;
90 echo "$i$j" >"path$i$j"
95 git commit -m "hundred" &&
96 (cat path1; echo new) >new-path &&
98 git add new-path path1 &&
99 git diff -l 4 -C -C --cached --name-status >actual 2>actual.err &&
100 sed -e "s/^\([CM]\)[0-9]* /\1 /" actual >actual.munged &&
101 cat >expect <<-EOF &&
105 test_cmp expect actual.munged &&
106 grep warning actual.err
109 test_expect_success
'rename pretty print with nothing in common' '
113 git commit -m "create a/b/c" &&
115 git mv a/b/c c/b/a &&
116 git commit -m "a/b/c -> c/b/a" &&
117 git diff -M --summary HEAD^ HEAD >output &&
118 test_i18ngrep " a/b/c => c/b/a " output &&
119 git diff -M --stat HEAD^ HEAD >output &&
120 test_i18ngrep " a/b/c => c/b/a " output
123 test_expect_success
'rename pretty print with common prefix' '
125 git mv c/b/a c/d/e &&
126 git commit -m "c/b/a -> c/d/e" &&
127 git diff -M --summary HEAD^ HEAD >output &&
128 test_i18ngrep " c/{b/a => d/e} " output &&
129 git diff -M --stat HEAD^ HEAD >output &&
130 test_i18ngrep " c/{b/a => d/e} " output
133 test_expect_success
'rename pretty print with common suffix' '
136 git commit -m "c/d/e -> d/e" &&
137 git diff -M --summary HEAD^ HEAD >output &&
138 test_i18ngrep " {c/d => d}/e " output &&
139 git diff -M --stat HEAD^ HEAD >output &&
140 test_i18ngrep " {c/d => d}/e " output
143 test_expect_success
'rename pretty print with common prefix and suffix' '
146 git commit -m "d/e -> d/f/e" &&
147 git diff -M --summary HEAD^ HEAD >output &&
148 test_i18ngrep " d/{ => f}/e " output &&
149 git diff -M --stat HEAD^ HEAD >output &&
150 test_i18ngrep " d/{ => f}/e " output
153 test_expect_success
'rename pretty print common prefix and suffix overlap' '
155 git mv d/f/e d/f/f/e &&
156 git commit -m "d/f/e d/f/f/e" &&
157 git diff -M --summary HEAD^ HEAD >output &&
158 test_i18ngrep " d/f/{ => f}/e " output &&
159 git diff -M --stat HEAD^ HEAD >output &&
160 test_i18ngrep " d/f/{ => f}/e " output