1#!/bin/sh
   2test_description=gitattributes
   4. ./test-lib.sh
   6attr_check () {
   8        path="$1"
  10        expect="$2"
  11        git check-attr test -- "$path" >actual &&
  13        echo "$path: test: $2" >expect &&
  14        test_cmp expect actual
  15}
  17test_expect_success 'setup' '
  20        mkdir -p a/b/d a/c &&
  22        (
  23                echo "f test=f"
  24                echo "a/i test=a/i"
  25        ) >.gitattributes &&
  26        (
  27                echo "g test=a/g" &&
  28                echo "b/g test=a/b/g"
  29        ) >a/.gitattributes &&
  30        (
  31                echo "h test=a/b/h" &&
  32                echo "d/* test=a/b/d/*"
  33        ) >a/b/.gitattributes
  34'
  36test_expect_success 'attribute test' '
  38        attr_check f f &&
  40        attr_check a/f f &&
  41        attr_check a/c/f f &&
  42        attr_check a/g a/g &&
  43        attr_check a/b/g a/b/g &&
  44        attr_check b/g unspecified &&
  45        attr_check a/b/h a/b/h &&
  46        attr_check a/b/d/g "a/b/d/*"
  47'
  49test_expect_success 'root subdir attribute test' '
  51        attr_check a/i a/i &&
  53        attr_check subdir/a/i unspecified
  54'
  56test_expect_success 'setup bare' '
  58        git clone --bare . bare.git &&
  60        cd bare.git
  61'
  63test_expect_success 'bare repository: check that .gitattribute is ignored' '
  65        (
  67                echo "f test=f"
  68                echo "a/i test=a/i"
  69        ) >.gitattributes &&
  70        attr_check f unspecified &&
  71        attr_check a/f unspecified &&
  72        attr_check a/c/f unspecified &&
  73        attr_check a/i unspecified &&
  74        attr_check subdir/a/i unspecified
  75'
  77test_expect_success 'bare repository: test info/attributes' '
  79        (
  81                echo "f test=f"
  82                echo "a/i test=a/i"
  83        ) >info/attributes &&
  84        attr_check f f &&
  85        attr_check a/f f &&
  86        attr_check a/c/f f &&
  87        attr_check a/i a/i &&
  88        attr_check subdir/a/i unspecified
  89'
  91test_done