t / t0003-attributes.shon commit Sync with 1.7.6.6 (110c511)
   1#!/bin/sh
   2
   3test_description=gitattributes
   4
   5. ./test-lib.sh
   6
   7attr_check () {
   8
   9        path="$1"
  10        expect="$2"
  11
  12        git $3 check-attr test -- "$path" >actual 2>err &&
  13        echo "$path: test: $2" >expect &&
  14        test_cmp expect actual &&
  15        test_line_count = 0 err
  16
  17}
  18
  19
  20test_expect_success 'setup' '
  21
  22        mkdir -p a/b/d a/c b &&
  23        (
  24                echo "[attr]notest !test"
  25                echo "f test=f"
  26                echo "a/i test=a/i"
  27                echo "onoff test -test"
  28                echo "offon -test test"
  29                echo "no notest"
  30                echo "A/e/F test=A/e/F"
  31        ) >.gitattributes &&
  32        (
  33                echo "g test=a/g" &&
  34                echo "b/g test=a/b/g"
  35        ) >a/.gitattributes &&
  36        (
  37                echo "h test=a/b/h" &&
  38                echo "d/* test=a/b/d/*"
  39                echo "d/yes notest"
  40        ) >a/b/.gitattributes &&
  41        (
  42                echo "global test=global"
  43        ) >"$HOME"/global-gitattributes &&
  44        cat <<EOF >expect-all
  45f: test: f
  46a/f: test: f
  47a/c/f: test: f
  48a/g: test: a/g
  49a/b/g: test: a/b/g
  50b/g: test: unspecified
  51a/b/h: test: a/b/h
  52a/b/d/g: test: a/b/d/*
  53onoff: test: unset
  54offon: test: set
  55no: notest: set
  56no: test: unspecified
  57a/b/d/no: notest: set
  58a/b/d/no: test: a/b/d/*
  59a/b/d/yes: notest: set
  60a/b/d/yes: test: unspecified
  61EOF
  62
  63'
  64
  65test_expect_success 'command line checks' '
  66
  67        test_must_fail git check-attr &&
  68        test_must_fail git check-attr -- &&
  69        test_must_fail git check-attr test &&
  70        test_must_fail git check-attr test -- &&
  71        test_must_fail git check-attr -- f &&
  72        echo "f" | test_must_fail git check-attr --stdin &&
  73        echo "f" | test_must_fail git check-attr --stdin -- f &&
  74        echo "f" | test_must_fail git check-attr --stdin test -- f &&
  75        test_must_fail git check-attr "" -- f
  76
  77'
  78
  79test_expect_success 'attribute test' '
  80
  81        attr_check f f &&
  82        attr_check a/f f &&
  83        attr_check a/c/f f &&
  84        attr_check a/g a/g &&
  85        attr_check a/b/g a/b/g &&
  86        attr_check b/g unspecified &&
  87        attr_check a/b/h a/b/h &&
  88        attr_check a/b/d/g "a/b/d/*" &&
  89        attr_check onoff unset &&
  90        attr_check offon set &&
  91        attr_check no unspecified &&
  92        attr_check a/b/d/no "a/b/d/*" &&
  93        attr_check a/b/d/yes unspecified
  94
  95'
  96
  97test_expect_success 'attribute matching is case sensitive when core.ignorecase=0' '
  98
  99        test_must_fail attr_check F f "-c core.ignorecase=0" &&
 100        test_must_fail attr_check a/F f "-c core.ignorecase=0" &&
 101        test_must_fail attr_check a/c/F f "-c core.ignorecase=0" &&
 102        test_must_fail attr_check a/G a/g "-c core.ignorecase=0" &&
 103        test_must_fail attr_check a/B/g a/b/g "-c core.ignorecase=0" &&
 104        test_must_fail attr_check a/b/G a/b/g "-c core.ignorecase=0" &&
 105        test_must_fail attr_check a/b/H a/b/h "-c core.ignorecase=0" &&
 106        test_must_fail attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=0" &&
 107        test_must_fail attr_check oNoFf unset "-c core.ignorecase=0" &&
 108        test_must_fail attr_check oFfOn set "-c core.ignorecase=0" &&
 109        attr_check NO unspecified "-c core.ignorecase=0" &&
 110        test_must_fail attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=0" &&
 111        attr_check a/b/d/YES a/b/d/* "-c core.ignorecase=0" &&
 112        test_must_fail attr_check a/E/f "A/e/F" "-c core.ignorecase=0"
 113
 114'
 115
 116test_expect_success 'attribute matching is case insensitive when core.ignorecase=1' '
 117
 118        attr_check F f "-c core.ignorecase=1" &&
 119        attr_check a/F f "-c core.ignorecase=1" &&
 120        attr_check a/c/F f "-c core.ignorecase=1" &&
 121        attr_check a/G a/g "-c core.ignorecase=1" &&
 122        attr_check a/B/g a/b/g "-c core.ignorecase=1" &&
 123        attr_check a/b/G a/b/g "-c core.ignorecase=1" &&
 124        attr_check a/b/H a/b/h "-c core.ignorecase=1" &&
 125        attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=1" &&
 126        attr_check oNoFf unset "-c core.ignorecase=1" &&
 127        attr_check oFfOn set "-c core.ignorecase=1" &&
 128        attr_check NO unspecified "-c core.ignorecase=1" &&
 129        attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=1" &&
 130        attr_check a/b/d/YES unspecified "-c core.ignorecase=1" &&
 131        attr_check a/E/f "A/e/F" "-c core.ignorecase=1"
 132
 133'
 134
 135test_expect_success 'check whether FS is case-insensitive' '
 136        mkdir junk &&
 137        echo good >junk/CamelCase &&
 138        echo bad >junk/camelcase &&
 139        if test "$(cat junk/CamelCase)" != good
 140        then
 141                test_set_prereq CASE_INSENSITIVE_FS
 142        fi
 143'
 144
 145test_expect_success CASE_INSENSITIVE_FS 'additional case insensitivity tests' '
 146        test_must_fail attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=0" &&
 147        test_must_fail attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=0" &&
 148        attr_check A/b/h a/b/h "-c core.ignorecase=1" &&
 149        attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=1" &&
 150        attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=1"
 151'
 152
 153test_expect_success 'unnormalized paths' '
 154
 155        attr_check ./f f &&
 156        attr_check ./a/g a/g &&
 157        attr_check a/./g a/g &&
 158        attr_check a/c/../b/g a/b/g
 159
 160'
 161
 162test_expect_success 'relative paths' '
 163
 164        (cd a && attr_check ../f f) &&
 165        (cd a && attr_check f f) &&
 166        (cd a && attr_check i a/i) &&
 167        (cd a && attr_check g a/g) &&
 168        (cd a && attr_check b/g a/b/g) &&
 169        (cd b && attr_check ../a/f f) &&
 170        (cd b && attr_check ../a/g a/g) &&
 171        (cd b && attr_check ../a/b/g a/b/g)
 172
 173'
 174
 175test_expect_success 'prefixes are not confused with leading directories' '
 176        attr_check a_plus/g unspecified &&
 177        cat >expect <<-\EOF &&
 178        a/g: test: a/g
 179        a_plus/g: test: unspecified
 180        EOF
 181        git check-attr test a/g a_plus/g >actual &&
 182        test_cmp expect actual
 183'
 184
 185test_expect_success 'core.attributesfile' '
 186        attr_check global unspecified &&
 187        git config core.attributesfile "$HOME/global-gitattributes" &&
 188        attr_check global global &&
 189        git config core.attributesfile "~/global-gitattributes" &&
 190        attr_check global global &&
 191        echo "global test=precedence" >> .gitattributes &&
 192        attr_check global precedence
 193'
 194
 195test_expect_success 'attribute test: read paths from stdin' '
 196
 197        grep -v notest < expect-all > expect &&
 198        sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
 199        test_cmp expect actual
 200'
 201
 202test_expect_success 'attribute test: --all option' '
 203
 204        grep -v unspecified < expect-all | sort > expect &&
 205        sed -e "s/:.*//" < expect-all | uniq |
 206                git check-attr --stdin --all | sort > actual &&
 207        test_cmp expect actual
 208'
 209
 210test_expect_success 'root subdir attribute test' '
 211
 212        attr_check a/i a/i &&
 213        attr_check subdir/a/i unspecified
 214
 215'
 216
 217test_expect_success 'setup bare' '
 218
 219        git clone --bare . bare.git &&
 220        cd bare.git
 221
 222'
 223
 224test_expect_success 'bare repository: check that .gitattribute is ignored' '
 225
 226        (
 227                echo "f test=f"
 228                echo "a/i test=a/i"
 229        ) >.gitattributes &&
 230        attr_check f unspecified &&
 231        attr_check a/f unspecified &&
 232        attr_check a/c/f unspecified &&
 233        attr_check a/i unspecified &&
 234        attr_check subdir/a/i unspecified
 235
 236'
 237
 238test_expect_success 'bare repository: test info/attributes' '
 239
 240        (
 241                echo "f test=f"
 242                echo "a/i test=a/i"
 243        ) >info/attributes &&
 244        attr_check f f &&
 245        attr_check a/f f &&
 246        attr_check a/c/f f &&
 247        attr_check a/i a/i &&
 248        attr_check subdir/a/i unspecified
 249
 250'
 251
 252test_done