Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t6434-merge-recursive-rename-options.sh
blobdf1d0c156c54a3ce0f96557e882435136862b4d8
1 #!/bin/sh
3 test_description='merge-recursive rename options
5 Test rename detection by examining rename/delete conflicts.
7 * (HEAD -> rename) rename
8 | * (main) delete
9 |/
10 * base
12 git diff --name-status base main
13 D 0-old
14 D 1-old
15 D 2-old
16 D 3-old
18 git diff --name-status -M01 base rename
19 R025 0-old 0-new
20 R050 1-old 1-new
21 R075 2-old 2-new
22 R100 3-old 3-new
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).
29 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
30 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
32 TEST_PASSES_SANITIZE_LEAK=true
33 . ./test-lib.sh
35 get_expected_stages () {
36 git checkout rename -- $1-new &&
37 git ls-files --stage $1-new >expected-stages-undetected-$1 &&
38 sed "s/ 0 / 2 /" <expected-stages-undetected-$1 \
39 >expected-stages-detected-$1 &&
40 git read-tree -u --reset HEAD
43 rename_detected () {
44 git ls-files --stage $1-old $1-new >stages-actual-$1 &&
45 test_cmp expected-stages-detected-$1 stages-actual-$1
48 rename_undetected () {
49 git ls-files --stage $1-old $1-new >stages-actual-$1 &&
50 test_cmp expected-stages-undetected-$1 stages-actual-$1
53 check_common () {
54 git ls-files --stage >stages-actual &&
55 test_line_count = 4 stages-actual
58 check_threshold_0 () {
59 check_common &&
60 rename_detected 0 &&
61 rename_detected 1 &&
62 rename_detected 2 &&
63 rename_detected 3
66 check_threshold_1 () {
67 check_common &&
68 rename_undetected 0 &&
69 rename_detected 1 &&
70 rename_detected 2 &&
71 rename_detected 3
74 check_threshold_2 () {
75 check_common &&
76 rename_undetected 0 &&
77 rename_undetected 1 &&
78 rename_detected 2 &&
79 rename_detected 3
82 check_exact_renames () {
83 check_common &&
84 rename_undetected 0 &&
85 rename_undetected 1 &&
86 rename_undetected 2 &&
87 rename_detected 3
90 check_no_renames () {
91 check_common &&
92 rename_undetected 0 &&
93 rename_undetected 1 &&
94 rename_undetected 2 &&
95 rename_undetected 3
98 test_expect_success 'setup repo' '
99 cat <<-\EOF >3-old &&
105 sed s/33/22/ <3-old >2-old &&
106 sed s/33/11/ <3-old >1-old &&
107 sed s/33/00/ <3-old >0-old &&
108 git add [0-3]-old &&
109 git commit -m base &&
110 git rm [0-3]-old &&
111 git commit -m delete &&
112 git checkout -b rename HEAD^ &&
113 cp 3-old 3-new &&
114 sed 1,1s/./x/ <2-old >2-new &&
115 sed 1,2s/./x/ <1-old >1-new &&
116 sed 1,3s/./x/ <0-old >0-new &&
117 git add [0-3]-new &&
118 git rm [0-3]-old &&
119 git commit -m rename &&
120 get_expected_stages 0 &&
121 get_expected_stages 1 &&
122 get_expected_stages 2 &&
123 get_expected_stages 3 &&
124 check_50="false" &&
125 tail="HEAD^ -- HEAD main"
128 test_expect_success 'setup thresholds' '
129 git diff --name-status -M01 HEAD^ HEAD >diff-output &&
130 test_debug "cat diff-output" &&
131 test_line_count = 4 diff-output &&
132 grep "R[0-9][0-9][0-9] \([0-3]\)-old \1-new" diff-output \
133 >grep-output &&
134 test_cmp diff-output grep-output &&
135 th0=$(sed -n "s/R\(...\) 0-old 0-new/\1/p" <diff-output) &&
136 th1=$(sed -n "s/R\(...\) 1-old 1-new/\1/p" <diff-output) &&
137 th2=$(sed -n "s/R\(...\) 2-old 2-new/\1/p" <diff-output) &&
138 th3=$(sed -n "s/R\(...\) 3-old 3-new/\1/p" <diff-output) &&
139 test "$th0" -lt "$th1" &&
140 test "$th1" -lt "$th2" &&
141 test "$th2" -lt "$th3" &&
142 test "$th3" = 100 &&
143 if test 50 -le "$th0"
144 then
145 check_50=check_threshold_0
146 elif test 50 -le "$th1"
147 then
148 check_50=check_threshold_1
149 elif test 50 -le "$th2"
150 then
151 check_50=check_threshold_2
152 fi &&
153 th0="$th0%" &&
154 th1="$th1%" &&
155 th2="$th2%" &&
156 th3="$th3%"
159 test_expect_success 'assumption for tests: rename detection with diff' '
160 git diff --name-status -M$th0 --diff-filter=R HEAD^ HEAD \
161 >diff-output-0 &&
162 git diff --name-status -M$th1 --diff-filter=R HEAD^ HEAD \
163 >diff-output-1 &&
164 git diff --name-status -M$th2 --diff-filter=R HEAD^ HEAD \
165 >diff-output-2 &&
166 git diff --name-status -M100% --diff-filter=R HEAD^ HEAD \
167 >diff-output-3 &&
168 test_line_count = 4 diff-output-0 &&
169 test_line_count = 3 diff-output-1 &&
170 test_line_count = 2 diff-output-2 &&
171 test_line_count = 1 diff-output-3
174 test_expect_success 'default similarity threshold is 50%' '
175 git read-tree --reset -u HEAD &&
176 test_must_fail git merge-recursive $tail &&
177 $check_50
180 test_expect_success 'low rename threshold' '
181 git read-tree --reset -u HEAD &&
182 test_must_fail git merge-recursive --find-renames=$th0 $tail &&
183 check_threshold_0
186 test_expect_success 'medium rename threshold' '
187 git read-tree --reset -u HEAD &&
188 test_must_fail git merge-recursive --find-renames=$th1 $tail &&
189 check_threshold_1
192 test_expect_success 'high rename threshold' '
193 git read-tree --reset -u HEAD &&
194 test_must_fail git merge-recursive --find-renames=$th2 $tail &&
195 check_threshold_2
198 test_expect_success 'exact renames only' '
199 git read-tree --reset -u HEAD &&
200 test_must_fail git merge-recursive --find-renames=100% $tail &&
201 check_exact_renames
204 test_expect_success 'rename threshold is truncated' '
205 git read-tree --reset -u HEAD &&
206 test_must_fail git merge-recursive --find-renames=200% $tail &&
207 check_exact_renames
210 test_expect_success 'disabled rename detection' '
211 git read-tree --reset -u HEAD &&
212 git merge-recursive --no-renames $tail &&
213 check_no_renames
216 test_expect_success 'last wins in --find-renames=<m> --find-renames=<n>' '
217 git read-tree --reset -u HEAD &&
218 test_must_fail git merge-recursive \
219 --find-renames=$th0 --find-renames=$th2 $tail &&
220 check_threshold_2
223 test_expect_success '--find-renames resets threshold' '
224 git read-tree --reset -u HEAD &&
225 test_must_fail git merge-recursive \
226 --find-renames=$th0 --find-renames $tail &&
227 $check_50
230 test_expect_success 'last wins in --no-renames --find-renames' '
231 git read-tree --reset -u HEAD &&
232 test_must_fail git merge-recursive --no-renames --find-renames $tail &&
233 $check_50
236 test_expect_success 'last wins in --find-renames --no-renames' '
237 git read-tree --reset -u HEAD &&
238 git merge-recursive --find-renames --no-renames $tail &&
239 check_no_renames
242 test_expect_success 'assumption for further tests: trivial merge succeeds' '
243 git read-tree --reset -u HEAD &&
244 git merge-recursive HEAD -- HEAD HEAD &&
245 git diff --quiet --cached &&
246 git merge-recursive --find-renames=$th0 HEAD -- HEAD HEAD &&
247 git diff --quiet --cached &&
248 git merge-recursive --find-renames=$th2 HEAD -- HEAD HEAD &&
249 git diff --quiet --cached &&
250 git merge-recursive --find-renames=100% HEAD -- HEAD HEAD &&
251 git diff --quiet --cached &&
252 git merge-recursive --no-renames HEAD -- HEAD HEAD &&
253 git diff --quiet --cached
256 test_expect_success '--find-renames rejects negative argument' '
257 git read-tree --reset -u HEAD &&
258 test_must_fail git merge-recursive --find-renames=-25 \
259 HEAD -- HEAD HEAD &&
260 git diff --quiet --cached
263 test_expect_success '--find-renames rejects non-numbers' '
264 git read-tree --reset -u HEAD &&
265 test_must_fail git merge-recursive --find-renames=0xf \
266 HEAD -- HEAD HEAD &&
267 git diff --quiet --cached
270 test_expect_success 'rename-threshold=<n> is a synonym for find-renames=<n>' '
271 git read-tree --reset -u HEAD &&
272 test_must_fail git merge-recursive --rename-threshold=$th0 $tail &&
273 check_threshold_0
276 test_expect_success 'last wins in --no-renames --rename-threshold=<n>' '
277 git read-tree --reset -u HEAD &&
278 test_must_fail git merge-recursive --no-renames --rename-threshold=$th0 $tail &&
279 check_threshold_0
282 test_expect_success 'last wins in --rename-threshold=<n> --no-renames' '
283 git read-tree --reset -u HEAD &&
284 git merge-recursive --rename-threshold=$th0 --no-renames $tail &&
285 check_no_renames
288 test_expect_success '--rename-threshold=<n> rejects negative argument' '
289 git read-tree --reset -u HEAD &&
290 test_must_fail git merge-recursive --rename-threshold=-25 \
291 HEAD -- HEAD HEAD &&
292 git diff --quiet --cached
295 test_expect_success '--rename-threshold=<n> rejects non-numbers' '
296 git read-tree --reset -u HEAD &&
297 test_must_fail git merge-recursive --rename-threshold=0xf \
298 HEAD -- HEAD HEAD &&
299 git diff --quiet --cached
302 test_expect_success 'last wins in --rename-threshold=<m> --find-renames=<n>' '
303 git read-tree --reset -u HEAD &&
304 test_must_fail git merge-recursive \
305 --rename-threshold=$th0 --find-renames=$th2 $tail &&
306 check_threshold_2
309 test_expect_success 'last wins in --find-renames=<m> --rename-threshold=<n>' '
310 git read-tree --reset -u HEAD &&
311 test_must_fail git merge-recursive \
312 --find-renames=$th2 --rename-threshold=$th0 $tail &&
313 check_threshold_0
316 test_expect_success 'merge.renames disables rename detection' '
317 git read-tree --reset -u HEAD &&
318 git -c merge.renames=false merge-recursive $tail &&
319 check_no_renames
322 test_expect_success 'merge.renames defaults to diff.renames' '
323 git read-tree --reset -u HEAD &&
324 git -c diff.renames=false merge-recursive $tail &&
325 check_no_renames
328 test_expect_success 'merge.renames overrides diff.renames' '
329 git read-tree --reset -u HEAD &&
330 test_must_fail git -c diff.renames=false -c merge.renames=true merge-recursive $tail &&
331 $check_50
334 test_done