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' '
30 cat >expected <<-\EOF &&
31 diff --git a/path0 b/path1
36 @@ -8,7 +8,7 @@ Line 7
46 cat >no-rename <<-\EOF
47 diff --git a/path0 b/path0
48 deleted file mode 100644
49 index fdbec44..0000000
68 diff --git a/path1 b/path1
70 index 0000000..752c50e
93 'update-index --add a file.' \
94 'git update-index --add path0'
98 'tree=$(git write-tree) && echo $tree'
100 sed -e 's/line/Line/' <path0 >path1
102 test_expect_success \
103 'renamed and edited the file.' \
104 'git update-index --add --remove path0 path1'
106 test_expect_success \
107 'git diff-index -p -M after rename and editing.' \
108 'git diff-index -p -M $tree >current'
111 test_expect_success \
112 'validate the output.' \
113 'compare_diff_patch current expected'
115 test_expect_success 'test diff.renames=true' '
116 git -c diff.renames=true diff --cached $tree >current &&
117 compare_diff_patch current expected
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
125 test_expect_success 'test diff.renames unset' '
126 git diff --cached $tree >current &&
127 compare_diff_patch current expected
130 test_expect_success 'favour same basenames over different ones' '
131 cp path1 another-path &&
132 git add another-path &&
136 git mv another-path subdir/path1 &&
137 git status | test_i18ngrep "renamed: .*path1 -> subdir/path1"'
139 test_expect_success 'favour same basenames even with minor differences' '
140 git show HEAD:path1 | sed "s/15/16/" > subdir/path1 &&
141 git status | test_i18ngrep "renamed: .*path1 -> subdir/path1"'
143 test_expect_success 'setup for many rename source candidates' '
145 for i in 0 1 2 3 4 5 6 7 8 9;
147 for j in 0 1 2 3 4 5 6 7 8 9;
149 echo "$i$j" >"path$i$j"
154 git commit -m "hundred" &&
155 (cat path1; echo new) >new-path &&
157 git add new-path path1 &&
158 git diff -l 4 -C -C --cached --name-status >actual 2>actual.err &&
159 sed -e "s/^\([CM]\)[0-9]* /\1 /" actual >actual.munged &&
160 cat >expect <<-EOF &&
164 test_cmp expect actual.munged &&
165 grep warning actual.err
168 test_expect_success 'rename pretty print with nothing in common' '
172 git commit -m "create a/b/c" &&
174 git mv a/b/c c/b/a &&
175 git commit -m "a/b/c -> c/b/a" &&
176 git diff -M --summary HEAD^ HEAD >output &&
177 test_i18ngrep " a/b/c => c/b/a " output &&
178 git diff -M --stat HEAD^ HEAD >output &&
179 test_i18ngrep " a/b/c => c/b/a " output
182 test_expect_success 'rename pretty print with common prefix' '
184 git mv c/b/a c/d/e &&
185 git commit -m "c/b/a -> c/d/e" &&
186 git diff -M --summary HEAD^ HEAD >output &&
187 test_i18ngrep " c/{b/a => d/e} " output &&
188 git diff -M --stat HEAD^ HEAD >output &&
189 test_i18ngrep " c/{b/a => d/e} " output
192 test_expect_success 'rename pretty print with common suffix' '
195 git commit -m "c/d/e -> d/e" &&
196 git diff -M --summary HEAD^ HEAD >output &&
197 test_i18ngrep " {c/d => d}/e " output &&
198 git diff -M --stat HEAD^ HEAD >output &&
199 test_i18ngrep " {c/d => d}/e " output
202 test_expect_success 'rename pretty print with common prefix and suffix' '
205 git commit -m "d/e -> d/f/e" &&
206 git diff -M --summary HEAD^ HEAD >output &&
207 test_i18ngrep " d/{ => f}/e " output &&
208 git diff -M --stat HEAD^ HEAD >output &&
209 test_i18ngrep " d/{ => f}/e " output
212 test_expect_success 'rename pretty print common prefix and suffix overlap' '
214 git mv d/f/e d/f/f/e &&
215 git commit -m "d/f/e d/f/f/e" &&
216 git diff -M --summary HEAD^ HEAD >output &&
217 test_i18ngrep " d/f/{ => f}/e " output &&
218 git diff -M --stat HEAD^ HEAD >output &&
219 test_i18ngrep " d/f/{ => f}/e " output