3 test_description
='merge-recursive rename options
5 Test rename detection by examining rename/delete conflicts.
7 * (HEAD -> rename) rename
12 git diff --name-status base master
18 git diff --name-status -M01 base rename
24 Actual similarity indices are parsed from diff output. We rely on the fact that
25 they are rounded down (see, e.g., Documentation/diff-generate-patch.txt, which
26 mentions this in a different context).
31 get_expected_stages
() {
32 git checkout rename
-- $1-new &&
33 git ls-files
--stage $1-new >expected-stages-undetected-
$1 &&
34 sed "s/ 0 / 2 /" <expected-stages-undetected-
$1 \
35 >expected-stages-detected-
$1 &&
36 git read-tree
-u --reset HEAD
40 git ls-files
--stage $1-old $1-new >stages-actual-
$1 &&
41 test_cmp expected-stages-detected-
$1 stages-actual-
$1
44 rename_undetected
() {
45 git ls-files
--stage $1-old $1-new >stages-actual-
$1 &&
46 test_cmp expected-stages-undetected-
$1 stages-actual-
$1
50 git ls-files
--stage >stages-actual
&&
51 test_line_count
= 4 stages-actual
54 check_threshold_0
() {
62 check_threshold_1
() {
64 rename_undetected
0 &&
70 check_threshold_2
() {
72 rename_undetected
0 &&
73 rename_undetected
1 &&
78 check_exact_renames
() {
80 rename_undetected
0 &&
81 rename_undetected
1 &&
82 rename_undetected
2 &&
86 test_expect_success
'setup repo' '
93 sed s/33/22/ <3-old >2-old &&
94 sed s/33/11/ <3-old >1-old &&
95 sed s/33/00/ <3-old >0-old &&
99 git commit -m delete &&
100 git checkout -b rename HEAD^ &&
102 sed 1,1s/./x/ <2-old >2-new &&
103 sed 1,2s/./x/ <1-old >1-new &&
104 sed 1,3s/./x/ <0-old >0-new &&
107 git commit -m rename &&
108 get_expected_stages 0 &&
109 get_expected_stages 1 &&
110 get_expected_stages 2 &&
111 get_expected_stages 3 &&
113 tail="HEAD^ -- HEAD master"
116 test_expect_success
'setup thresholds' '
117 git diff --name-status -M01 HEAD^ HEAD >diff-output &&
118 test_debug "cat diff-output" &&
119 test_line_count = 4 diff-output &&
120 grep "R[0-9][0-9][0-9] \([0-3]\)-old \1-new" diff-output \
122 test_cmp diff-output grep-output &&
123 th0=$(sed -n "s/R\(...\) 0-old 0-new/\1/p" <diff-output) &&
124 th1=$(sed -n "s/R\(...\) 1-old 1-new/\1/p" <diff-output) &&
125 th2=$(sed -n "s/R\(...\) 2-old 2-new/\1/p" <diff-output) &&
126 th3=$(sed -n "s/R\(...\) 3-old 3-new/\1/p" <diff-output) &&
127 test "$th0" -lt "$th1" &&
128 test "$th1" -lt "$th2" &&
129 test "$th2" -lt "$th3" &&
131 if test 50 -le "$th0"
133 check_50=check_threshold_0
134 elif test 50 -le "$th1"
136 check_50=check_threshold_1
137 elif test 50 -le "$th2"
139 check_50=check_threshold_2
147 test_expect_success
'assumption for tests: rename detection with diff' '
148 git diff --name-status -M$th0 --diff-filter=R HEAD^ HEAD \
150 git diff --name-status -M$th1 --diff-filter=R HEAD^ HEAD \
152 git diff --name-status -M$th2 --diff-filter=R HEAD^ HEAD \
154 git diff --name-status -M100% --diff-filter=R HEAD^ HEAD \
156 test_line_count = 4 diff-output-0 &&
157 test_line_count = 3 diff-output-1 &&
158 test_line_count = 2 diff-output-2 &&
159 test_line_count = 1 diff-output-3
162 test_expect_success
'default similarity threshold is 50%' '
163 git read-tree --reset -u HEAD &&
164 test_must_fail git merge-recursive $tail &&
168 test_expect_success
'low rename threshold' '
169 git read-tree --reset -u HEAD &&
170 test_must_fail git merge-recursive --find-renames=$th0 $tail &&
174 test_expect_success
'medium rename threshold' '
175 git read-tree --reset -u HEAD &&
176 test_must_fail git merge-recursive --find-renames=$th1 $tail &&
180 test_expect_success
'high rename threshold' '
181 git read-tree --reset -u HEAD &&
182 test_must_fail git merge-recursive --find-renames=$th2 $tail &&
186 test_expect_success
'exact renames only' '
187 git read-tree --reset -u HEAD &&
188 test_must_fail git merge-recursive --find-renames=100% $tail &&
192 test_expect_success
'rename threshold is truncated' '
193 git read-tree --reset -u HEAD &&
194 test_must_fail git merge-recursive --find-renames=200% $tail &&
198 test_expect_success
'last wins in --find-renames=<m> --find-renames=<n>' '
199 git read-tree --reset -u HEAD &&
200 test_must_fail git merge-recursive \
201 --find-renames=$th0 --find-renames=$th2 $tail &&
205 test_expect_success
'--find-renames resets threshold' '
206 git read-tree --reset -u HEAD &&
207 test_must_fail git merge-recursive \
208 --find-renames=$th0 --find-renames $tail &&
212 test_expect_success
'assumption for further tests: trivial merge succeeds' '
213 git read-tree --reset -u HEAD &&
214 git merge-recursive HEAD -- HEAD HEAD &&
215 git diff --quiet --cached &&
216 git merge-recursive --find-renames=$th0 HEAD -- HEAD HEAD &&
217 git diff --quiet --cached &&
218 git merge-recursive --find-renames=$th2 HEAD -- HEAD HEAD &&
219 git diff --quiet --cached &&
220 git merge-recursive --find-renames=100% HEAD -- HEAD HEAD &&
221 git diff --quiet --cached
224 test_expect_success
'--find-renames rejects negative argument' '
225 git read-tree --reset -u HEAD &&
226 test_must_fail git merge-recursive --find-renames=-25 \
228 git diff --quiet --cached
231 test_expect_success
'--find-renames rejects non-numbers' '
232 git read-tree --reset -u HEAD &&
233 test_must_fail git merge-recursive --find-renames=0xf \
235 git diff --quiet --cached