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.
25 . ..
/diff-lib.sh
;# test-lib chdir's into trash
29 'cat ../../README >file0 &&
30 cat ../../COPYING >file1 &&
31 git-update-cache --add file0 file1 &&
32 tree=$(git-write-tree) &&
36 'change file1 with copy-edit of file0 and remove file0' \
37 'sed -e "s/git/GIT/" file0 >file1 &&
39 git-update-cache --remove file0 file1'
43 'git-diff-cache -B --cached "$tree" >current'
46 :100644 000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
0000000000000000000000000000000000000000 D file0
47 :100644 000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3
0000000000000000000000000000000000000000 D100 file1
48 :000000 100644 0000000000000000000000000000000000000000 11e331465a89c394dc25c780de230043750c1ec8 N100 file1
52 'validate result of -B (#1)' \
53 'compare_diff_raw current expected'
56 'run diff with -B and -M' \
57 'git-diff-cache -B -M "$tree" >current'
60 :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
08bb2fb671deff4c03a4d4a0a1315dff98d5732c R100 file0 file1
64 'validate result of -B -M (#2)' \
65 'compare_diff_raw current expected'
68 'swap file0 and file1' \
70 git-read-tree -m $tree &&
71 git-checkout-cache -f -u -a &&
75 git-update-cache file0 file1'
79 'git-diff-cache -B "$tree" >current'
82 :100644 000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
0000000000000000000000000000000000000000 D100 file0
83 :000000 100644 0000000000000000000000000000000000000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 N100 file0
84 :100644 000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3
0000000000000000000000000000000000000000 D100 file1
85 :000000 100644 0000000000000000000000000000000000000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 N100 file1
89 'validate result of -B (#3)' \
90 'compare_diff_raw current expected'
93 'run diff with -B and -M' \
94 'git-diff-cache -B -M "$tree" >current'
97 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3
6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100 file1 file0
98 :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 R100 file0 file1
101 test_expect_success \
102 'validate result of -B -M (#4)' \
103 'compare_diff_raw current expected'
105 test_expect_success \
106 'make file0 into something completely different' \
109 git-update-cache file0 file1'
111 test_expect_success \
113 'git-diff-cache -B "$tree" >current'
116 :100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
67be421f88824578857624f7b3dc75e99a8a1481 T file0
117 :100644 000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3
0000000000000000000000000000000000000000 D100 file1
118 :000000 100644 0000000000000000000000000000000000000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 N100 file1
121 test_expect_success \
122 'validate result of -B (#5)' \
123 'compare_diff_raw current expected'
125 test_expect_success \
127 'git-diff-cache -B -M "$tree" >current'
129 # This should not mistake file0 as the copy source of new file1
130 # due to type differences.
132 :100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
67be421f88824578857624f7b3dc75e99a8a1481 T file0
133 :100644 000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3
0000000000000000000000000000000000000000 D100 file1
134 :000000 100644 0000000000000000000000000000000000000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 N100 file1
137 test_expect_success \
138 'validate result of -B -M (#6)' \
139 'compare_diff_raw current expected'
141 test_expect_success \
143 'git-diff-cache -M "$tree" >current'
145 # This should not mistake file0 as the copy source of new file1
146 # due to type differences.
148 :100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
67be421f88824578857624f7b3dc75e99a8a1481 T file0
149 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M file1
152 test_expect_success \
153 'validate result of -M (#7)' \
154 'compare_diff_raw current expected'
156 test_expect_success \
157 'file1 edited to look like file0 and file0 rename-edited to file2' \
158 'rm -f file0 file1 &&
159 git-read-tree -m $tree &&
160 git-checkout-cache -f -u -a &&
161 sed -e "s/git/GIT/" file0 >file1 &&
162 sed -e "s/git/GET/" file0 >file2 &&
164 git-update-cache --add --remove file0 file1 file2'
166 test_expect_success \
168 'git-diff-cache -B "$tree" >current'
171 :100644 000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
0000000000000000000000000000000000000000 D file0
172 :100644 000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3
0000000000000000000000000000000000000000 D100 file1
173 :000000 100644 0000000000000000000000000000000000000000 08bb2fb671deff4c03a4d4a0a1315dff98d5732c N100 file1
174 :000000 100644 0000000000000000000000000000000000000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 N file2
177 test_expect_success \
178 'validate result of -B (#8)' \
179 'compare_diff_raw current expected'
181 test_expect_success \
182 'run diff with -B -M' \
183 'git-diff-cache -B -M "$tree" >current'
186 :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
08bb2fb671deff4c03a4d4a0a1315dff98d5732c C095 file0 file1
187 :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
59f832e5c8b3f7e486be15ad0cd3e95ba9af8998 R095 file0 file2
190 test_expect_success \
191 'validate result of -B -M (#9)' \
192 'compare_diff_raw current expected'