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