git-check-attr: Demonstrate problems with unnormalized paths
[git/jrn.git] / t / t0003-attributes.sh
blob43957eae686203df6bda61a61fab791819b0804f
1 #!/bin/sh
3 test_description=gitattributes
5 . ./test-lib.sh
7 attr_check () {
9 path="$1"
10 expect="$2"
12 git check-attr test -- "$path" >actual 2>err &&
13 echo "$path: test: $2" >expect &&
14 test_cmp expect actual &&
15 test_line_count = 0 err
20 test_expect_success 'setup' '
22 mkdir -p a/b/d a/c &&
24 echo "[attr]notest !test"
25 echo "f test=f"
26 echo "a/i test=a/i"
27 echo "onoff test -test"
28 echo "offon -test test"
29 echo "no notest"
30 ) >.gitattributes &&
32 echo "g test=a/g" &&
33 echo "b/g test=a/b/g"
34 ) >a/.gitattributes &&
36 echo "h test=a/b/h" &&
37 echo "d/* test=a/b/d/*"
38 echo "d/yes notest"
39 ) >a/b/.gitattributes &&
41 echo "global test=global"
42 ) >"$HOME"/global-gitattributes &&
43 cat <<EOF >expect-all
44 f: test: f
45 a/f: test: f
46 a/c/f: test: f
47 a/g: test: a/g
48 a/b/g: test: a/b/g
49 b/g: test: unspecified
50 a/b/h: test: a/b/h
51 a/b/d/g: test: a/b/d/*
52 onoff: test: unset
53 offon: test: set
54 no: notest: set
55 no: test: unspecified
56 a/b/d/no: notest: set
57 a/b/d/no: test: a/b/d/*
58 a/b/d/yes: notest: set
59 a/b/d/yes: test: unspecified
60 EOF
64 test_expect_success 'command line checks' '
66 test_must_fail git check-attr &&
67 test_must_fail git check-attr -- &&
68 test_must_fail git check-attr test &&
69 test_must_fail git check-attr test -- &&
70 test_must_fail git check-attr -- f &&
71 echo "f" | test_must_fail git check-attr --stdin &&
72 echo "f" | test_must_fail git check-attr --stdin -- f &&
73 echo "f" | test_must_fail git check-attr --stdin test -- f &&
74 test_must_fail git check-attr "" -- f
78 test_expect_success 'attribute test' '
80 attr_check f f &&
81 attr_check a/f f &&
82 attr_check a/c/f f &&
83 attr_check a/g a/g &&
84 attr_check a/b/g a/b/g &&
85 attr_check b/g unspecified &&
86 attr_check a/b/h a/b/h &&
87 attr_check a/b/d/g "a/b/d/*" &&
88 attr_check onoff unset &&
89 attr_check offon set &&
90 attr_check no unspecified &&
91 attr_check a/b/d/no "a/b/d/*" &&
92 attr_check a/b/d/yes unspecified
96 test_expect_failure 'unnormalized paths' '
98 attr_check ./f f &&
99 attr_check ./a/g a/g &&
100 attr_check a/./g a/g &&
101 attr_check a/c/../b/g a/b/g
105 test_expect_success 'core.attributesfile' '
106 attr_check global unspecified &&
107 git config core.attributesfile "$HOME/global-gitattributes" &&
108 attr_check global global &&
109 git config core.attributesfile "~/global-gitattributes" &&
110 attr_check global global &&
111 echo "global test=precedence" >> .gitattributes &&
112 attr_check global precedence
115 test_expect_success 'attribute test: read paths from stdin' '
117 grep -v notest < expect-all > expect &&
118 sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
119 test_cmp expect actual
122 test_expect_success 'attribute test: --all option' '
124 grep -v unspecified < expect-all | sort > expect &&
125 sed -e "s/:.*//" < expect-all | uniq |
126 git check-attr --stdin --all | sort > actual &&
127 test_cmp expect actual
130 test_expect_success 'root subdir attribute test' '
132 attr_check a/i a/i &&
133 attr_check subdir/a/i unspecified
137 test_expect_success 'setup bare' '
139 git clone --bare . bare.git &&
140 cd bare.git
144 test_expect_success 'bare repository: check that .gitattribute is ignored' '
147 echo "f test=f"
148 echo "a/i test=a/i"
149 ) >.gitattributes &&
150 attr_check f unspecified &&
151 attr_check a/f unspecified &&
152 attr_check a/c/f unspecified &&
153 attr_check a/i unspecified &&
154 attr_check subdir/a/i unspecified
158 test_expect_success 'bare repository: test info/attributes' '
161 echo "f test=f"
162 echo "a/i test=a/i"
163 ) >info/attributes &&
164 attr_check f f &&
165 attr_check a/f f &&
166 attr_check a/c/f f &&
167 attr_check a/i a/i &&
168 attr_check subdir/a/i unspecified
172 test_done