t / t3910-mac-os-precompose.shon commit Merge branch 'jc/am-i-v-fix' into maint (28eec80)
   1#!/bin/sh
   2#
   3# Copyright (c) 2012 Torsten Bögershausen
   4#
   5
   6test_description='utf-8 decomposed (nfd) converted to precomposed (nfc)'
   7
   8. ./test-lib.sh
   9
  10if ! test_have_prereq UTF8_NFD_TO_NFC
  11then
  12        skip_all="filesystem does not corrupt utf-8"
  13        test_done
  14fi
  15
  16# create utf-8 variables
  17Adiarnfc=$(printf '\303\204')
  18Adiarnfd=$(printf 'A\314\210')
  19
  20Odiarnfc=$(printf '\303\226')
  21Odiarnfd=$(printf 'O\314\210')
  22AEligatu=$(printf '\303\206')
  23Invalidu=$(printf '\303\377')
  24
  25
  26#Create a string with 255 bytes (decomposed)
  27Alongd=$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd #21 Byte
  28Alongd=$Alongd$Alongd$Alongd                                           #63 Byte
  29Alongd=$Alongd$Alongd$Alongd$Alongd$Adiarnfd                           #255 Byte
  30
  31#Create a string with 254 bytes (precomposed)
  32Alongc=$AEligatu$AEligatu$AEligatu$AEligatu$AEligatu #10 Byte
  33Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc           #50 Byte
  34Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc           #250 Byte
  35Alongc=$Alongc$AEligatu$AEligatu                     #254 Byte
  36
  37test_expect_success "detect if nfd needed" '
  38        precomposeunicode=$(git config core.precomposeunicode) &&
  39        test "$precomposeunicode" = true &&
  40        git config core.precomposeunicode true
  41'
  42test_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'
  49test_expect_success "setup case mac" '
  50        git checkout -b mac_os
  51'
  52# This will test nfd2nfc in readdir()
  53test_expect_success "add file Adiarnfc" '
  54        echo f.Adiarnfc >f.$Adiarnfc &&
  55        git add f.$Adiarnfc &&
  56        git commit -m "add f.$Adiarnfc"
  57'
  58# This will test nfd2nfc in git stage()
  59test_expect_success "stage file d.Adiarnfd/f.Adiarnfd" '
  60        mkdir d.$Adiarnfd &&
  61        echo d.$Adiarnfd/f.$Adiarnfd >d.$Adiarnfd/f.$Adiarnfd &&
  62        git stage d.$Adiarnfd/f.$Adiarnfd &&
  63        git commit -m "add d.$Adiarnfd/f.$Adiarnfd"
  64'
  65test_expect_success "add link Adiarnfc" '
  66        ln -s d.$Adiarnfd/f.$Adiarnfd l.$Adiarnfc &&
  67        git add l.$Adiarnfc &&
  68        git commit -m "add l.Adiarnfc"
  69'
  70# This will test git log
  71test_expect_success "git log f.Adiar" '
  72        git log f.$Adiarnfc > f.Adiarnfc.log &&
  73        git log f.$Adiarnfd > f.Adiarnfd.log &&
  74        test -s f.Adiarnfc.log &&
  75        test -s f.Adiarnfd.log &&
  76        test_cmp f.Adiarnfc.log f.Adiarnfd.log &&
  77        rm f.Adiarnfc.log f.Adiarnfd.log
  78'
  79# This will test git ls-files
  80test_expect_success "git lsfiles f.Adiar" '
  81        git ls-files f.$Adiarnfc > f.Adiarnfc.log &&
  82        git ls-files f.$Adiarnfd > f.Adiarnfd.log &&
  83        test -s f.Adiarnfc.log &&
  84        test -s f.Adiarnfd.log &&
  85        test_cmp f.Adiarnfc.log f.Adiarnfd.log &&
  86        rm f.Adiarnfc.log f.Adiarnfd.log
  87'
  88# This will test git mv
  89test_expect_success "git mv" '
  90        git mv f.$Adiarnfd f.$Odiarnfc &&
  91        git mv d.$Adiarnfd d.$Odiarnfc &&
  92        git mv l.$Adiarnfd l.$Odiarnfc &&
  93        git commit -m "mv Adiarnfd Odiarnfc"
  94'
  95# Files can be checked out as nfc
  96# And the link has been corrected from nfd to nfc
  97test_expect_success "git checkout nfc" '
  98        rm f.$Odiarnfc &&
  99        git checkout f.$Odiarnfc
 100'
 101# Make it possible to checkout files with their NFD names
 102test_expect_success "git checkout file nfd" '
 103        rm -f f.* &&
 104        git checkout f.$Odiarnfd
 105'
 106# Make it possible to checkout links with their NFD names
 107test_expect_success "git checkout link nfd" '
 108        rm l.* &&
 109        git checkout l.$Odiarnfd
 110'
 111test_expect_success "setup case mac2" '
 112        git checkout master &&
 113        git reset --hard &&
 114        git checkout -b mac_os_2
 115'
 116# This will test nfd2nfc in git commit
 117test_expect_success "commit file d2.Adiarnfd/f.Adiarnfd" '
 118        mkdir d2.$Adiarnfd &&
 119        echo d2.$Adiarnfd/f.$Adiarnfd >d2.$Adiarnfd/f.$Adiarnfd &&
 120        git add d2.$Adiarnfd/f.$Adiarnfd &&
 121        git commit -m "add d2.$Adiarnfd/f.$Adiarnfd" -- d2.$Adiarnfd/f.$Adiarnfd
 122'
 123test_expect_success "setup for long decomposed filename" '
 124        git checkout master &&
 125        git reset --hard &&
 126        git checkout -b mac_os_long_nfd_fn
 127'
 128test_expect_success "Add long decomposed filename" '
 129        echo longd >$Alongd &&
 130        git add * &&
 131        git commit -m "Long filename"
 132'
 133test_expect_success "setup for long precomposed filename" '
 134        git checkout master &&
 135        git reset --hard &&
 136        git checkout -b mac_os_long_nfc_fn
 137'
 138test_expect_success "Add long precomposed filename" '
 139        echo longc >$Alongc &&
 140        git add * &&
 141        git commit -m "Long filename"
 142'
 143
 144test_expect_failure 'handle existing decomposed filenames' '
 145        echo content >"verbatim.$Adiarnfd" &&
 146        git -c core.precomposeunicode=false add "verbatim.$Adiarnfd" &&
 147        git commit -m "existing decomposed file" &&
 148        >expect &&
 149        git ls-files --exclude-standard -o "verbatim*" >untracked &&
 150        test_cmp expect untracked
 151'
 152
 153# Test if the global core.precomposeunicode stops autosensing
 154# Must be the last test case
 155test_expect_success "respect git config --global core.precomposeunicode" '
 156        git config --global core.precomposeunicode true &&
 157        rm -rf .git &&
 158        git init &&
 159        precomposeunicode=$(git config core.precomposeunicode) &&
 160        test "$precomposeunicode" = "true"
 161'
 162
 163test_done