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-index --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-index --remove file0 file1'
43 'git diff-index -B --cached "$tree" >current'
46 :100644 000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
0000000000000000000000000000000000000000 D file0
47 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3
11e331465a89c394dc25c780de230043750c1ec8 M100 file1
51 'validate result of -B (#1)' \
52 'compare_diff_raw expected current'
55 'run diff with -B and -M' \
56 'git diff-index -B -M "$tree" >current'
59 :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
08bb2fb671deff4c03a4d4a0a1315dff98d5732c R100 file0 file1
63 'validate result of -B -M (#2)' \
64 'compare_diff_raw expected current'
67 'swap file0 and file1' \
69 git read-tree -m $tree &&
70 git checkout-index -f -u -a &&
74 git update-index file0 file1'
78 'git diff-index -B "$tree" >current'
81 :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
6ff87c4664981e4397625791c8ea3bbb5f2279a3 M100 file0
82 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M100 file1
86 'validate result of -B (#3)' \
87 'compare_diff_raw expected current'
90 'run diff with -B and -M' \
91 'git diff-index -B -M "$tree" >current'
94 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3
6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100 file1 file0
95 :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 R100 file0 file1
99 'validate result of -B -M (#4)' \
100 'compare_diff_raw expected current'
102 test "$no_symlinks" ||
{
104 test_expect_success \
105 'make file0 into something completely different' \
108 git update-index file0 file1'
110 test_expect_success \
112 'git diff-index -B "$tree" >current'
115 :100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
67be421f88824578857624f7b3dc75e99a8a1481 T file0
116 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M100 file1
119 test_expect_success \
120 'validate result of -B (#5)' \
121 'compare_diff_raw expected current'
123 test_expect_success \
125 'git diff-index -B -M "$tree" >current'
127 # This should not mistake file0 as the copy source of new file1
128 # due to type differences.
130 :100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
67be421f88824578857624f7b3dc75e99a8a1481 T file0
131 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M100 file1
134 test_expect_success \
135 'validate result of -B -M (#6)' \
136 'compare_diff_raw expected current'
138 test_expect_success \
140 'git diff-index -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 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M file1
149 test_expect_success \
150 'validate result of -M (#7)' \
151 'compare_diff_raw expected current'
153 } # end symlink tests
155 test_expect_success \
156 'file1 edited to look like file0 and file0 rename-edited to file2' \
157 'rm -f file0 file1 &&
158 git read-tree -m $tree &&
159 git checkout-index -f -u -a &&
160 sed -e "s/git/GIT/" file0 >file1 &&
161 sed -e "s/git/GET/" file0 >file2 &&
163 git update-index --add --remove file0 file1 file2'
165 test_expect_success \
167 'git diff-index -B "$tree" >current'
170 :100644 000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
0000000000000000000000000000000000000000 D file0
171 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3
08bb2fb671deff4c03a4d4a0a1315dff98d5732c M100 file1
172 :000000 100644 0000000000000000000000000000000000000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 A file2
175 test_expect_success \
176 'validate result of -B (#8)' \
177 'compare_diff_raw expected current'
179 test_expect_success \
180 'run diff with -B -M' \
181 'git diff-index -B -M "$tree" >current'
184 :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
08bb2fb671deff4c03a4d4a0a1315dff98d5732c C095 file0 file1
185 :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2
59f832e5c8b3f7e486be15ad0cd3e95ba9af8998 R095 file0 file2
188 test_expect_success \
189 'validate result of -B -M (#9)' \
190 'compare_diff_raw expected current'