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