t / t0003-attributes.shon commit attr: Allow multiple changes to an attribute on the same line. (969f9d7)
   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                echo "onoff test -test"
  26                echo "offon -test test"
  27        ) >.gitattributes &&
  28        (
  29                echo "g test=a/g" &&
  30                echo "b/g test=a/b/g"
  31        ) >a/.gitattributes &&
  32        (
  33                echo "h test=a/b/h" &&
  34                echo "d/* test=a/b/d/*"
  35        ) >a/b/.gitattributes
  36
  37'
  38
  39test_expect_success 'attribute test' '
  40
  41        attr_check f f &&
  42        attr_check a/f f &&
  43        attr_check a/c/f f &&
  44        attr_check a/g a/g &&
  45        attr_check a/b/g a/b/g &&
  46        attr_check b/g unspecified &&
  47        attr_check a/b/h a/b/h &&
  48        attr_check a/b/d/g "a/b/d/*"
  49        attr_check onoff unset
  50        attr_check offon set
  51
  52'
  53
  54test_expect_success 'attribute test: read paths from stdin' '
  55
  56        cat <<EOF > expect
  57f: test: f
  58a/f: test: f
  59a/c/f: test: f
  60a/g: test: a/g
  61a/b/g: test: a/b/g
  62b/g: test: unspecified
  63a/b/h: test: a/b/h
  64a/b/d/g: test: a/b/d/*
  65onoff: test: unset
  66offon: test: set
  67EOF
  68
  69        sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
  70        test_cmp expect actual
  71'
  72
  73test_expect_success 'root subdir attribute test' '
  74
  75        attr_check a/i a/i &&
  76        attr_check subdir/a/i unspecified
  77
  78'
  79
  80test_expect_success 'setup bare' '
  81
  82        git clone --bare . bare.git &&
  83        cd bare.git
  84
  85'
  86
  87test_expect_success 'bare repository: check that .gitattribute is ignored' '
  88
  89        (
  90                echo "f test=f"
  91                echo "a/i test=a/i"
  92        ) >.gitattributes &&
  93        attr_check f unspecified &&
  94        attr_check a/f unspecified &&
  95        attr_check a/c/f unspecified &&
  96        attr_check a/i unspecified &&
  97        attr_check subdir/a/i unspecified
  98
  99'
 100
 101test_expect_success 'bare repository: test info/attributes' '
 102
 103        (
 104                echo "f test=f"
 105                echo "a/i test=a/i"
 106        ) >info/attributes &&
 107        attr_check f f &&
 108        attr_check a/f f &&
 109        attr_check a/c/f f &&
 110        attr_check a/i a/i &&
 111        attr_check subdir/a/i unspecified
 112
 113'
 114
 115test_done