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