]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4001-diff-rename.sh
test-lib: make "-x" work with "--verbose-log"
[thirdparty/git.git] / t / t4001-diff-rename.sh
CommitLineData
5c97558c
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='Test rename detection in diff engine.
7
8'
9. ./test-lib.sh
bfdbee98 10. "$TEST_DIRECTORY"/diff-lib.sh
5c97558c 11
f07fc9e7
MM
12test_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
a9276a69 30 cat >expected <<-\EOF &&
f07fc9e7
MM
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
a9276a69
MM
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
5c97558c
JH
90'
91
92test_expect_success \
10455d2a 93 'update-index --add a file.' \
5be60078 94 'git update-index --add path0'
5c97558c
JH
95
96test_expect_success \
97 'write that tree.' \
5be60078 98 'tree=$(git write-tree) && echo $tree'
5c97558c
JH
99
100sed -e 's/line/Line/' <path0 >path1
101rm -f path0
102test_expect_success \
103 'renamed and edited the file.' \
5be60078 104 'git update-index --add --remove path0 path1'
5c97558c
JH
105
106test_expect_success \
5be60078
JH
107 'git diff-index -p -M after rename and editing.' \
108 'git diff-index -p -M $tree >current'
f07fc9e7 109
57fe64a4
JH
110
111test_expect_success \
112 'validate the output.' \
ec1fcc16 113 'compare_diff_patch current expected'
57fe64a4 114
a9276a69
MM
115test_expect_success 'test diff.renames=true' '
116 git -c diff.renames=true diff --cached $tree >current &&
117 compare_diff_patch current expected
118'
119
120test_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
125test_expect_success 'test diff.renames unset' '
126 git diff --cached $tree >current &&
5404c116 127 compare_diff_patch current expected
a9276a69
MM
128'
129
68b2a005 130test_expect_success 'favour same basenames over different ones' '
0ce39643
JS
131 cp path1 another-path &&
132 git add another-path &&
133 git commit -m 1 &&
134 git rm path1 &&
135 mkdir subdir &&
136 git mv another-path subdir/path1 &&
68b2a005 137 git status | test_i18ngrep "renamed: .*path1 -> subdir/path1"'
0ce39643 138
68b2a005 139test_expect_success 'favour same basenames even with minor differences' '
0ce39643 140 git show HEAD:path1 | sed "s/15/16/" > subdir/path1 &&
68b2a005 141 git status | test_i18ngrep "renamed: .*path1 -> subdir/path1"'
0ce39643 142
ca4e3ca0
SG
143test_expect_success 'two files with same basename and same content' '
144 git reset --hard &&
145 mkdir -p dir/A dir/B &&
146 cp path1 dir/A/file &&
147 cp path1 dir/B/file &&
148 git add dir &&
149 git commit -m 2 &&
150 git mv dir other-dir &&
151 git status | test_i18ngrep "renamed: .*dir/A/file -> other-dir/A/file"
152'
153
f31027c9
JH
154test_expect_success 'setup for many rename source candidates' '
155 git reset --hard &&
156 for i in 0 1 2 3 4 5 6 7 8 9;
157 do
158 for j in 0 1 2 3 4 5 6 7 8 9;
159 do
160 echo "$i$j" >"path$i$j"
161 done
162 done &&
163 git add "path??" &&
164 test_tick &&
165 git commit -m "hundred" &&
166 (cat path1; echo new) >new-path &&
167 echo old >>path1 &&
168 git add new-path path1 &&
169 git diff -l 4 -C -C --cached --name-status >actual 2>actual.err &&
170 sed -e "s/^\([CM]\)[0-9]* /\1 /" actual >actual.munged &&
171 cat >expect <<-EOF &&
172 C path1 new-path
173 M path1
174 EOF
175 test_cmp expect actual.munged &&
176 grep warning actual.err
177'
178
b174eb42
AP
179test_expect_success 'rename pretty print with nothing in common' '
180 mkdir -p a/b/ &&
181 : >a/b/c &&
182 git add a/b/c &&
183 git commit -m "create a/b/c" &&
184 mkdir -p c/b/ &&
185 git mv a/b/c c/b/a &&
186 git commit -m "a/b/c -> c/b/a" &&
187 git diff -M --summary HEAD^ HEAD >output &&
188 test_i18ngrep " a/b/c => c/b/a " output &&
189 git diff -M --stat HEAD^ HEAD >output &&
190 test_i18ngrep " a/b/c => c/b/a " output
191'
192
193test_expect_success 'rename pretty print with common prefix' '
194 mkdir -p c/d &&
195 git mv c/b/a c/d/e &&
196 git commit -m "c/b/a -> c/d/e" &&
197 git diff -M --summary HEAD^ HEAD >output &&
198 test_i18ngrep " c/{b/a => d/e} " output &&
199 git diff -M --stat HEAD^ HEAD >output &&
200 test_i18ngrep " c/{b/a => d/e} " output
201'
202
203test_expect_success 'rename pretty print with common suffix' '
204 mkdir d &&
205 git mv c/d/e d/e &&
206 git commit -m "c/d/e -> d/e" &&
207 git diff -M --summary HEAD^ HEAD >output &&
208 test_i18ngrep " {c/d => d}/e " output &&
209 git diff -M --stat HEAD^ HEAD >output &&
210 test_i18ngrep " {c/d => d}/e " output
211'
212
213test_expect_success 'rename pretty print with common prefix and suffix' '
214 mkdir d/f &&
215 git mv d/e d/f/e &&
216 git commit -m "d/e -> d/f/e" &&
217 git diff -M --summary HEAD^ HEAD >output &&
218 test_i18ngrep " d/{ => f}/e " output &&
219 git diff -M --stat HEAD^ HEAD >output &&
220 test_i18ngrep " d/{ => f}/e " output
221'
222
223test_expect_success 'rename pretty print common prefix and suffix overlap' '
224 mkdir d/f/f &&
225 git mv d/f/e d/f/f/e &&
226 git commit -m "d/f/e d/f/f/e" &&
227 git diff -M --summary HEAD^ HEAD >output &&
228 test_i18ngrep " d/f/{ => f}/e " output &&
229 git diff -M --stat HEAD^ HEAD >output &&
230 test_i18ngrep " d/f/{ => f}/e " output
231'
232
57fe64a4 233test_done