#!/bin/sh # # Copyright (c) 2012 Torsten Bögershausen # global test_description := ''utf-8 decomposed (nfd) converted to precomposed (nfc)'' source ./test-lib.sh if ! test_have_prereq UTF8_NFD_TO_NFC { global skip_all := '"filesystem does not corrupt utf-8'" test_done } # create utf-8 variables global Adiarnfc := $[printf '\303\204] global Adiarnfd := $[printf 'A\314\210] global Odiarnfc := $[printf '\303\226] global Odiarnfd := $[printf 'O\314\210] global AEligatu := $[printf '\303\206] global Invalidu := $[printf '\303\377] #Create a string with 255 bytes (decomposed) global Alongd := "$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd" #21 Byte global Alongd := "$Alongd$Alongd$Alongd" #63 Byte global Alongd := "$Alongd$Alongd$Alongd$Alongd$Adiarnfd" #255 Byte #Create a string with 254 bytes (precomposed) global Alongc := "$AEligatu$AEligatu$AEligatu$AEligatu$AEligatu" #10 Byte global Alongc := "$Alongc$Alongc$Alongc$Alongc$Alongc" #50 Byte global Alongc := "$Alongc$Alongc$Alongc$Alongc$Alongc" #250 Byte global Alongc := "$Alongc$AEligatu$AEligatu" #254 Byte test_expect_success "detect if nfd needed" ' precomposeunicode=$(git config core.precomposeunicode) && test "$precomposeunicode" = true && git config core.precomposeunicode true ' test_expect_success "setup" ' >x && git add x && git commit -m "1st commit" && git rm x && git commit -m "rm x" ' test_expect_success "setup case mac" ' git checkout -b mac_os ' # This will test nfd2nfc in git diff test_expect_success "git diff f.Adiar" ' touch f.$Adiarnfc && git add f.$Adiarnfc && echo f.Adiarnfc >f.$Adiarnfc && git diff f.$Adiarnfd >expect && git diff f.$Adiarnfc >actual && test_cmp expect actual && git reset HEAD f.Adiarnfc && rm f.$Adiarnfc expect actual ' # This will test nfd2nfc in git diff-files test_expect_success "git diff-files f.Adiar" ' touch f.$Adiarnfc && git add f.$Adiarnfc && echo f.Adiarnfc >f.$Adiarnfc && git diff-files f.$Adiarnfd >expect && git diff-files f.$Adiarnfc >actual && test_cmp expect actual && git reset HEAD f.Adiarnfc && rm f.$Adiarnfc expect actual ' # This will test nfd2nfc in git diff-index test_expect_success "git diff-index f.Adiar" ' touch f.$Adiarnfc && git add f.$Adiarnfc && echo f.Adiarnfc >f.$Adiarnfc && git diff-index HEAD f.$Adiarnfd >expect && git diff-index HEAD f.$Adiarnfc >actual && test_cmp expect actual && git reset HEAD f.Adiarnfc && rm f.$Adiarnfc expect actual ' # This will test nfd2nfc in readdir() test_expect_success "add file Adiarnfc" ' echo f.Adiarnfc >f.$Adiarnfc && git add f.$Adiarnfc && git commit -m "add f.$Adiarnfc" ' # This will test nfd2nfc in git diff-tree test_expect_success "git diff-tree f.Adiar" ' echo f.Adiarnfc >>f.$Adiarnfc && git diff-tree HEAD f.$Adiarnfd >expect && git diff-tree HEAD f.$Adiarnfc >actual && test_cmp expect actual && git checkout f.$Adiarnfc && rm expect actual ' # This will test nfd2nfc in git stage() test_expect_success "stage file d.Adiarnfd/f.Adiarnfd" ' mkdir d.$Adiarnfd && echo d.$Adiarnfd/f.$Adiarnfd >d.$Adiarnfd/f.$Adiarnfd && git stage d.$Adiarnfd/f.$Adiarnfd && git commit -m "add d.$Adiarnfd/f.$Adiarnfd" ' test_expect_success "add link Adiarnfc" ' ln -s d.$Adiarnfd/f.$Adiarnfd l.$Adiarnfc && git add l.$Adiarnfc && git commit -m "add l.Adiarnfc" ' # This will test git log test_expect_success "git log f.Adiar" ' git log f.$Adiarnfc > f.Adiarnfc.log && git log f.$Adiarnfd > f.Adiarnfd.log && test -s f.Adiarnfc.log && test -s f.Adiarnfd.log && test_cmp f.Adiarnfc.log f.Adiarnfd.log && rm f.Adiarnfc.log f.Adiarnfd.log ' # This will test git ls-files test_expect_success "git lsfiles f.Adiar" ' git ls-files f.$Adiarnfc > f.Adiarnfc.log && git ls-files f.$Adiarnfd > f.Adiarnfd.log && test -s f.Adiarnfc.log && test -s f.Adiarnfd.log && test_cmp f.Adiarnfc.log f.Adiarnfd.log && rm f.Adiarnfc.log f.Adiarnfd.log ' # This will test git mv test_expect_success "git mv" ' git mv f.$Adiarnfd f.$Odiarnfc && git mv d.$Adiarnfd d.$Odiarnfc && git mv l.$Adiarnfd l.$Odiarnfc && git commit -m "mv Adiarnfd Odiarnfc" ' # Files can be checked out as nfc # And the link has been corrected from nfd to nfc test_expect_success "git checkout nfc" ' rm f.$Odiarnfc && git checkout f.$Odiarnfc ' # Make it possible to checkout files with their NFD names test_expect_success "git checkout file nfd" ' rm -f f.* && git checkout f.$Odiarnfd ' # Make it possible to checkout links with their NFD names test_expect_success "git checkout link nfd" ' rm l.* && git checkout l.$Odiarnfd ' test_expect_success "setup case mac2" ' git checkout master && git reset --hard && git checkout -b mac_os_2 ' # This will test nfd2nfc in git commit test_expect_success "commit file d2.Adiarnfd/f.Adiarnfd" ' mkdir d2.$Adiarnfd && echo d2.$Adiarnfd/f.$Adiarnfd >d2.$Adiarnfd/f.$Adiarnfd && git add d2.$Adiarnfd/f.$Adiarnfd && git commit -m "add d2.$Adiarnfd/f.$Adiarnfd" -- d2.$Adiarnfd/f.$Adiarnfd ' test_expect_success "setup for long decomposed filename" ' git checkout master && git reset --hard && git checkout -b mac_os_long_nfd_fn ' test_expect_success "Add long decomposed filename" ' echo longd >$Alongd && git add * && git commit -m "Long filename" ' test_expect_success "setup for long precomposed filename" ' git checkout master && git reset --hard && git checkout -b mac_os_long_nfc_fn ' test_expect_success "Add long precomposed filename" ' echo longc >$Alongc && git add * && git commit -m "Long filename" ' test_expect_failure 'handle existing decomposed filenames' ' echo content >"verbatim.$Adiarnfd" && git -c core.precomposeunicode=false add "verbatim.$Adiarnfd" && git commit -m "existing decomposed file" && >expect && git ls-files --exclude-standard -o "verbatim*" >untracked && test_cmp expect untracked ' # Test if the global core.precomposeunicode stops autosensing # Must be the last test case test_expect_success "respect git config --global core.precomposeunicode" ' git config --global core.precomposeunicode true && rm -rf .git && git init && precomposeunicode=$(git config core.precomposeunicode) && test "$precomposeunicode" = "true" ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"utf-8 decomposed (nfd) converted to precomposed (nfc)">)} spids: [13] ) ] spids: [13] ) (C {(.)} {(./test-lib.sh)}) (If arms: [ (if_arm cond: [(Pipeline children:[(C {(test_have_prereq)} {(UTF8_NFD_TO_NFC)})] negated:True)] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:skip_all) op: Equal rhs: {(DQ ("filesystem does not corrupt utf-8"))} spids: [35] ) ] spids: [35] ) (C {(test_done)}) ] spids: [-1 32] ) ] spids: [-1 43] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:Adiarnfc) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(printf)} {(SQ <"\\303\\204">)})]) left_token: spids: [50 56] ) } spids: [49] ) ] spids: [49] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:Adiarnfd) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(printf)} {(SQ <"A\\314\\210">)})]) left_token: spids: [59 65] ) } spids: [58] ) ] spids: [58] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:Odiarnfc) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(printf)} {(SQ <"\\303\\226">)})]) left_token: spids: [69 75] ) } spids: [68] ) ] spids: [68] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:Odiarnfd) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(printf)} {(SQ <"O\\314\\210">)})]) left_token: spids: [78 84] ) } spids: [77] ) ] spids: [77] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:AEligatu) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(printf)} {(SQ <"\\303\\206">)})]) left_token: spids: [87 93] ) } spids: [86] ) ] spids: [86] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:Invalidu) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(printf)} {(SQ <"\\303\\377">)})]) left_token: spids: [96 102] ) } spids: [95] ) ] spids: [95] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:Alongd) op: Equal rhs: {($ VSub_Name "$Adiarnfd") ($ VSub_Name "$Adiarnfd") ($ VSub_Name "$Adiarnfd") ($ VSub_Name "$Adiarnfd") ($ VSub_Name "$Adiarnfd") ($ VSub_Name "$Adiarnfd") ($ VSub_Name "$Adiarnfd") } spids: [109] ) ] spids: [109] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:Alongd) op: Equal rhs: {($ VSub_Name "$Alongd") ($ VSub_Name "$Alongd") ($ VSub_Name "$Alongd")} spids: [121] ) ] spids: [121] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:Alongd) op: Equal rhs: {($ VSub_Name "$Alongd") ($ VSub_Name "$Alongd") ($ VSub_Name "$Alongd") ($ VSub_Name "$Alongd") ($ VSub_Name "$Adiarnfd") } spids: [129] ) ] spids: [129] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:Alongc) op: Equal rhs: {($ VSub_Name "$AEligatu") ($ VSub_Name "$AEligatu") ($ VSub_Name "$AEligatu") ($ VSub_Name "$AEligatu") ($ VSub_Name "$AEligatu") } spids: [143] ) ] spids: [143] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:Alongc) op: Equal rhs: {($ VSub_Name "$Alongc") ($ VSub_Name "$Alongc") ($ VSub_Name "$Alongc") ($ VSub_Name "$Alongc") ($ VSub_Name "$Alongc") } spids: [153] ) ] spids: [153] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:Alongc) op: Equal rhs: {($ VSub_Name "$Alongc") ($ VSub_Name "$Alongc") ($ VSub_Name "$Alongc") ($ VSub_Name "$Alongc") ($ VSub_Name "$Alongc") } spids: [163] ) ] spids: [163] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:Alongc) op: Equal rhs: {($ VSub_Name "$Alongc") ($ VSub_Name "$AEligatu") ($ VSub_Name "$AEligatu")} spids: [173] ) ] spids: [173] ) (C {(test_expect_success)} {(DQ ("detect if nfd needed"))} { (SQ <"\n"> <"\tprecomposeunicode=$(git config core.precomposeunicode) &&\n"> <"\ttest \"$precomposeunicode\" = true &&\n"> <"\tgit config core.precomposeunicode true\n"> ) } ) (C {(test_expect_success)} {(DQ (setup))} { (SQ <"\n"> <"\t>x &&\n"> <"\tgit add x &&\n"> <"\tgit commit -m \"1st commit\" &&\n"> <"\tgit rm x &&\n"> <"\tgit commit -m \"rm x\"\n"> ) } ) (C {(test_expect_success)} {(DQ ("setup case mac"))} {(SQ <"\n"> <"\tgit checkout -b mac_os\n">)}) (C {(test_expect_success)} {(DQ ("git diff f.Adiar"))} { (SQ <"\n"> <"\ttouch f.$Adiarnfc &&\n"> <"\tgit add f.$Adiarnfc &&\n"> <"\techo f.Adiarnfc >f.$Adiarnfc &&\n"> <"\tgit diff f.$Adiarnfd >expect &&\n"> <"\tgit diff f.$Adiarnfc >actual &&\n"> <"\ttest_cmp expect actual &&\n"> <"\tgit reset HEAD f.Adiarnfc &&\n"> <"\trm f.$Adiarnfc expect actual\n"> ) } ) (C {(test_expect_success)} {(DQ ("git diff-files f.Adiar"))} { (SQ <"\n"> <"\ttouch f.$Adiarnfc &&\n"> <"\tgit add f.$Adiarnfc &&\n"> <"\techo f.Adiarnfc >f.$Adiarnfc &&\n"> <"\tgit diff-files f.$Adiarnfd >expect &&\n"> <"\tgit diff-files f.$Adiarnfc >actual &&\n"> <"\ttest_cmp expect actual &&\n"> <"\tgit reset HEAD f.Adiarnfc &&\n"> <"\trm f.$Adiarnfc expect actual\n"> ) } ) (C {(test_expect_success)} {(DQ ("git diff-index f.Adiar"))} { (SQ <"\n"> <"\ttouch f.$Adiarnfc &&\n"> <"\tgit add f.$Adiarnfc &&\n"> <"\techo f.Adiarnfc >f.$Adiarnfc &&\n"> <"\tgit diff-index HEAD f.$Adiarnfd >expect &&\n"> <"\tgit diff-index HEAD f.$Adiarnfc >actual &&\n"> <"\ttest_cmp expect actual &&\n"> <"\tgit reset HEAD f.Adiarnfc &&\n"> <"\trm f.$Adiarnfc expect actual\n"> ) } ) (C {(test_expect_success)} {(DQ ("add file Adiarnfc"))} { (SQ <"\n"> <"\techo f.Adiarnfc >f.$Adiarnfc &&\n"> <"\tgit add f.$Adiarnfc &&\n"> <"\tgit commit -m \"add f.$Adiarnfc\"\n"> ) } ) (C {(test_expect_success)} {(DQ ("git diff-tree f.Adiar"))} { (SQ <"\n"> <"\techo f.Adiarnfc >>f.$Adiarnfc &&\n"> <"\tgit diff-tree HEAD f.$Adiarnfd >expect &&\n"> <"\tgit diff-tree HEAD f.$Adiarnfc >actual &&\n"> <"\ttest_cmp expect actual &&\n"> <"\tgit checkout f.$Adiarnfc &&\n"> <"\trm expect actual\n"> ) } ) (C {(test_expect_success)} {(DQ ("stage file d.Adiarnfd/f.Adiarnfd"))} { (SQ <"\n"> <"\tmkdir d.$Adiarnfd &&\n"> <"\techo d.$Adiarnfd/f.$Adiarnfd >d.$Adiarnfd/f.$Adiarnfd &&\n"> <"\tgit stage d.$Adiarnfd/f.$Adiarnfd &&\n"> <"\tgit commit -m \"add d.$Adiarnfd/f.$Adiarnfd\"\n"> ) } ) (C {(test_expect_success)} {(DQ ("add link Adiarnfc"))} { (SQ <"\n"> <"\tln -s d.$Adiarnfd/f.$Adiarnfd l.$Adiarnfc &&\n"> <"\tgit add l.$Adiarnfc &&\n"> <"\tgit commit -m \"add l.Adiarnfc\"\n"> ) } ) (C {(test_expect_success)} {(DQ ("git log f.Adiar"))} { (SQ <"\n"> <"\tgit log f.$Adiarnfc > f.Adiarnfc.log &&\n"> <"\tgit log f.$Adiarnfd > f.Adiarnfd.log &&\n"> <"\ttest -s f.Adiarnfc.log &&\n"> <"\ttest -s f.Adiarnfd.log &&\n"> <"\ttest_cmp f.Adiarnfc.log f.Adiarnfd.log &&\n"> <"\trm f.Adiarnfc.log f.Adiarnfd.log\n"> ) } ) (C {(test_expect_success)} {(DQ ("git lsfiles f.Adiar"))} { (SQ <"\n"> <"\tgit ls-files f.$Adiarnfc > f.Adiarnfc.log &&\n"> <"\tgit ls-files f.$Adiarnfd > f.Adiarnfd.log &&\n"> <"\ttest -s f.Adiarnfc.log &&\n"> <"\ttest -s f.Adiarnfd.log &&\n"> <"\ttest_cmp f.Adiarnfc.log f.Adiarnfd.log &&\n"> <"\trm f.Adiarnfc.log f.Adiarnfd.log\n"> ) } ) (C {(test_expect_success)} {(DQ ("git mv"))} { (SQ <"\n"> <"\tgit mv f.$Adiarnfd f.$Odiarnfc &&\n"> <"\tgit mv d.$Adiarnfd d.$Odiarnfc &&\n"> <"\tgit mv l.$Adiarnfd l.$Odiarnfc &&\n"> <"\tgit commit -m \"mv Adiarnfd Odiarnfc\"\n"> ) } ) (C {(test_expect_success)} {(DQ ("git checkout nfc"))} {(SQ <"\n"> <"\trm f.$Odiarnfc &&\n"> <"\tgit checkout f.$Odiarnfc\n">)} ) (C {(test_expect_success)} {(DQ ("git checkout file nfd"))} {(SQ <"\n"> <"\trm -f f.* &&\n"> <"\tgit checkout f.$Odiarnfd\n">)} ) (C {(test_expect_success)} {(DQ ("git checkout link nfd"))} {(SQ <"\n"> <"\trm l.* &&\n"> <"\tgit checkout l.$Odiarnfd\n">)} ) (C {(test_expect_success)} {(DQ ("setup case mac2"))} { (SQ <"\n"> <"\tgit checkout master &&\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout -b mac_os_2\n"> ) } ) (C {(test_expect_success)} {(DQ ("commit file d2.Adiarnfd/f.Adiarnfd"))} { (SQ <"\n"> <"\tmkdir d2.$Adiarnfd &&\n"> <"\techo d2.$Adiarnfd/f.$Adiarnfd >d2.$Adiarnfd/f.$Adiarnfd &&\n"> <"\tgit add d2.$Adiarnfd/f.$Adiarnfd &&\n"> <"\tgit commit -m \"add d2.$Adiarnfd/f.$Adiarnfd\" -- d2.$Adiarnfd/f.$Adiarnfd\n"> ) } ) (C {(test_expect_success)} {(DQ ("setup for long decomposed filename"))} { (SQ <"\n"> <"\tgit checkout master &&\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout -b mac_os_long_nfd_fn\n"> ) } ) (C {(test_expect_success)} {(DQ ("Add long decomposed filename"))} { (SQ <"\n"> <"\techo longd >$Alongd &&\n"> <"\tgit add * &&\n"> <"\tgit commit -m \"Long filename\"\n"> ) } ) (C {(test_expect_success)} {(DQ ("setup for long precomposed filename"))} { (SQ <"\n"> <"\tgit checkout master &&\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout -b mac_os_long_nfc_fn\n"> ) } ) (C {(test_expect_success)} {(DQ ("Add long precomposed filename"))} { (SQ <"\n"> <"\techo longc >$Alongc &&\n"> <"\tgit add * &&\n"> <"\tgit commit -m \"Long filename\"\n"> ) } ) (C {(test_expect_failure)} {(SQ <"handle existing decomposed filenames">)} { (SQ <"\n"> <"\techo content >\"verbatim.$Adiarnfd\" &&\n"> <"\tgit -c core.precomposeunicode=false add \"verbatim.$Adiarnfd\" &&\n"> <"\tgit commit -m \"existing decomposed file\" &&\n"> <"\t>expect &&\n"> <"\tgit ls-files --exclude-standard -o \"verbatim*\" >untracked &&\n"> <"\ttest_cmp expect untracked\n"> ) } ) (C {(test_expect_success)} {(DQ ("respect git config --global core.precomposeunicode"))} { (SQ <"\n"> <"\tgit config --global core.precomposeunicode true &&\n"> <"\trm -rf .git &&\n"> <"\tgit init &&\n"> <"\tprecomposeunicode=$(git config core.precomposeunicode) &&\n"> <"\ttest \"$precomposeunicode\" = \"true\"\n"> ) } ) (C {(test_done)}) ] )