]>
Commit | Line | Data |
---|---|---|
f345b0a0 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='Break and then rename | |
7 | ||
8 | We have two very different files, file0 and file1, registered in a tree. | |
9 | ||
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 | |
f2b4f0a2 JH |
13 | original file1 and creation of completely rewritten file1. The latter |
14 | two are then merged back into a single "complete rewrite". | |
f345b0a0 JH |
15 | |
16 | Further, with -B and -M together, these three modifications should | |
17 | turn into rename-edit of file0 into file1. | |
18 | ||
19 | Starting from the same two files in the tree, we swap file0 and file1. | |
f2b4f0a2 | 20 | With -B, this should be detected as two complete rewrites. |
f345b0a0 JH |
21 | |
22 | Further, with -B and -M together, these should turn into two renames. | |
23 | ' | |
24 | . ./test-lib.sh | |
bfdbee98 | 25 | . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash |
f345b0a0 | 26 | |
db7b9e3a JH |
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) | |
32 | ' | |
33 | ||
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 | |
38 | ' | |
39 | ||
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 | |
47 | ' | |
48 | ||
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 | |
55 | ' | |
56 | ||
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 | |
65 | ' | |
66 | ||
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 | |
74 | ' | |
75 | ||
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 | |
83 | ' | |
84 | ||
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 | |
89 | ' | |
90 | ||
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 | |
98 | ' | |
99 | ||
100 | test_expect_success 'run diff with -B -M (#6)' ' | |
101 | git diff-index -B -M reference >current && | |
102 | ||
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 | |
109 | EOF | |
110 | compare_diff_raw expect current | |
111 | ' | |
112 | ||
113 | test_expect_success 'run diff with -M (#7)' ' | |
114 | git diff-index -M reference >current && | |
115 | ||
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 | |
121 | EOF | |
122 | compare_diff_raw expect current | |
123 | ' | |
124 | ||
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 | |
133 | ' | |
134 | ||
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 | |
141 | EOF | |
142 | compare_diff_raw expect current | |
143 | ' | |
144 | ||
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 | |
150 | EOF | |
151 | compare_diff_raw expect current | |
152 | ' | |
f345b0a0 JH |
153 | |
154 | test_done |