a49f8a9813b81a1db41f22a2843e03abbc2aa61c
   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 check-attr test -- "$path" >actual &&
  13        echo "$path: test: $2" >expect &&
  14        test_cmp expect actual
  15
  16}
  17
  18
  19test_expect_success 'setup' '
  20
  21        mkdir -p a/b/d a/c &&
  22        (
  23                echo "[attr]notest !test"
  24                echo "f test=f"
  25                echo "a/i test=a/i"
  26                echo "onoff test -test"
  27                echo "offon -test test"
  28                echo "no notest"
  29        ) >.gitattributes &&
  30        (
  31                echo "g test=a/g" &&
  32                echo "b/g test=a/b/g"
  33        ) >a/.gitattributes &&
  34        (
  35                echo "h test=a/b/h" &&
  36                echo "d/* test=a/b/d/*"
  37                echo "d/yes notest"
  38        ) >a/b/.gitattributes &&
  39        (
  40                echo "global test=global"
  41        ) >"$HOME"/global-gitattributes &&
  42        cat <<EOF >expect-all
  43f: test: f
  44a/f: test: f
  45a/c/f: test: f
  46a/g: test: a/g
  47a/b/g: test: a/b/g
  48b/g: test: unspecified
  49a/b/h: test: a/b/h
  50a/b/d/g: test: a/b/d/*
  51onoff: test: unset
  52offon: test: set
  53no: notest: set
  54no: test: unspecified
  55a/b/d/no: notest: set
  56a/b/d/no: test: a/b/d/*
  57a/b/d/yes: notest: set
  58a/b/d/yes: test: unspecified
  59EOF
  60
  61'
  62
  63test_expect_success 'command line checks' '
  64
  65        test_must_fail git check-attr &&
  66        test_must_fail git check-attr -- &&
  67        test_must_fail git check-attr test &&
  68        test_must_fail git check-attr test -- &&
  69        test_must_fail git check-attr -- f &&
  70        echo "f" | test_must_fail git check-attr --stdin &&
  71        echo "f" | test_must_fail git check-attr --stdin -- f &&
  72        echo "f" | test_must_fail git check-attr --stdin test -- f &&
  73        echo "f" | test_must_fail git check-attr --stdin test f &&
  74        test_must_fail git check-attr "" -- f
  75
  76'
  77
  78test_expect_success 'attribute test' '
  79
  80        attr_check f f &&
  81        attr_check a/f f &&
  82        attr_check a/c/f f &&
  83        attr_check a/g a/g &&
  84        attr_check a/b/g a/b/g &&
  85        attr_check b/g unspecified &&
  86        attr_check a/b/h a/b/h &&
  87        attr_check a/b/d/g "a/b/d/*" &&
  88        attr_check onoff unset &&
  89        attr_check offon set &&
  90        attr_check no unspecified &&
  91        attr_check a/b/d/no "a/b/d/*" &&
  92        attr_check a/b/d/yes unspecified
  93
  94'
  95
  96test_expect_success 'core.attributesfile' '
  97        attr_check global unspecified &&
  98        git config core.attributesfile "$HOME/global-gitattributes" &&
  99        attr_check global global &&
 100        git config core.attributesfile "~/global-gitattributes" &&
 101        attr_check global global &&
 102        echo "global test=precedence" >> .gitattributes &&
 103        attr_check global precedence
 104'
 105
 106test_expect_success 'attribute test: read paths from stdin' '
 107
 108        grep -v notest < expect-all > expect &&
 109        sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
 110        test_cmp expect actual
 111'
 112
 113test_expect_success 'attribute test: --all option' '
 114
 115        grep -v unspecified < expect-all | sort > expect &&
 116        sed -e "s/:.*//" < expect-all | uniq |
 117                git check-attr --stdin --all | sort > actual &&
 118        test_cmp expect actual
 119'
 120
 121test_expect_success 'root subdir attribute test' '
 122
 123        attr_check a/i a/i &&
 124        attr_check subdir/a/i unspecified
 125
 126'
 127
 128test_expect_success 'setup bare' '
 129
 130        git clone --bare . bare.git &&
 131        cd bare.git
 132
 133'
 134
 135test_expect_success 'bare repository: check that .gitattribute is ignored' '
 136
 137        (
 138                echo "f test=f"
 139                echo "a/i test=a/i"
 140        ) >.gitattributes &&
 141        attr_check f unspecified &&
 142        attr_check a/f unspecified &&
 143        attr_check a/c/f unspecified &&
 144        attr_check a/i unspecified &&
 145        attr_check subdir/a/i unspecified
 146
 147'
 148
 149test_expect_success 'bare repository: test info/attributes' '
 150
 151        (
 152                echo "f test=f"
 153                echo "a/i test=a/i"
 154        ) >info/attributes &&
 155        attr_check f f &&
 156        attr_check a/f f &&
 157        attr_check a/c/f f &&
 158        attr_check a/i a/i &&
 159        attr_check subdir/a/i unspecified
 160
 161'
 162
 163test_done