summaryrefslogtreecommitdiff
path: root/t/t4008-diff-break-rewrite.sh
blob: 040d0ddbd4c0f7a0b33337602be7e5910954e09f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/sh
#
# Copyright (c) 2005 Junio C Hamano
#

test_description='Break and then rename

We have two very different files, file0 and file1, registered in a tree.

We update file1 so drastically that it is more similar to file0, and
then remove file0.  With -B, changes to file1 should be broken into
separate delete and create, resulting in removal of file0, removal of
original file1 and creation of completely rewritten file1.

Further, with -B and -M together, these three modifications should
turn into rename-edit of file0 into file1.

Starting from the same two files in the tree, we swap file0 and file1.
With -B, this should be detected as two complete rewrites, resulting in
four changes in total.

Further, with -B and -M together, these should turn into two renames.
'
. ./test-lib.sh
. ../diff-lib.sh ;# test-lib chdir's into trash

test_expect_success \
    setup \
    'cat ../../README >file0 &&
     cat ../../COPYING >file1 &&
    git-update-cache --add file0 file1 &&
    tree=$(git-write-tree) &&
    echo "$tree"'

test_expect_success \
    'change file1 with copy-edit of file0 and remove file0' \
    'sed -e "s/git/GIT/" file0 >file1 &&
     rm -f file0 &&
    git-update-cache --remove file0 file1'

test_expect_success \
    'run diff with -B' \
    'git-diff-cache -B --cached "$tree" >current'

cat >expected <<\EOF
:100644 000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 0000000000000000000000000000000000000000 D	file0
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 11e331465a89c394dc25c780de230043750c1ec8 M100	file1
EOF

test_expect_success \
    'validate result of -B (#1)' \
    'compare_diff_raw expected current'

test_expect_success \
    'run diff with -B and -M' \
    'git-diff-cache -B -M "$tree" >current'

cat >expected <<\EOF
:100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 08bb2fb671deff4c03a4d4a0a1315dff98d5732c R100	file0	file1
EOF

test_expect_success \
    'validate result of -B -M (#2)' \
    'compare_diff_raw expected current'

test_expect_success \
    'swap file0 and file1' \
    'rm -f file0 file1 &&
     git-read-tree -m $tree &&
     git-checkout-cache -f -u -a &&
     mv file0 tmp &&
     mv file1 file0 &&
     mv tmp file1 &&
     git-update-cache file0 file1'

test_expect_success \
    'run diff with -B' \
    'git-diff-cache -B "$tree" >current'

cat >expected <<\EOF
:100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 6ff87c4664981e4397625791c8ea3bbb5f2279a3 M100	file0
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M100	file1
EOF

test_expect_success \
    'validate result of -B (#3)' \
    'compare_diff_raw expected current'

test_expect_success \
    'run diff with -B and -M' \
    'git-diff-cache -B -M "$tree" >current'

cat >expected <<\EOF
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100	file1	file0
:100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 R100	file0	file1
EOF

test_expect_success \
    'validate result of -B -M (#4)' \
    'compare_diff_raw expected current'

test_expect_success \
    'make file0 into something completely different' \
    'rm -f file0 &&
     ln -s frotz file0 &&
     git-update-cache file0 file1'

test_expect_success \
    'run diff with -B' \
    'git-diff-cache -B "$tree" >current'

cat >expected <<\EOF
:100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 67be421f88824578857624f7b3dc75e99a8a1481 T	file0
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M100	file1
EOF

test_expect_success \
    'validate result of -B (#5)' \
    'compare_diff_raw expected current'

test_expect_success \
    'run diff with -B' \
    'git-diff-cache -B -M "$tree" >current'

# This should not mistake file0 as the copy source of new file1
# due to type differences.
cat >expected <<\EOF
:100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 67be421f88824578857624f7b3dc75e99a8a1481 T	file0
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M100	file1
EOF

test_expect_success \
    'validate result of -B -M (#6)' \
    'compare_diff_raw expected current'

test_expect_success \
    'run diff with -M' \
    'git-diff-cache -M "$tree" >current'

# This should not mistake file0 as the copy source of new file1
# due to type differences.
cat >expected <<\EOF
:100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 67be421f88824578857624f7b3dc75e99a8a1481 T	file0
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M	file1
EOF

test_expect_success \
    'validate result of -M (#7)' \
    'compare_diff_raw expected current'

test_expect_success \
    'file1 edited to look like file0 and file0 rename-edited to file2' \
    'rm -f file0 file1 &&
     git-read-tree -m $tree &&
     git-checkout-cache -f -u -a &&
     sed -e "s/git/GIT/" file0 >file1 &&
     sed -e "s/git/GET/" file0 >file2 &&
     rm -f file0
     git-update-cache --add --remove file0 file1 file2'

test_expect_success \
    'run diff with -B' \
    'git-diff-cache -B "$tree" >current'

cat >expected <<\EOF
:100644 000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 0000000000000000000000000000000000000000 D	file0
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 08bb2fb671deff4c03a4d4a0a1315dff98d5732c M100	file1
:000000 100644 0000000000000000000000000000000000000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 N	file2
EOF

test_expect_success \
    'validate result of -B (#8)' \
    'compare_diff_raw expected current'

test_expect_success \
    'run diff with -B -M' \
    'git-diff-cache -B -M "$tree" >current'

cat >expected <<\EOF
:100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 08bb2fb671deff4c03a4d4a0a1315dff98d5732c C095	file0	file1
:100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 59f832e5c8b3f7e486be15ad0cd3e95ba9af8998 R095	file0	file2
EOF

test_expect_success \
    'validate result of -B -M (#9)' \
    'compare_diff_raw expected current'

test_done