3 # Copyright (c) 2005 Junio C Hamano
6 test_description='Break and then rename
8 We have two very different files, file0 and file1, registered in a tree.
10 We update file1 so drastically that it is more similar to file0, and
11 then remove file0. With -B, changes to file1 should be broken into
12 separate delete and create, resulting in removal of file0, removal of
13 original file1 and creation of completely rewritten file1.
15 Further, with -B and -M together, these three modifications should
16 turn into rename-edit of file0 into file1.
18 Starting from the same two files in the tree, we swap file0 and file1.
19 With -B, this should be detected as two complete rewrites, resulting in
20 four changes in total.
22 Further, with -B and -M together, these should turn into two renames.
26 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
27 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
28 sanitize_diff_raw='s/ '"$_x40"' '"$_x40"' \([CDNR]\)[0-9]* / X X \1# /'
30 # When heuristics are improved, the score numbers would change.
31 # Ignore them while comparing.
32 # Also we do not check SHA1 hash generation in this test, which
33 # is a job for t0000-basic.sh
35 sed -e "$sanitize_diff_raw" <"$1" >.tmp-1
36 sed -e "$sanitize_diff_raw" <"$2" >.tmp-2
37 diff -u .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
42 'cat ../../README >file0 &&
43 cat ../../COPYING >file1 &&
44 git-update-cache --add file0 file1 &&
45 tree=$(git-write-tree) &&
49 'change file1 with copy-edit of file0 and remove file0' \
50 'sed -e "s/git/GIT/" file0 >file1 &&
52 git-update-cache --remove file0 file1'
56 'git-diff-cache -B --cached "$tree" >current'
59 :100644 000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 0000000000000000000000000000000000000000 D file0
60 :100644 000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0000000000000000000000000000000000000000 D100 file1
61 :000000 100644 0000000000000000000000000000000000000000 11e331465a89c394dc25c780de230043750c1ec8 N100 file1
65 'validate result of -B (#1)' \
66 'compare_diff_raw current expected'
69 'run diff with -B and -M' \
70 'git-diff-cache -B -M "$tree" >current'
73 :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 08bb2fb671deff4c03a4d4a0a1315dff98d5732c R100 file0 file1
77 'validate result of -B -M (#2)' \
78 'compare_diff_raw current expected'
81 'swap file0 and file1' \
83 git-read-tree -m $tree &&
84 git-checkout-cache -f -u -a &&
88 git-update-cache file0 file1'
92 'git-diff-cache -B "$tree" >current'
95 :100644 000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 0000000000000000000000000000000000000000 D100 file0
96 :000000 100644 0000000000000000000000000000000000000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 N100 file0
97 :100644 000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0000000000000000000000000000000000000000 D100 file1
98 :000000 100644 0000000000000000000000000000000000000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 N100 file1
101 test_expect_success \
102 'validate result of -B (#3)' \
103 'compare_diff_raw current expected'
105 test_expect_success \
106 'run diff with -B and -M' \
107 'git-diff-cache -B -M "$tree" >current'
110 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100 file1 file0
111 :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 R100 file0 file1
114 test_expect_success \
115 'validate result of -B -M (#4)' \
116 'compare_diff_raw current expected'
118 test_expect_success \
119 'make file0 into something completely different' \
122 git-update-cache file0 file1'
124 test_expect_success \
126 'git-diff-cache -B "$tree" >current'
129 :100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 67be421f88824578857624f7b3dc75e99a8a1481 T file0
130 :100644 000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0000000000000000000000000000000000000000 D100 file1
131 :000000 100644 0000000000000000000000000000000000000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 N100 file1
134 test_expect_success \
135 'validate result of -B (#5)' \
136 'compare_diff_raw current expected'
138 test_expect_success \
140 'git-diff-cache -B -M "$tree" >current'
142 # This should not mistake file0 as the copy source of new file1
143 # due to type differences.
145 :100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 67be421f88824578857624f7b3dc75e99a8a1481 T file0
146 :100644 000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0000000000000000000000000000000000000000 D100 file1
147 :000000 100644 0000000000000000000000000000000000000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 N100 file1
150 test_expect_success \
151 'validate result of -B -M (#6)' \
152 'compare_diff_raw current expected'
154 test_expect_success \
156 'git-diff-cache -M "$tree" >current'
158 # This should not mistake file0 as the copy source of new file1
159 # due to type differences.
161 :100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 67be421f88824578857624f7b3dc75e99a8a1481 T file0
162 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M file1
165 test_expect_success \
166 'validate result of -M (#7)' \
167 'compare_diff_raw current expected'
169 test_expect_success \
170 'file1 edited to look like file0 and file0 rename-edited to file2' \
171 'rm -f file0 file1 &&
172 git-read-tree -m $tree &&
173 git-checkout-cache -f -u -a &&
174 sed -e "s/git/GIT/" file0 >file1 &&
175 sed -e "s/git/GET/" file0 >file2 &&
177 git-update-cache --add --remove file0 file1 file2'
179 test_expect_success \
181 'git-diff-cache -B "$tree" >current'
184 :100644 000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 0000000000000000000000000000000000000000 D file0
185 :100644 000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0000000000000000000000000000000000000000 D100 file1
186 :000000 100644 0000000000000000000000000000000000000000 08bb2fb671deff4c03a4d4a0a1315dff98d5732c N100 file1
187 :000000 100644 0000000000000000000000000000000000000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 N file2
190 test_expect_success \
191 'validate result of -B (#8)' \
192 'compare_diff_raw current expected'
194 test_expect_success \
195 'run diff with -B -M' \
196 'git-diff-cache -B -M "$tree" >current'
199 :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 08bb2fb671deff4c03a4d4a0a1315dff98d5732c C095 file0 file1
200 :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 59f832e5c8b3f7e486be15ad0cd3e95ba9af8998 R095 file0 file2
203 test_expect_success \
204 'validate result of -B -M (#9)' \
205 'compare_diff_raw current expected'