| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='CRLF merge conflict across text=auto change |
| 4 | |
| 5 | * [main] remove .gitattributes |
| 6 | ! [side] add line from b |
| 7 | -- |
| 8 | + [side] add line from b |
| 9 | * [main] remove .gitattributes |
| 10 | * [main^] add line from a |
| 11 | * [main~2] normalize file |
| 12 | *+ [side^] Initial |
| 13 | ' |
| 14 | |
| 15 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 16 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 17 | |
| 18 | . ./test-lib.sh |
| 19 | |
| 20 | test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b |
| 21 | |
| 22 | compare_files () { |
| 23 | tr '\015\000' QN <"$1" >"$1".expect && |
| 24 | tr '\015\000' QN <"$2" >"$2".actual && |
| 25 | test_cmp "$1".expect "$2".actual && |
| 26 | rm "$1".expect "$2".actual |
| 27 | } |
| 28 | |
| 29 | test_expect_success setup ' |
| 30 | git config core.autocrlf false && |
| 31 | |
| 32 | echo first line | append_cr >file && |
| 33 | echo first line >control_file && |
| 34 | echo only line >inert_file && |
| 35 | |
| 36 | git add file control_file inert_file && |
| 37 | test_tick && |
| 38 | git commit -m "Initial" && |
| 39 | git tag initial && |
| 40 | git branch side && |
| 41 | |
| 42 | echo "* text=auto" >.gitattributes && |
| 43 | echo first line >file && |
| 44 | git add .gitattributes file && |
| 45 | test_tick && |
| 46 | git commit -m "normalize file" && |
| 47 | |
| 48 | echo same line | append_cr >>file && |
| 49 | echo same line >>control_file && |
| 50 | git add file control_file && |
| 51 | test_tick && |
| 52 | git commit -m "add line from a" && |
| 53 | git tag a && |
| 54 | |
| 55 | git rm .gitattributes && |
| 56 | rm file && |
| 57 | git checkout file && |
| 58 | test_tick && |
| 59 | git commit -m "remove .gitattributes" && |
| 60 | git tag c && |
| 61 | |
| 62 | git checkout side && |
| 63 | echo same line | append_cr >>file && |
| 64 | echo same line >>control_file && |
| 65 | git add file control_file && |
| 66 | test_tick && |
| 67 | git commit -m "add line from b" && |
| 68 | git tag b && |
| 69 | |
| 70 | git checkout main |
| 71 | ' |
| 72 | |
| 73 | test_expect_success 'set up fuzz_conflict() helper' ' |
| 74 | fuzz_conflict() { |
| 75 | sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@" |
| 76 | } |
| 77 | ' |
| 78 | |
| 79 | test_expect_success 'Merge after setting text=auto' ' |
| 80 | cat <<-\EOF >expected && |
| 81 | first line |
| 82 | same line |
| 83 | EOF |
| 84 | |
| 85 | if test_have_prereq NATIVE_CRLF; then |
| 86 | append_cr <expected >expected.temp && |
| 87 | mv expected.temp expected |
| 88 | fi && |
| 89 | git config merge.renormalize true && |
| 90 | git rm -fr . && |
| 91 | rm -f .gitattributes && |
| 92 | git reset --hard a && |
| 93 | git merge b && |
| 94 | compare_files expected file |
| 95 | ' |
| 96 | |
| 97 | test_expect_success 'Merge addition of text=auto eol=LF' ' |
| 98 | git config core.eol lf && |
| 99 | cat <<-\EOF >expected && |
| 100 | first line |
| 101 | same line |
| 102 | EOF |
| 103 | |
| 104 | git config merge.renormalize true && |
| 105 | git rm -fr . && |
| 106 | rm -f .gitattributes && |
| 107 | git reset --hard b && |
| 108 | git merge a && |
| 109 | compare_files expected file |
| 110 | ' |
| 111 | |
| 112 | test_expect_success 'Merge addition of text=auto eol=CRLF' ' |
| 113 | git config core.eol crlf && |
| 114 | cat <<-\EOF >expected && |
| 115 | first line |
| 116 | same line |
| 117 | EOF |
| 118 | |
| 119 | append_cr <expected >expected.temp && |
| 120 | mv expected.temp expected && |
| 121 | git config merge.renormalize true && |
| 122 | git rm -fr . && |
| 123 | rm -f .gitattributes && |
| 124 | git reset --hard b && |
| 125 | echo >&2 "After git reset --hard b" && |
| 126 | git ls-files -s --eol >&2 && |
| 127 | git merge a && |
| 128 | compare_files expected file |
| 129 | ' |
| 130 | |
| 131 | test_expect_success 'Detect CRLF/LF conflict after setting text=auto' ' |
| 132 | git config core.eol native && |
| 133 | echo "<<<<<<<" >expected && |
| 134 | echo first line >>expected && |
| 135 | echo same line >>expected && |
| 136 | echo ======= >>expected && |
| 137 | echo first line | append_cr >>expected && |
| 138 | echo same line | append_cr >>expected && |
| 139 | echo ">>>>>>>" >>expected && |
| 140 | git config merge.renormalize false && |
| 141 | rm -f .gitattributes && |
| 142 | git reset --hard a && |
| 143 | test_must_fail git merge b && |
| 144 | fuzz_conflict file >file.fuzzy && |
| 145 | compare_files expected file.fuzzy |
| 146 | ' |
| 147 | |
| 148 | test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' ' |
| 149 | echo "<<<<<<<" >expected && |
| 150 | echo first line | append_cr >>expected && |
| 151 | echo same line | append_cr >>expected && |
| 152 | echo ======= >>expected && |
| 153 | echo first line >>expected && |
| 154 | echo same line >>expected && |
| 155 | echo ">>>>>>>" >>expected && |
| 156 | git config merge.renormalize false && |
| 157 | rm -f .gitattributes && |
| 158 | git reset --hard b && |
| 159 | test_must_fail git merge a && |
| 160 | fuzz_conflict file >file.fuzzy && |
| 161 | compare_files expected file.fuzzy |
| 162 | ' |
| 163 | |
| 164 | test_expect_success 'checkout -m after setting text=auto' ' |
| 165 | cat <<-\EOF >expected && |
| 166 | first line |
| 167 | same line |
| 168 | EOF |
| 169 | |
| 170 | git config merge.renormalize true && |
| 171 | git rm -fr . && |
| 172 | rm -f .gitattributes && |
| 173 | git reset --hard initial && |
| 174 | git restore --source=a -- . && |
| 175 | git checkout -m b && |
| 176 | git diff --no-index --ignore-cr-at-eol expected file |
| 177 | ' |
| 178 | |
| 179 | test_expect_success 'checkout -m addition of text=auto' ' |
| 180 | cat <<-\EOF >expected && |
| 181 | first line |
| 182 | same line |
| 183 | EOF |
| 184 | |
| 185 | git config merge.renormalize true && |
| 186 | git rm -fr . && |
| 187 | rm -f .gitattributes file && |
| 188 | git reset --hard initial && |
| 189 | git restore --source=b -- . && |
| 190 | git checkout -m a && |
| 191 | git diff --no-index --ignore-cr-at-eol expected file |
| 192 | ' |
| 193 | |
| 194 | test_expect_success 'Test delete/normalize conflict' ' |
| 195 | git checkout -f side && |
| 196 | git rm -fr . && |
| 197 | rm -f .gitattributes && |
| 198 | git reset --hard initial && |
| 199 | git rm file && |
| 200 | git commit -m "remove file" && |
| 201 | git checkout main && |
| 202 | git reset --hard a^ && |
| 203 | git merge side && |
| 204 | test_path_is_missing file |
| 205 | ' |
| 206 | |
| 207 | test_expect_success 'rename/delete vs. renormalization' ' |
| 208 | git init subrepo && |
| 209 | ( |
| 210 | cd subrepo && |
| 211 | echo foo >oldfile && |
| 212 | git add oldfile && |
| 213 | git commit -m original && |
| 214 | |
| 215 | git branch rename && |
| 216 | git branch nuke && |
| 217 | |
| 218 | git checkout rename && |
| 219 | git mv oldfile newfile && |
| 220 | git commit -m renamed && |
| 221 | |
| 222 | git checkout nuke && |
| 223 | git rm oldfile && |
| 224 | git commit -m deleted && |
| 225 | |
| 226 | git checkout rename^0 && |
| 227 | test_must_fail git -c merge.renormalize=true merge nuke >out && |
| 228 | |
| 229 | grep "rename/delete" out |
| 230 | ) |
| 231 | ' |
| 232 | |
| 233 | test_done |