t / t3910-mac-os-precompose.shon commit Merge branch 'rs/checkout-init-macro' (e683f17)
   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 git diff
  53test_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
  64test_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
  75test_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'
  85# This will test nfd2nfc in readdir()
  86test_expect_success "add file Adiarnfc" '
  87        echo f.Adiarnfc >f.$Adiarnfc &&
  88        git add f.$Adiarnfc &&
  89        git commit -m "add f.$Adiarnfc"
  90'
  91# This will test nfd2nfc in git diff-tree
  92test_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'
 100# This will test nfd2nfc in git stage()
 101test_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'
 107test_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
 113test_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
 122test_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
 131test_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
 139test_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
 144test_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
 149test_expect_success "git checkout link nfd" '
 150        rm l.* &&
 151        git checkout l.$Odiarnfd
 152'
 153test_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
 159test_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'
 165test_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'
 170test_expect_success "Add long decomposed filename" '
 171        echo longd >$Alongd &&
 172        git add * &&
 173        git commit -m "Long filename"
 174'
 175test_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'
 180test_expect_success "Add long precomposed filename" '
 181        echo longc >$Alongc &&
 182        git add * &&
 183        git commit -m "Long filename"
 184'
 185
 186test_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
 195# Test if the global core.precomposeunicode stops autosensing
 196# Must be the last test case
 197test_expect_success "respect git config --global core.precomposeunicode" '
 198        git config --global core.precomposeunicode true &&
 199        rm -rf .git &&
 200        git init &&
 201        precomposeunicode=$(git config core.precomposeunicode) &&
 202        test "$precomposeunicode" = "true"
 203'
 204
 205test_done