1#!/bin/sh 2 3test_description='combined and merge diff handle binary files and textconv' 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 6 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 && 15 two=$(git rev-parse --short HEAD:binary) && 16 git checkout -b branch-binary HEAD^ && 17 echo threeQ3 | q_to_nul >binary && 18 git commit -a -m three && 19 three=$(git rev-parse --short HEAD:binary) && 20 test_must_fail git merge main && 21 echo resolvedQhooray | q_to_nul >binary && 22 git commit -a -m resolved && 23 res=$(git rev-parse --short HEAD:binary) 24' 25 26cat >expect <<EOF 27resolved 28 29diff --git a/binary b/binary 30index $three..$res 100644 31Binary files a/binary and b/binary differ 32resolved 33 34diff --git a/binary b/binary 35index $two..$res 100644 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 43cat >expect <<EOF 44resolved 45 46diff --combined binary 47index $three,$two..$res 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 55cat >expect <<EOF 56resolved 57 58diff --cc binary 59index $three,$two..$res 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' ' 68 git checkout main && 69 test_commit one text && 70 test_commit two text && 71 two=$(git rev-parse --short HEAD:text) && 72 git checkout -b branch-text HEAD^ && 73 test_commit three text && 74 three=$(git rev-parse --short HEAD:text) && 75 test_must_fail git merge main && 76 test_commit resolved text && 77 res=$(git rev-parse --short HEAD:text) && 78 echo text -diff >.gitattributes 79' 80 81cat >expect <<EOF 82resolved 83 84diff --git a/text b/text 85index $three..$res 100644 86Binary files a/text and b/text differ 87resolved 88 89diff --git a/text b/text 90index $two..$res 100644 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 98cat >expect <<EOF 99resolved 100 101diff --combined text 102index $three,$two..$res 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 110cat >expect <<EOF 111resolved 112 113diff --cc text 114index $three,$two..$res 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 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 127cat >expect <<EOF 128resolved 129 130diff --git a/text b/text 131index $three..$res 100644 132--- a/text 133+++ b/text 134@@ -1 +1 @@ 135-THREE 136+RESOLVED 137resolved 138 139diff --git a/text b/text 140index $two..$res 100644 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 152cat >expect <<EOF 153resolved 154 155diff --combined text 156index $three,$two..$res 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 169cat >expect <<EOF 170resolved 171 172diff --cc text 173index $three,$two..$res 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 186cat >expect <<EOF 187diff --combined text 188index $three,$two..$res 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 202cat >expect <<EOF 203diff --cc text 204index $three,$two..0000000 205--- a/text 206+++ b/text 207@@@ -1,1 -1,1 +1,5 @@@ 208++<<<<<<< HEAD 209 +THREE 210++======= 211+ TWO 212++>>>>>>> MAIN 213EOF 214test_expect_success 'diff --cc respects textconv on worktree file' ' 215 git reset --hard HEAD^ && 216 test_must_fail git merge main && 217 git diff >actual && 218 test_cmp expect actual 219' 220 221test_done 222