Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t3910-mac-os-precompose.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t3910-mac-os-precompose.sh` 276 lines · 8023 bytes Raw Blame History 1 #!/bin/sh 2 # 3 # Copyright (c) 2012 Torsten Bögershausen 4 # 5 6 test_description='utf-8 decomposed (nfd) converted to precomposed (nfc)' 7 8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 10 11 . ./test-lib.sh 12 13 if ! test_have_prereq UTF8_NFD_TO_NFC 14 then 15 skip_all="filesystem does not corrupt utf-8" 16 test_done 17 fi 18 19 # create utf-8 variables 20 Adiarnfc=$(printf '\303\204') 21 Adiarnfd=$(printf 'A\314\210') 22 23 Odiarnfc=$(printf '\303\226') 24 Odiarnfd=$(printf 'O\314\210') 25 AEligatu=$(printf '\303\206') 26 Invalidu=$(printf '\303\377') 27 28 29 #Create a string with 255 bytes (decomposed) 30 Alongd=$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd #21 Byte 31 Alongd=$Alongd$Alongd$Alongd #63 Byte 32 Alongd=$Alongd$Alongd$Alongd$Alongd$Adiarnfd #255 Byte 33 34 #Create a string with 254 bytes (precomposed) 35 Alongc=$AEligatu$AEligatu$AEligatu$AEligatu$AEligatu #10 Byte 36 Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc #50 Byte 37 Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc #250 Byte 38 Alongc=$Alongc$AEligatu$AEligatu #254 Byte 39 40 41 ls_files_nfc_nfd () { 42 test_when_finished "git config --global --unset core.precomposeunicode" && 43 prglbl=$1 44 prlocl=$2 45 aumlcreat=$3 46 aumllist=$4 47 git config --global core.precomposeunicode $prglbl && 48 ( 49 rm -rf .git && 50 mkdir -p "somewhere/$prglbl/$prlocl/$aumlcreat" && 51 mypwd=$PWD && 52 cd "somewhere/$prglbl/$prlocl/$aumlcreat" && 53 git init && 54 git config core.precomposeunicode $prlocl && 55 git --literal-pathspecs ls-files "$mypwd/somewhere/$prglbl/$prlocl/$aumllist" 2>err && 56 >expected && 57 test_cmp expected err 58 ) 59 } 60 61 test_expect_success "detect if nfd needed" ' 62 precomposeunicode=$(git config core.precomposeunicode) && 63 test "$precomposeunicode" = true && 64 git config core.precomposeunicode true 65 ' 66 test_expect_success "setup" ' 67 >x && 68 git add x && 69 git commit -m "1st commit" && 70 git rm x && 71 git commit -m "rm x" 72 ' 73 test_expect_success "setup case mac" ' 74 git checkout -b mac_os 75 ' 76 # This will test nfd2nfc in git diff 77 test_expect_success "git diff f.Adiar" ' 78 touch f.$Adiarnfc && 79 git add f.$Adiarnfc && 80 echo f.Adiarnfc >f.$Adiarnfc && 81 git diff f.$Adiarnfd >expect && 82 git diff f.$Adiarnfc >actual && 83 test_cmp expect actual && 84 git reset HEAD f.Adiarnfc && 85 rm f.$Adiarnfc expect actual 86 ' 87 # This will test nfd2nfc in git diff-files 88 test_expect_success "git diff-files f.Adiar" ' 89 touch f.$Adiarnfc && 90 git add f.$Adiarnfc && 91 echo f.Adiarnfc >f.$Adiarnfc && 92 git diff-files f.$Adiarnfd >expect && 93 git diff-files f.$Adiarnfc >actual && 94 test_cmp expect actual && 95 git reset HEAD f.Adiarnfc && 96 rm f.$Adiarnfc expect actual 97 ' 98 # This will test nfd2nfc in git diff-index 99 test_expect_success "git diff-index f.Adiar" ' 100 touch f.$Adiarnfc && 101 git add f.$Adiarnfc && 102 echo f.Adiarnfc >f.$Adiarnfc && 103 git diff-index HEAD f.$Adiarnfd >expect && 104 git diff-index HEAD f.$Adiarnfc >actual && 105 test_cmp expect actual && 106 git reset HEAD f.Adiarnfc && 107 rm f.$Adiarnfc expect actual 108 ' 109 # This will test nfd2nfc in readdir() 110 test_expect_success "add file Adiarnfc" ' 111 echo f.Adiarnfc >f.$Adiarnfc && 112 git add f.$Adiarnfc && 113 git commit -m "add f.$Adiarnfc" 114 ' 115 # This will test nfd2nfc in git diff-tree 116 test_expect_success "git diff-tree f.Adiar" ' 117 echo f.Adiarnfc >>f.$Adiarnfc && 118 git diff-tree HEAD f.$Adiarnfd >expect && 119 git diff-tree HEAD f.$Adiarnfc >actual && 120 test_cmp expect actual && 121 git checkout f.$Adiarnfc && 122 rm expect actual 123 ' 124 # This will test nfd2nfc in git stage() 125 test_expect_success "stage file d.Adiarnfd/f.Adiarnfd" ' 126 mkdir d.$Adiarnfd && 127 echo d.$Adiarnfd/f.$Adiarnfd >d.$Adiarnfd/f.$Adiarnfd && 128 git stage d.$Adiarnfd/f.$Adiarnfd && 129 git commit -m "add d.$Adiarnfd/f.$Adiarnfd" 130 ' 131 test_expect_success "add link Adiarnfc" ' 132 ln -s d.$Adiarnfd/f.$Adiarnfd l.$Adiarnfc && 133 git add l.$Adiarnfc && 134 git commit -m "add l.Adiarnfc" 135 ' 136 # This will test git log 137 test_expect_success "git log f.Adiar" ' 138 git log f.$Adiarnfc > f.Adiarnfc.log && 139 git log f.$Adiarnfd > f.Adiarnfd.log && 140 test -s f.Adiarnfc.log && 141 test -s f.Adiarnfd.log && 142 test_cmp f.Adiarnfc.log f.Adiarnfd.log && 143 rm f.Adiarnfc.log f.Adiarnfd.log 144 ' 145 # This will test git ls-files 146 test_expect_success "git lsfiles f.Adiar" ' 147 git ls-files f.$Adiarnfc > f.Adiarnfc.log && 148 git ls-files f.$Adiarnfd > f.Adiarnfd.log && 149 test -s f.Adiarnfc.log && 150 test -s f.Adiarnfd.log && 151 test_cmp f.Adiarnfc.log f.Adiarnfd.log && 152 rm f.Adiarnfc.log f.Adiarnfd.log 153 ' 154 # This will test git mv 155 test_expect_success "git mv" ' 156 git mv f.$Adiarnfd f.$Odiarnfc && 157 git mv d.$Adiarnfd d.$Odiarnfc && 158 git mv l.$Adiarnfd l.$Odiarnfc && 159 git commit -m "mv Adiarnfd Odiarnfc" 160 ' 161 # Files can be checked out as nfc 162 # And the link has been corrected from nfd to nfc 163 test_expect_success "git checkout nfc" ' 164 rm f.$Odiarnfc && 165 git checkout f.$Odiarnfc 166 ' 167 # Make it possible to checkout files with their NFD names 168 test_expect_success "git checkout file nfd" ' 169 rm -f f.* && 170 git checkout f.$Odiarnfd 171 ' 172 # Make it possible to checkout links with their NFD names 173 test_expect_success "git checkout link nfd" ' 174 rm l.* && 175 git checkout l.$Odiarnfd 176 ' 177 test_expect_success "setup case mac2" ' 178 git checkout main && 179 git reset --hard && 180 git checkout -b mac_os_2 181 ' 182 # This will test nfd2nfc in git commit 183 test_expect_success "commit file d2.Adiarnfd/f.Adiarnfd" ' 184 mkdir d2.$Adiarnfd && 185 echo d2.$Adiarnfd/f.$Adiarnfd >d2.$Adiarnfd/f.$Adiarnfd && 186 git add d2.$Adiarnfd/f.$Adiarnfd && 187 git commit -m "add d2.$Adiarnfd/f.$Adiarnfd" -- d2.$Adiarnfd/f.$Adiarnfd 188 ' 189 test_expect_success "setup for long decomposed filename" ' 190 git checkout main && 191 git reset --hard && 192 git checkout -b mac_os_long_nfd_fn 193 ' 194 test_expect_success "Add long decomposed filename" ' 195 echo longd >$Alongd && 196 git add * && 197 git commit -m "Long filename" 198 ' 199 test_expect_success "setup for long precomposed filename" ' 200 git checkout main && 201 git reset --hard && 202 git checkout -b mac_os_long_nfc_fn 203 ' 204 test_expect_success "Add long precomposed filename" ' 205 echo longc >$Alongc && 206 git add * && 207 git commit -m "Long filename" 208 ' 209 210 test_expect_success "status with long non-ASCII filename" ' 211 test_when_finished "rm -rf long-utf8-status" && 212 git init long-utf8-status && 213 ( 214 cd long-utf8-status && 215 test "$(git config --bool core.precomposeunicode)" = true && 216 long_utf8_name=$( 217 printf "%253s\342\200\224" "" | 218 tr " " a 219 ) && 220 test "$(printf "%s" "$long_utf8_name" | wc -c | tr -d " ")" = 256 && 221 printf "content\n" >"$long_utf8_name" && 222 git status --porcelain=v1 >actual 223 ) 224 ' 225 226 test_expect_failure 'handle existing decomposed filenames' ' 227 echo content >"verbatim.$Adiarnfd" && 228 git -c core.precomposeunicode=false add "verbatim.$Adiarnfd" && 229 git commit -m "existing decomposed file" && 230 git ls-files --exclude-standard -o "verbatim*" >untracked && 231 test_must_be_empty untracked 232 ' 233 234 test_expect_success "unicode decomposed: git restore -p . " ' 235 DIRNAMEPWD=dir.Odiarnfc && 236 DIRNAMEINREPO=dir.$Adiarnfc && 237 export DIRNAMEPWD DIRNAMEINREPO && 238 git init "$DIRNAMEPWD" && 239 ( 240 cd "$DIRNAMEPWD" && 241 mkdir "$DIRNAMEINREPO" && 242 cd "$DIRNAMEINREPO" && 243 echo "Initial" >file && 244 git add file && 245 echo "More stuff" >>file && 246 echo y | git restore -p . 247 ) 248 ' 249 250 # Test if the global core.precomposeunicode stops autosensing 251 test_expect_success "respect git config --global core.precomposeunicode" ' 252 test_when_finished "git config --global --unset core.precomposeunicode" && 253 git config --global core.precomposeunicode true && 254 rm -rf .git && 255 git init && 256 precomposeunicode=$(git config core.precomposeunicode) && 257 test "$precomposeunicode" = "true" 258 ' 259 260 test_expect_success "ls-files false false nfd nfd" ' 261 ls_files_nfc_nfd false false $Adiarnfd $Adiarnfd 262 ' 263 264 test_expect_success "ls-files false true nfd nfd" ' 265 ls_files_nfc_nfd false true $Adiarnfd $Adiarnfd 266 ' 267 268 test_expect_success "ls-files true false nfd nfd" ' 269 ls_files_nfc_nfd true false $Adiarnfd $Adiarnfd 270 ' 271 272 test_expect_success "ls-files true true nfd nfd" ' 273 ls_files_nfc_nfd true true $Adiarnfd $Adiarnfd 274 ' 275 276 test_done