Torsten Bögershausen | 76759c7 | 2012-07-08 15:50:25 +0200 | [diff] [blame] | 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 | . ./test-lib.sh |
| 9 | |
Michael J Gruber | 308566e | 2012-07-30 11:57:18 +0200 | [diff] [blame] | 10 | if ! test_have_prereq UTF8_NFD_TO_NFC |
| 11 | then |
| 12 | skip_all="filesystem does not corrupt utf-8" |
| 13 | test_done |
| 14 | fi |
| 15 | |
| 16 | # create utf-8 variables |
Elia Pinto | a4cf6b4 | 2014-04-30 09:22:55 -0700 | [diff] [blame] | 17 | Adiarnfc=$(printf '\303\204') |
| 18 | Adiarnfd=$(printf 'A\314\210') |
Torsten Bögershausen | 76759c7 | 2012-07-08 15:50:25 +0200 | [diff] [blame] | 19 | |
Elia Pinto | a4cf6b4 | 2014-04-30 09:22:55 -0700 | [diff] [blame] | 20 | Odiarnfc=$(printf '\303\226') |
| 21 | Odiarnfd=$(printf 'O\314\210') |
| 22 | AEligatu=$(printf '\303\206') |
| 23 | Invalidu=$(printf '\303\377') |
Torsten Bögershausen | 76759c7 | 2012-07-08 15:50:25 +0200 | [diff] [blame] | 24 | |
| 25 | |
Michael J Gruber | 308566e | 2012-07-30 11:57:18 +0200 | [diff] [blame] | 26 | #Create a string with 255 bytes (decomposed) |
| 27 | Alongd=$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd #21 Byte |
| 28 | Alongd=$Alongd$Alongd$Alongd #63 Byte |
| 29 | Alongd=$Alongd$Alongd$Alongd$Alongd$Adiarnfd #255 Byte |
Torsten Bögershausen | 76759c7 | 2012-07-08 15:50:25 +0200 | [diff] [blame] | 30 | |
Michael J Gruber | 308566e | 2012-07-30 11:57:18 +0200 | [diff] [blame] | 31 | #Create a string with 254 bytes (precomposed) |
| 32 | Alongc=$AEligatu$AEligatu$AEligatu$AEligatu$AEligatu #10 Byte |
| 33 | Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc #50 Byte |
| 34 | Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc #250 Byte |
| 35 | Alongc=$Alongc$AEligatu$AEligatu #254 Byte |
Torsten Bögershausen | 76759c7 | 2012-07-08 15:50:25 +0200 | [diff] [blame] | 36 | |
Michael J Gruber | 308566e | 2012-07-30 11:57:18 +0200 | [diff] [blame] | 37 | test_expect_success "detect if nfd needed" ' |
Elia Pinto | a4cf6b4 | 2014-04-30 09:22:55 -0700 | [diff] [blame] | 38 | precomposeunicode=$(git config core.precomposeunicode) && |
Torsten Bögershausen | 92b0c8b | 2013-08-27 15:50:40 +0200 | [diff] [blame] | 39 | test "$precomposeunicode" = true && |
Michael J Gruber | 308566e | 2012-07-30 11:57:18 +0200 | [diff] [blame] | 40 | git config core.precomposeunicode true |
| 41 | ' |
| 42 | test_expect_success "setup" ' |
| 43 | >x && |
| 44 | git add x && |
| 45 | git commit -m "1st commit" && |
| 46 | git rm x && |
| 47 | git commit -m "rm x" |
| 48 | ' |
| 49 | test_expect_success "setup case mac" ' |
| 50 | git checkout -b mac_os |
| 51 | ' |
Alexander Rinass | 90a78b8 | 2016-05-13 22:41:02 +0200 | [diff] [blame] | 52 | # This will test nfd2nfc in git diff |
| 53 | test_expect_success "git diff f.Adiar" ' |
| 54 | touch f.$Adiarnfc && |
| 55 | git add f.$Adiarnfc && |
| 56 | echo f.Adiarnfc >f.$Adiarnfc && |
| 57 | git diff f.$Adiarnfd >expect && |
| 58 | git diff f.$Adiarnfc >actual && |
| 59 | test_cmp expect actual && |
| 60 | git reset HEAD f.Adiarnfc && |
| 61 | rm f.$Adiarnfc expect actual |
| 62 | ' |
| 63 | # This will test nfd2nfc in git diff-files |
| 64 | test_expect_success "git diff-files f.Adiar" ' |
| 65 | touch f.$Adiarnfc && |
| 66 | git add f.$Adiarnfc && |
| 67 | echo f.Adiarnfc >f.$Adiarnfc && |
| 68 | git diff-files f.$Adiarnfd >expect && |
| 69 | git diff-files f.$Adiarnfc >actual && |
| 70 | test_cmp expect actual && |
| 71 | git reset HEAD f.Adiarnfc && |
| 72 | rm f.$Adiarnfc expect actual |
| 73 | ' |
| 74 | # This will test nfd2nfc in git diff-index |
| 75 | test_expect_success "git diff-index f.Adiar" ' |
| 76 | touch f.$Adiarnfc && |
| 77 | git add f.$Adiarnfc && |
| 78 | echo f.Adiarnfc >f.$Adiarnfc && |
| 79 | git diff-index HEAD f.$Adiarnfd >expect && |
| 80 | git diff-index HEAD f.$Adiarnfc >actual && |
| 81 | test_cmp expect actual && |
| 82 | git reset HEAD f.Adiarnfc && |
| 83 | rm f.$Adiarnfc expect actual |
| 84 | ' |
Michael J Gruber | 308566e | 2012-07-30 11:57:18 +0200 | [diff] [blame] | 85 | # This will test nfd2nfc in readdir() |
| 86 | test_expect_success "add file Adiarnfc" ' |
| 87 | echo f.Adiarnfc >f.$Adiarnfc && |
| 88 | git add f.$Adiarnfc && |
| 89 | git commit -m "add f.$Adiarnfc" |
| 90 | ' |
Alexander Rinass | 90a78b8 | 2016-05-13 22:41:02 +0200 | [diff] [blame] | 91 | # This will test nfd2nfc in git diff-tree |
| 92 | test_expect_success "git diff-tree f.Adiar" ' |
| 93 | echo f.Adiarnfc >>f.$Adiarnfc && |
| 94 | git diff-tree HEAD f.$Adiarnfd >expect && |
| 95 | git diff-tree HEAD f.$Adiarnfc >actual && |
| 96 | test_cmp expect actual && |
| 97 | git checkout f.$Adiarnfc && |
| 98 | rm expect actual |
| 99 | ' |
Michael J Gruber | 308566e | 2012-07-30 11:57:18 +0200 | [diff] [blame] | 100 | # This will test nfd2nfc in git stage() |
| 101 | test_expect_success "stage file d.Adiarnfd/f.Adiarnfd" ' |
| 102 | mkdir d.$Adiarnfd && |
| 103 | echo d.$Adiarnfd/f.$Adiarnfd >d.$Adiarnfd/f.$Adiarnfd && |
| 104 | git stage d.$Adiarnfd/f.$Adiarnfd && |
| 105 | git commit -m "add d.$Adiarnfd/f.$Adiarnfd" |
| 106 | ' |
| 107 | test_expect_success "add link Adiarnfc" ' |
| 108 | ln -s d.$Adiarnfd/f.$Adiarnfd l.$Adiarnfc && |
| 109 | git add l.$Adiarnfc && |
| 110 | git commit -m "add l.Adiarnfc" |
| 111 | ' |
| 112 | # This will test git log |
| 113 | test_expect_success "git log f.Adiar" ' |
| 114 | git log f.$Adiarnfc > f.Adiarnfc.log && |
| 115 | git log f.$Adiarnfd > f.Adiarnfd.log && |
| 116 | test -s f.Adiarnfc.log && |
| 117 | test -s f.Adiarnfd.log && |
| 118 | test_cmp f.Adiarnfc.log f.Adiarnfd.log && |
| 119 | rm f.Adiarnfc.log f.Adiarnfd.log |
| 120 | ' |
| 121 | # This will test git ls-files |
| 122 | test_expect_success "git lsfiles f.Adiar" ' |
| 123 | git ls-files f.$Adiarnfc > f.Adiarnfc.log && |
| 124 | git ls-files f.$Adiarnfd > f.Adiarnfd.log && |
| 125 | test -s f.Adiarnfc.log && |
| 126 | test -s f.Adiarnfd.log && |
| 127 | test_cmp f.Adiarnfc.log f.Adiarnfd.log && |
| 128 | rm f.Adiarnfc.log f.Adiarnfd.log |
| 129 | ' |
| 130 | # This will test git mv |
| 131 | test_expect_success "git mv" ' |
| 132 | git mv f.$Adiarnfd f.$Odiarnfc && |
| 133 | git mv d.$Adiarnfd d.$Odiarnfc && |
| 134 | git mv l.$Adiarnfd l.$Odiarnfc && |
| 135 | git commit -m "mv Adiarnfd Odiarnfc" |
| 136 | ' |
| 137 | # Files can be checked out as nfc |
| 138 | # And the link has been corrected from nfd to nfc |
| 139 | test_expect_success "git checkout nfc" ' |
| 140 | rm f.$Odiarnfc && |
| 141 | git checkout f.$Odiarnfc |
| 142 | ' |
| 143 | # Make it possible to checkout files with their NFD names |
| 144 | test_expect_success "git checkout file nfd" ' |
| 145 | rm -f f.* && |
| 146 | git checkout f.$Odiarnfd |
| 147 | ' |
| 148 | # Make it possible to checkout links with their NFD names |
| 149 | test_expect_success "git checkout link nfd" ' |
| 150 | rm l.* && |
| 151 | git checkout l.$Odiarnfd |
| 152 | ' |
| 153 | test_expect_success "setup case mac2" ' |
| 154 | git checkout master && |
| 155 | git reset --hard && |
| 156 | git checkout -b mac_os_2 |
| 157 | ' |
| 158 | # This will test nfd2nfc in git commit |
| 159 | test_expect_success "commit file d2.Adiarnfd/f.Adiarnfd" ' |
| 160 | mkdir d2.$Adiarnfd && |
| 161 | echo d2.$Adiarnfd/f.$Adiarnfd >d2.$Adiarnfd/f.$Adiarnfd && |
| 162 | git add d2.$Adiarnfd/f.$Adiarnfd && |
| 163 | git commit -m "add d2.$Adiarnfd/f.$Adiarnfd" -- d2.$Adiarnfd/f.$Adiarnfd |
| 164 | ' |
| 165 | test_expect_success "setup for long decomposed filename" ' |
| 166 | git checkout master && |
| 167 | git reset --hard && |
| 168 | git checkout -b mac_os_long_nfd_fn |
| 169 | ' |
| 170 | test_expect_success "Add long decomposed filename" ' |
| 171 | echo longd >$Alongd && |
| 172 | git add * && |
| 173 | git commit -m "Long filename" |
| 174 | ' |
| 175 | test_expect_success "setup for long precomposed filename" ' |
| 176 | git checkout master && |
| 177 | git reset --hard && |
| 178 | git checkout -b mac_os_long_nfc_fn |
| 179 | ' |
| 180 | test_expect_success "Add long precomposed filename" ' |
| 181 | echo longc >$Alongc && |
| 182 | git add * && |
| 183 | git commit -m "Long filename" |
| 184 | ' |
Jeff King | 750b2e4 | 2014-04-28 12:16:31 -0400 | [diff] [blame] | 185 | |
| 186 | test_expect_failure 'handle existing decomposed filenames' ' |
| 187 | echo content >"verbatim.$Adiarnfd" && |
| 188 | git -c core.precomposeunicode=false add "verbatim.$Adiarnfd" && |
| 189 | git commit -m "existing decomposed file" && |
| 190 | >expect && |
| 191 | git ls-files --exclude-standard -o "verbatim*" >untracked && |
| 192 | test_cmp expect untracked |
| 193 | ' |
| 194 | |
Michael J Gruber | 308566e | 2012-07-30 11:57:18 +0200 | [diff] [blame] | 195 | # Test if the global core.precomposeunicode stops autosensing |
| 196 | # Must be the last test case |
| 197 | test_expect_success "respect git config --global core.precomposeunicode" ' |
| 198 | git config --global core.precomposeunicode true && |
| 199 | rm -rf .git && |
| 200 | git init && |
Elia Pinto | a4cf6b4 | 2014-04-30 09:22:55 -0700 | [diff] [blame] | 201 | precomposeunicode=$(git config core.precomposeunicode) && |
Michael J Gruber | 308566e | 2012-07-30 11:57:18 +0200 | [diff] [blame] | 202 | test "$precomposeunicode" = "true" |
| 203 | ' |
Torsten Bögershausen | 76759c7 | 2012-07-08 15:50:25 +0200 | [diff] [blame] | 204 | |
| 205 | test_done |