Merge branch 'ma/maintenance-crontab-fix'
[git] / t / t4048-diff-combined-binary.sh
1 #!/bin/sh
2
3 test_description='combined and merge diff handle binary files and textconv'
4 . ./test-lib.sh
5
6 test_expect_success 'setup binary merge conflict' '
7         echo oneQ1 | q_to_nul >binary &&
8         git add binary &&
9         git commit -m one &&
10         echo twoQ2 | q_to_nul >binary &&
11         git commit -a -m two &&
12         two=$(git rev-parse --short HEAD:binary) &&
13         git checkout -b branch-binary HEAD^ &&
14         echo threeQ3 | q_to_nul >binary &&
15         git commit -a -m three &&
16         three=$(git rev-parse --short HEAD:binary) &&
17         test_must_fail git merge master &&
18         echo resolvedQhooray | q_to_nul >binary &&
19         git commit -a -m resolved &&
20         res=$(git rev-parse --short HEAD:binary)
21 '
22
23 cat >expect <<EOF
24 resolved
25
26 diff --git a/binary b/binary
27 index $three..$res 100644
28 Binary files a/binary and b/binary differ
29 resolved
30
31 diff --git a/binary b/binary
32 index $two..$res 100644
33 Binary files a/binary and b/binary differ
34 EOF
35 test_expect_success 'diff -m indicates binary-ness' '
36         git show --format=%s -m >actual &&
37         test_cmp expect actual
38 '
39
40 cat >expect <<EOF
41 resolved
42
43 diff --combined binary
44 index $three,$two..$res
45 Binary files differ
46 EOF
47 test_expect_success 'diff -c indicates binary-ness' '
48         git show --format=%s -c >actual &&
49         test_cmp expect actual
50 '
51
52 cat >expect <<EOF
53 resolved
54
55 diff --cc binary
56 index $three,$two..$res
57 Binary files differ
58 EOF
59 test_expect_success 'diff --cc indicates binary-ness' '
60         git show --format=%s --cc >actual &&
61         test_cmp expect actual
62 '
63
64 test_expect_success 'setup non-binary with binary attribute' '
65         git checkout master &&
66         test_commit one text &&
67         test_commit two text &&
68         two=$(git rev-parse --short HEAD:text) &&
69         git checkout -b branch-text HEAD^ &&
70         test_commit three text &&
71         three=$(git rev-parse --short HEAD:text) &&
72         test_must_fail git merge master &&
73         test_commit resolved text &&
74         res=$(git rev-parse --short HEAD:text) &&
75         echo text -diff >.gitattributes
76 '
77
78 cat >expect <<EOF
79 resolved
80
81 diff --git a/text b/text
82 index $three..$res 100644
83 Binary files a/text and b/text differ
84 resolved
85
86 diff --git a/text b/text
87 index $two..$res 100644
88 Binary files a/text and b/text differ
89 EOF
90 test_expect_success 'diff -m respects binary attribute' '
91         git show --format=%s -m >actual &&
92         test_cmp expect actual
93 '
94
95 cat >expect <<EOF
96 resolved
97
98 diff --combined text
99 index $three,$two..$res
100 Binary files differ
101 EOF
102 test_expect_success 'diff -c respects binary attribute' '
103         git show --format=%s -c >actual &&
104         test_cmp expect actual
105 '
106
107 cat >expect <<EOF
108 resolved
109
110 diff --cc text
111 index $three,$two..$res
112 Binary files differ
113 EOF
114 test_expect_success 'diff --cc respects binary attribute' '
115         git show --format=%s --cc >actual &&
116         test_cmp expect actual
117 '
118
119 test_expect_success 'setup textconv attribute' '
120         echo "text diff=upcase" >.gitattributes &&
121         git config diff.upcase.textconv "tr a-z A-Z <"
122 '
123
124 cat >expect <<EOF
125 resolved
126
127 diff --git a/text b/text
128 index $three..$res 100644
129 --- a/text
130 +++ b/text
131 @@ -1 +1 @@
132 -THREE
133 +RESOLVED
134 resolved
135
136 diff --git a/text b/text
137 index $two..$res 100644
138 --- a/text
139 +++ b/text
140 @@ -1 +1 @@
141 -TWO
142 +RESOLVED
143 EOF
144 test_expect_success 'diff -m respects textconv attribute' '
145         git show --format=%s -m >actual &&
146         test_cmp expect actual
147 '
148
149 cat >expect <<EOF
150 resolved
151
152 diff --combined text
153 index $three,$two..$res
154 --- a/text
155 +++ b/text
156 @@@ -1,1 -1,1 +1,1 @@@
157 - THREE
158  -TWO
159 ++RESOLVED
160 EOF
161 test_expect_success 'diff -c respects textconv attribute' '
162         git show --format=%s -c >actual &&
163         test_cmp expect actual
164 '
165
166 cat >expect <<EOF
167 resolved
168
169 diff --cc text
170 index $three,$two..$res
171 --- a/text
172 +++ b/text
173 @@@ -1,1 -1,1 +1,1 @@@
174 - THREE
175  -TWO
176 ++RESOLVED
177 EOF
178 test_expect_success 'diff --cc respects textconv attribute' '
179         git show --format=%s --cc >actual &&
180         test_cmp expect actual
181 '
182
183 cat >expect <<EOF
184 diff --combined text
185 index $three,$two..$res
186 --- a/text
187 +++ b/text
188 @@@ -1,1 -1,1 +1,1 @@@
189 - three
190  -two
191 ++resolved
192 EOF
193 test_expect_success 'diff-tree plumbing does not respect textconv' '
194         git diff-tree HEAD -c -p >full &&
195         tail -n +2 full >actual &&
196         test_cmp expect actual
197 '
198
199 cat >expect <<EOF
200 diff --cc text
201 index $three,$two..0000000
202 --- a/text
203 +++ b/text
204 @@@ -1,1 -1,1 +1,5 @@@
205 ++<<<<<<< HEAD
206  +THREE
207 ++=======
208 + TWO
209 ++>>>>>>> MASTER
210 EOF
211 test_expect_success 'diff --cc respects textconv on worktree file' '
212         git reset --hard HEAD^ &&
213         test_must_fail git merge master &&
214         git diff >actual &&
215         test_cmp expect actual
216 '
217
218 test_done