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. The latter
14 two are then merged back into a single "complete rewrite".
16 Further, with -B and -M together, these three modifications should
17 turn into rename-edit of file0 into file1.
19 Starting from the same two files in the tree, we swap file0 and file1.
20 With -B, this should be detected as two complete rewrites.
22 Further, with -B and -M together, these should turn into two renames.
25 TEST_PASSES_SANITIZE_LEAK
=true
27 .
"$TEST_DIRECTORY"/lib-diff.sh
;# test-lib chdir's into trash
29 test_expect_success setup
'
30 echo some dissimilar content >file0 &&
31 COPYING_test_data >file1 &&
32 blob0_id=$(git hash-object file0) &&
33 blob1_id=$(git hash-object file1) &&
34 git update-index --add file0 file1 &&
35 git tag reference $(git write-tree)
38 test_expect_success
'change file1 with copy-edit of file0 and remove file0' '
39 sed -e "s/git/GIT/" file0 >file1 &&
40 blob2_id=$(git hash-object file1) &&
42 git update-index --remove file0 file1
45 test_expect_success
'run diff with -B (#1)' '
46 git diff-index -B --cached reference >current &&
48 :100644 000000 $blob0_id $ZERO_OID D file0
49 :100644 100644 $blob1_id $blob2_id M100 file1
51 compare_diff_raw expect current
54 test_expect_success
'run diff with -B and -M (#2)' '
55 git diff-index -B -M reference >current &&
57 :100644 100644 $blob0_id $blob2_id R100 file0 file1
59 compare_diff_raw expect current
62 test_expect_success
'swap file0 and file1' '
64 git read-tree -m reference &&
65 git checkout-index -f -u -a &&
69 git update-index file0 file1
72 test_expect_success
'run diff with -B (#3)' '
73 git diff-index -B reference >current &&
75 :100644 100644 $blob0_id $blob1_id M100 file0
76 :100644 100644 $blob1_id $blob0_id M100 file1
78 compare_diff_raw expect current
81 test_expect_success
'run diff with -B and -M (#4)' '
82 git diff-index -B -M reference >current &&
84 :100644 100644 $blob1_id $blob1_id R100 file1 file0
85 :100644 100644 $blob0_id $blob0_id R100 file0 file1
87 compare_diff_raw expect current
90 test_expect_success
'make file0 into something completely different' '
92 test_ln_s_add frotz file0 &&
93 slink_id=$(printf frotz | git hash-object --stdin) &&
94 git update-index file1
97 test_expect_success
'run diff with -B (#5)' '
98 git diff-index -B reference >current &&
100 :100644 120000 $blob0_id $slink_id T file0
101 :100644 100644 $blob1_id $blob0_id M100 file1
103 compare_diff_raw expect current
106 test_expect_success
'run diff with -B -M (#6)' '
107 git diff-index -B -M reference >current &&
109 # file0 changed from regular to symlink. file1 is the same as the preimage
110 # of file0. Because the change does not make file0 disappear, file1 is
111 # denoted as a copy of file0
112 cat >expect <<-EOF &&
113 :100644 120000 $blob0_id $slink_id T file0
114 :100644 100644 $blob0_id $blob0_id C file0 file1
116 compare_diff_raw expect current
119 test_expect_success
'run diff with -M (#7)' '
120 git diff-index -M reference >current &&
122 # This should not mistake file0 as the copy source of new file1
123 # due to type differences.
124 cat >expect <<-EOF &&
125 :100644 120000 $blob0_id $slink_id T file0
126 :100644 100644 $blob1_id $blob0_id M file1
128 compare_diff_raw expect current
131 test_expect_success
'file1 edited to look like file0 and file0 rename-edited to file2' '
133 git read-tree -m reference &&
134 git checkout-index -f -u -a &&
135 sed -e "s/git/GIT/" file0 >file1 &&
136 sed -e "s/git/GET/" file0 >file2 &&
137 blob3_id=$(git hash-object file2) &&
139 git update-index --add --remove file0 file1 file2
142 test_expect_success
'run diff with -B (#8)' '
143 git diff-index -B reference >current &&
144 cat >expect <<-EOF &&
145 :100644 000000 $blob0_id $ZERO_OID D file0
146 :100644 100644 $blob1_id $blob2_id M100 file1
147 :000000 100644 $ZERO_OID $blob3_id A file2
149 compare_diff_raw expect current
152 test_expect_success
'run diff with -B -C (#9)' '
153 git diff-index -B -C reference >current &&
154 cat >expect <<-EOF &&
155 :100644 100644 $blob0_id $blob2_id C095 file0 file1
156 :100644 100644 $blob0_id $blob3_id R095 file0 file2
158 compare_diff_raw expect current