apply: update line lengths for --inaccurate-eof
[git/raj.git] / t / t4008-diff-break-rewrite.sh
blob9dd1bc5e162bb0b8821337a1e43cd8ad85423507
1 #!/bin/sh
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.
24 . ./test-lib.sh
25 . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
27 test_expect_success setup '
28 cat "$TEST_DIRECTORY"/diff-lib/README >file0 &&
29 cat "$TEST_DIRECTORY"/diff-lib/COPYING >file1 &&
30 git update-index --add file0 file1 &&
31 git tag reference $(git write-tree)
34 test_expect_success 'change file1 with copy-edit of file0 and remove file0' '
35 sed -e "s/git/GIT/" file0 >file1 &&
36 rm -f file0 &&
37 git update-index --remove file0 file1
40 test_expect_success 'run diff with -B (#1)' '
41 git diff-index -B --cached reference >current &&
42 cat >expect <<-\EOF &&
43 :100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D file0
44 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100 file1
45 EOF
46 compare_diff_raw expect current
49 test_expect_success 'run diff with -B and -M (#2)' '
50 git diff-index -B -M reference >current &&
51 cat >expect <<-\EOF &&
52 :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec R100 file0 file1
53 EOF
54 compare_diff_raw expect current
57 test_expect_success 'swap file0 and file1' '
58 rm -f file0 file1 &&
59 git read-tree -m reference &&
60 git checkout-index -f -u -a &&
61 mv file0 tmp &&
62 mv file1 file0 &&
63 mv tmp file1 &&
64 git update-index file0 file1
67 test_expect_success 'run diff with -B (#3)' '
68 git diff-index -B reference >current &&
69 cat >expect <<-\EOF &&
70 :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 6ff87c4664981e4397625791c8ea3bbb5f2279a3 M100 file0
71 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100 file1
72 EOF
73 compare_diff_raw expect current
76 test_expect_success 'run diff with -B and -M (#4)' '
77 git diff-index -B -M reference >current &&
78 cat >expect <<-\EOF &&
79 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100 file1 file0
80 :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 R100 file0 file1
81 EOF
82 compare_diff_raw expect current
85 test_expect_success 'make file0 into something completely different' '
86 rm -f file0 &&
87 test_ln_s_add frotz file0 &&
88 git update-index file1
91 test_expect_success 'run diff with -B (#5)' '
92 git diff-index -B reference >current &&
93 cat >expect <<-\EOF &&
94 :100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
95 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100 file1
96 EOF
97 compare_diff_raw expect current
100 test_expect_success 'run diff with -B -M (#6)' '
101 git diff-index -B -M reference >current &&
103 # file0 changed from regular to symlink. file1 is the same as the preimage
104 # of file0. Because the change does not make file0 disappear, file1 is
105 # denoted as a copy of file0
106 cat >expect <<-\EOF &&
107 :100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
108 :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 C file0 file1
110 compare_diff_raw expect current
113 test_expect_success 'run diff with -M (#7)' '
114 git diff-index -M reference >current &&
116 # This should not mistake file0 as the copy source of new file1
117 # due to type differences.
118 cat >expect <<-\EOF &&
119 :100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
120 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M file1
122 compare_diff_raw expect current
125 test_expect_success 'file1 edited to look like file0 and file0 rename-edited to file2' '
126 rm -f file0 file1 &&
127 git read-tree -m reference &&
128 git checkout-index -f -u -a &&
129 sed -e "s/git/GIT/" file0 >file1 &&
130 sed -e "s/git/GET/" file0 >file2 &&
131 rm -f file0 &&
132 git update-index --add --remove file0 file1 file2
135 test_expect_success 'run diff with -B (#8)' '
136 git diff-index -B reference >current &&
137 cat >expect <<-\EOF &&
138 :100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D file0
139 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100 file1
140 :000000 100644 0000000000000000000000000000000000000000 69a939f651686f56322566e2fd76715947a24162 A file2
142 compare_diff_raw expect current
145 test_expect_success 'run diff with -B -C (#9)' '
146 git diff-index -B -C reference >current &&
147 cat >expect <<-\EOF &&
148 :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec C095 file0 file1
149 :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 69a939f651686f56322566e2fd76715947a24162 R095 file0 file2
151 compare_diff_raw expect current
154 test_done