t / t0003-attributes.shon commit Merge branch 'tr/word-diff' (1bdd46c)
   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'
  41
  42test_expect_success 'attribute test' '
  43
  44        attr_check f f &&
  45        attr_check a/f f &&
  46        attr_check a/c/f f &&
  47        attr_check a/g a/g &&
  48        attr_check a/b/g a/b/g &&
  49        attr_check b/g unspecified &&
  50        attr_check a/b/h a/b/h &&
  51        attr_check a/b/d/g "a/b/d/*"
  52        attr_check onoff unset
  53        attr_check offon set
  54        attr_check no unspecified
  55        attr_check a/b/d/no "a/b/d/*"
  56        attr_check a/b/d/yes unspecified
  57
  58'
  59
  60test_expect_success 'attribute test: read paths from stdin' '
  61
  62        cat <<EOF > expect
  63f: test: f
  64a/f: test: f
  65a/c/f: test: f
  66a/g: test: a/g
  67a/b/g: test: a/b/g
  68b/g: test: unspecified
  69a/b/h: test: a/b/h
  70a/b/d/g: test: a/b/d/*
  71onoff: test: unset
  72offon: test: set
  73no: test: unspecified
  74a/b/d/no: test: a/b/d/*
  75a/b/d/yes: test: unspecified
  76EOF
  77
  78        sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
  79        test_cmp expect actual
  80'
  81
  82test_expect_success 'root subdir attribute test' '
  83
  84        attr_check a/i a/i &&
  85        attr_check subdir/a/i unspecified
  86
  87'
  88
  89test_expect_success 'setup bare' '
  90
  91        git clone --bare . bare.git &&
  92        cd bare.git
  93
  94'
  95
  96test_expect_success 'bare repository: check that .gitattribute is ignored' '
  97
  98        (
  99                echo "f test=f"
 100                echo "a/i test=a/i"
 101        ) >.gitattributes &&
 102        attr_check f unspecified &&
 103        attr_check a/f unspecified &&
 104        attr_check a/c/f unspecified &&
 105        attr_check a/i unspecified &&
 106        attr_check subdir/a/i unspecified
 107
 108'
 109
 110test_expect_success 'bare repository: test info/attributes' '
 111
 112        (
 113                echo "f test=f"
 114                echo "a/i test=a/i"
 115        ) >info/attributes &&
 116        attr_check f f &&
 117        attr_check a/f f &&
 118        attr_check a/c/f f &&
 119        attr_check a/i a/i &&
 120        attr_check subdir/a/i unspecified
 121
 122'
 123
 124test_done