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_DIRECTORY"/lib-diff.sh
;# test-lib chdir's into trash
27 test_expect_success setup
'
28 cat "$TEST_DIRECTORY"/lib-diff/README >file0 &&
29 cat "$TEST_DIRECTORY"/lib-diff/COPYING >file1 &&
30 blob0_id=$(git hash-object file0) &&
31 blob1_id=$(git hash-object file1) &&
32 git update-index --add file0 file1 &&
33 git tag reference $(git write-tree)
36 test_expect_success
'change file1 with copy-edit of file0 and remove file0' '
37 sed -e "s/git/GIT/" file0 >file1 &&
38 blob2_id=$(git hash-object file1) &&
40 git update-index --remove file0 file1
43 test_expect_success
'run diff with -B (#1)' '
44 git diff-index -B --cached reference >current &&
46 :100644 000000 $blob0_id $ZERO_OID D file0
47 :100644 100644 $blob1_id $blob2_id M100 file1
49 compare_diff_raw expect current
52 test_expect_success
'run diff with -B and -M (#2)' '
53 git diff-index -B -M reference >current &&
55 :100644 100644 $blob0_id $blob2_id R100 file0 file1
57 compare_diff_raw expect current
60 test_expect_success
'swap file0 and file1' '
62 git read-tree -m reference &&
63 git checkout-index -f -u -a &&
67 git update-index file0 file1
70 test_expect_success
'run diff with -B (#3)' '
71 git diff-index -B reference >current &&
73 :100644 100644 $blob0_id $blob1_id M100 file0
74 :100644 100644 $blob1_id $blob0_id M100 file1
76 compare_diff_raw expect current
79 test_expect_success
'run diff with -B and -M (#4)' '
80 git diff-index -B -M reference >current &&
82 :100644 100644 $blob1_id $blob1_id R100 file1 file0
83 :100644 100644 $blob0_id $blob0_id R100 file0 file1
85 compare_diff_raw expect current
88 test_expect_success
'make file0 into something completely different' '
90 test_ln_s_add frotz file0 &&
91 slink_id=$(printf frotz | git hash-object --stdin) &&
92 git update-index file1
95 test_expect_success
'run diff with -B (#5)' '
96 git diff-index -B reference >current &&
98 :100644 120000 $blob0_id $slink_id T file0
99 :100644 100644 $blob1_id $blob0_id M100 file1
101 compare_diff_raw expect current
104 test_expect_success
'run diff with -B -M (#6)' '
105 git diff-index -B -M reference >current &&
107 # file0 changed from regular to symlink. file1 is the same as the preimage
108 # of file0. Because the change does not make file0 disappear, file1 is
109 # denoted as a copy of file0
110 cat >expect <<-EOF &&
111 :100644 120000 $blob0_id $slink_id T file0
112 :100644 100644 $blob0_id $blob0_id C file0 file1
114 compare_diff_raw expect current
117 test_expect_success
'run diff with -M (#7)' '
118 git diff-index -M reference >current &&
120 # This should not mistake file0 as the copy source of new file1
121 # due to type differences.
122 cat >expect <<-EOF &&
123 :100644 120000 $blob0_id $slink_id T file0
124 :100644 100644 $blob1_id $blob0_id M file1
126 compare_diff_raw expect current
129 test_expect_success
'file1 edited to look like file0 and file0 rename-edited to file2' '
131 git read-tree -m reference &&
132 git checkout-index -f -u -a &&
133 sed -e "s/git/GIT/" file0 >file1 &&
134 sed -e "s/git/GET/" file0 >file2 &&
135 blob3_id=$(git hash-object file2) &&
137 git update-index --add --remove file0 file1 file2
140 test_expect_success
'run diff with -B (#8)' '
141 git diff-index -B reference >current &&
142 cat >expect <<-EOF &&
143 :100644 000000 $blob0_id $ZERO_OID D file0
144 :100644 100644 $blob1_id $blob2_id M100 file1
145 :000000 100644 $ZERO_OID $blob3_id A file2
147 compare_diff_raw expect current
150 test_expect_success
'run diff with -B -C (#9)' '
151 git diff-index -B -C reference >current &&
152 cat >expect <<-EOF &&
153 :100644 100644 $blob0_id $blob2_id C095 file0 file1
154 :100644 100644 $blob0_id $blob3_id R095 file0 file2
156 compare_diff_raw expect current