t / t0003-attributes.shon commit gitweb: Handle invalid regexp in regexp search (36612e4)
   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
  43'
  44
  45test_expect_success 'attribute test' '
  46
  47        attr_check f f &&
  48        attr_check a/f f &&
  49        attr_check a/c/f f &&
  50        attr_check a/g a/g &&
  51        attr_check a/b/g a/b/g &&
  52        attr_check b/g unspecified &&
  53        attr_check a/b/h a/b/h &&
  54        attr_check a/b/d/g "a/b/d/*" &&
  55        attr_check onoff unset &&
  56        attr_check offon set &&
  57        attr_check no unspecified &&
  58        attr_check a/b/d/no "a/b/d/*" &&
  59        attr_check a/b/d/yes unspecified
  60
  61'
  62
  63test_expect_success 'prefixes are not confused with leading directories' '
  64        attr_check a_plus/g unspecified &&
  65        cat >expect <<-\EOF &&
  66        a/g: test: a/g
  67        a_plus/g: test: unspecified
  68        EOF
  69        git check-attr test a/g a_plus/g >actual &&
  70        test_cmp expect actual
  71'
  72
  73test_expect_success 'core.attributesfile' '
  74        attr_check global unspecified &&
  75        git config core.attributesfile "$HOME/global-gitattributes" &&
  76        attr_check global global &&
  77        git config core.attributesfile "~/global-gitattributes" &&
  78        attr_check global global &&
  79        echo "global test=precedence" >> .gitattributes &&
  80        attr_check global precedence
  81'
  82
  83test_expect_success 'attribute test: read paths from stdin' '
  84
  85        cat <<EOF > expect &&
  86f: test: f
  87a/f: test: f
  88a/c/f: test: f
  89a/g: test: a/g
  90a/b/g: test: a/b/g
  91b/g: test: unspecified
  92a/b/h: test: a/b/h
  93a/b/d/g: test: a/b/d/*
  94onoff: test: unset
  95offon: test: set
  96no: test: unspecified
  97a/b/d/no: test: a/b/d/*
  98a/b/d/yes: test: unspecified
  99EOF
 100
 101        sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
 102        test_cmp expect actual
 103'
 104
 105test_expect_success 'root subdir attribute test' '
 106
 107        attr_check a/i a/i &&
 108        attr_check subdir/a/i unspecified
 109
 110'
 111
 112test_expect_success 'setup bare' '
 113
 114        git clone --bare . bare.git &&
 115        cd bare.git
 116
 117'
 118
 119test_expect_success 'bare repository: check that .gitattribute is ignored' '
 120
 121        (
 122                echo "f test=f"
 123                echo "a/i test=a/i"
 124        ) >.gitattributes &&
 125        attr_check f unspecified &&
 126        attr_check a/f unspecified &&
 127        attr_check a/c/f unspecified &&
 128        attr_check a/i unspecified &&
 129        attr_check subdir/a/i unspecified
 130
 131'
 132
 133test_expect_success 'bare repository: test info/attributes' '
 134
 135        (
 136                echo "f test=f"
 137                echo "a/i test=a/i"
 138        ) >info/attributes &&
 139        attr_check f f &&
 140        attr_check a/f f &&
 141        attr_check a/c/f f &&
 142        attr_check a/i a/i &&
 143        attr_check subdir/a/i unspecified
 144
 145'
 146
 147test_done