t / t0003-attributes.shon commit Fix parsing of @{-1}@{1} (aa9c55b)
   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 "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
  35'
  36
  37test_expect_success 'attribute test' '
  38
  39        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
  48'
  49
  50test_expect_success 'attribute test: read paths from stdin' '
  51
  52        cat <<EOF > expect
  53f: test: f
  54a/f: test: f
  55a/c/f: test: f
  56a/g: test: a/g
  57a/b/g: test: a/b/g
  58b/g: test: unspecified
  59a/b/h: test: a/b/h
  60a/b/d/g: test: a/b/d/*
  61EOF
  62
  63        sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
  64        test_cmp expect actual
  65'
  66
  67test_expect_success 'root subdir attribute test' '
  68
  69        attr_check a/i a/i &&
  70        attr_check subdir/a/i unspecified
  71
  72'
  73
  74test_expect_success 'setup bare' '
  75
  76        git clone --bare . bare.git &&
  77        cd bare.git
  78
  79'
  80
  81test_expect_success 'bare repository: check that .gitattribute is ignored' '
  82
  83        (
  84                echo "f test=f"
  85                echo "a/i test=a/i"
  86        ) >.gitattributes &&
  87        attr_check f unspecified &&
  88        attr_check a/f unspecified &&
  89        attr_check a/c/f unspecified &&
  90        attr_check a/i unspecified &&
  91        attr_check subdir/a/i unspecified
  92
  93'
  94
  95test_expect_success 'bare repository: test info/attributes' '
  96
  97        (
  98                echo "f test=f"
  99                echo "a/i test=a/i"
 100        ) >info/attributes &&
 101        attr_check f f &&
 102        attr_check a/f f &&
 103        attr_check a/c/f f &&
 104        attr_check a/i a/i &&
 105        attr_check subdir/a/i unspecified
 106
 107'
 108
 109test_done