]>
Commit | Line | Data |
---|---|---|
5c97558c JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='Test rename detection in diff engine. | |
7 | ||
8 | ' | |
9 | . ./test-lib.sh | |
bfdbee98 | 10 | . "$TEST_DIRECTORY"/diff-lib.sh |
5c97558c JH |
11 | |
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 | |
27 | ' | |
28 | ||
29 | test_expect_success \ | |
10455d2a | 30 | 'update-index --add a file.' \ |
5be60078 | 31 | 'git update-index --add path0' |
5c97558c JH |
32 | |
33 | test_expect_success \ | |
34 | 'write that tree.' \ | |
5be60078 | 35 | 'tree=$(git write-tree) && echo $tree' |
5c97558c JH |
36 | |
37 | sed -e 's/line/Line/' <path0 >path1 | |
38 | rm -f path0 | |
39 | test_expect_success \ | |
40 | 'renamed and edited the file.' \ | |
5be60078 | 41 | 'git update-index --add --remove path0 path1' |
5c97558c JH |
42 | |
43 | test_expect_success \ | |
5be60078 JH |
44 | 'git diff-index -p -M after rename and editing.' \ |
45 | 'git diff-index -p -M $tree >current' | |
5c97558c JH |
46 | cat >expected <<\EOF |
47 | diff --git a/path0 b/path1 | |
dc938417 LT |
48 | rename from path0 |
49 | rename to path1 | |
5c97558c JH |
50 | --- a/path0 |
51 | +++ b/path1 | |
acb72577 | 52 | @@ -8,7 +8,7 @@ Line 7 |
5c97558c JH |
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 | |
57fe64a4 JH |
62 | |
63 | test_expect_success \ | |
64 | 'validate the output.' \ | |
ec1fcc16 | 65 | 'compare_diff_patch current expected' |
57fe64a4 | 66 | |
68b2a005 | 67 | test_expect_success 'favour same basenames over different ones' ' |
0ce39643 JS |
68 | cp path1 another-path && |
69 | git add another-path && | |
70 | git commit -m 1 && | |
71 | git rm path1 && | |
72 | mkdir subdir && | |
73 | git mv another-path subdir/path1 && | |
68b2a005 | 74 | git status | test_i18ngrep "renamed: .*path1 -> subdir/path1"' |
0ce39643 | 75 | |
68b2a005 | 76 | test_expect_success 'favour same basenames even with minor differences' ' |
0ce39643 | 77 | git show HEAD:path1 | sed "s/15/16/" > subdir/path1 && |
68b2a005 | 78 | git status | test_i18ngrep "renamed: .*path1 -> subdir/path1"' |
0ce39643 | 79 | |
f31027c9 JH |
80 | test_expect_success 'setup for many rename source candidates' ' |
81 | git reset --hard && | |
82 | for i in 0 1 2 3 4 5 6 7 8 9; | |
83 | do | |
84 | for j in 0 1 2 3 4 5 6 7 8 9; | |
85 | do | |
86 | echo "$i$j" >"path$i$j" | |
87 | done | |
88 | done && | |
89 | git add "path??" && | |
90 | test_tick && | |
91 | git commit -m "hundred" && | |
92 | (cat path1; echo new) >new-path && | |
93 | echo old >>path1 && | |
94 | git add new-path path1 && | |
95 | git diff -l 4 -C -C --cached --name-status >actual 2>actual.err && | |
96 | sed -e "s/^\([CM]\)[0-9]* /\1 /" actual >actual.munged && | |
97 | cat >expect <<-EOF && | |
98 | C path1 new-path | |
99 | M path1 | |
100 | EOF | |
101 | test_cmp expect actual.munged && | |
102 | grep warning actual.err | |
103 | ' | |
104 | ||
b174eb42 AP |
105 | test_expect_success 'rename pretty print with nothing in common' ' |
106 | mkdir -p a/b/ && | |
107 | : >a/b/c && | |
108 | git add a/b/c && | |
109 | git commit -m "create a/b/c" && | |
110 | mkdir -p c/b/ && | |
111 | git mv a/b/c c/b/a && | |
112 | git commit -m "a/b/c -> c/b/a" && | |
113 | git diff -M --summary HEAD^ HEAD >output && | |
114 | test_i18ngrep " a/b/c => c/b/a " output && | |
115 | git diff -M --stat HEAD^ HEAD >output && | |
116 | test_i18ngrep " a/b/c => c/b/a " output | |
117 | ' | |
118 | ||
119 | test_expect_success 'rename pretty print with common prefix' ' | |
120 | mkdir -p c/d && | |
121 | git mv c/b/a c/d/e && | |
122 | git commit -m "c/b/a -> c/d/e" && | |
123 | git diff -M --summary HEAD^ HEAD >output && | |
124 | test_i18ngrep " c/{b/a => d/e} " output && | |
125 | git diff -M --stat HEAD^ HEAD >output && | |
126 | test_i18ngrep " c/{b/a => d/e} " output | |
127 | ' | |
128 | ||
129 | test_expect_success 'rename pretty print with common suffix' ' | |
130 | mkdir d && | |
131 | git mv c/d/e d/e && | |
132 | git commit -m "c/d/e -> d/e" && | |
133 | git diff -M --summary HEAD^ HEAD >output && | |
134 | test_i18ngrep " {c/d => d}/e " output && | |
135 | git diff -M --stat HEAD^ HEAD >output && | |
136 | test_i18ngrep " {c/d => d}/e " output | |
137 | ' | |
138 | ||
139 | test_expect_success 'rename pretty print with common prefix and suffix' ' | |
140 | mkdir d/f && | |
141 | git mv d/e d/f/e && | |
142 | git commit -m "d/e -> d/f/e" && | |
143 | git diff -M --summary HEAD^ HEAD >output && | |
144 | test_i18ngrep " d/{ => f}/e " output && | |
145 | git diff -M --stat HEAD^ HEAD >output && | |
146 | test_i18ngrep " d/{ => f}/e " output | |
147 | ' | |
148 | ||
149 | test_expect_success 'rename pretty print common prefix and suffix overlap' ' | |
150 | mkdir d/f/f && | |
151 | git mv d/f/e d/f/f/e && | |
152 | git commit -m "d/f/e d/f/f/e" && | |
153 | git diff -M --summary HEAD^ HEAD >output && | |
154 | test_i18ngrep " d/f/{ => f}/e " output && | |
155 | git diff -M --stat HEAD^ HEAD >output && | |
156 | test_i18ngrep " d/f/{ => f}/e " output | |
157 | ' | |
158 | ||
57fe64a4 | 159 | test_done |