Code

8892ba3bb2e55f16e4de3ee02c297077a6025740
[git.git] / t / t0003-attributes.sh
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 &&
13         echo "$path: test: $2" >expect &&
14         test_cmp expect actual
16 }
19 test_expect_success 'setup' '
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                 echo "global test=global"
41         ) >"$HOME"/global-gitattributes
43 '
45 test_expect_success 'command line checks' '
47         test_must_fail git check-attr &&
48         test_must_fail git check-attr -- &&
49         test_must_fail git check-attr test &&
50         test_must_fail git check-attr test -- &&
51         test_must_fail git check-attr -- f &&
52         echo "f" | test_must_fail git check-attr --stdin &&
53         echo "f" | test_must_fail git check-attr --stdin -- f &&
54         echo "f" | test_must_fail git check-attr --stdin test -- f &&
55         echo "f" | test_must_fail git check-attr --stdin test f &&
56         test_must_fail git check-attr "" -- f
58 '
60 test_expect_success 'attribute test' '
62         attr_check f f &&
63         attr_check a/f f &&
64         attr_check a/c/f f &&
65         attr_check a/g a/g &&
66         attr_check a/b/g a/b/g &&
67         attr_check b/g unspecified &&
68         attr_check a/b/h a/b/h &&
69         attr_check a/b/d/g "a/b/d/*" &&
70         attr_check onoff unset &&
71         attr_check offon set &&
72         attr_check no unspecified &&
73         attr_check a/b/d/no "a/b/d/*" &&
74         attr_check a/b/d/yes unspecified
76 '
78 test_expect_success 'core.attributesfile' '
79         attr_check global unspecified &&
80         git config core.attributesfile "$HOME/global-gitattributes" &&
81         attr_check global global &&
82         git config core.attributesfile "~/global-gitattributes" &&
83         attr_check global global &&
84         echo "global test=precedence" >> .gitattributes &&
85         attr_check global precedence
86 '
88 test_expect_success 'attribute test: read paths from stdin' '
90         cat <<EOF > expect &&
91 f: test: f
92 a/f: test: f
93 a/c/f: test: f
94 a/g: test: a/g
95 a/b/g: test: a/b/g
96 b/g: test: unspecified
97 a/b/h: test: a/b/h
98 a/b/d/g: test: a/b/d/*
99 onoff: test: unset
100 offon: test: set
101 no: test: unspecified
102 a/b/d/no: test: a/b/d/*
103 a/b/d/yes: test: unspecified
104 EOF
106         sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
107         test_cmp expect actual
110 test_expect_success 'attribute test: --all option' '
112         cat <<EOF > all &&
113 f: test: f
114 a/f: test: f
115 a/c/f: test: f
116 a/g: test: a/g
117 a/b/g: test: a/b/g
118 b/g: test: unspecified
119 a/b/h: test: a/b/h
120 a/b/d/g: test: a/b/d/*
121 onoff: test: unset
122 offon: test: set
123 no: notest: set
124 a/b/d/no: test: a/b/d/*
125 a/b/d/no: notest: set
126 a/b/d/yes: notest: set
127 EOF
129         grep -v unspecified < all | sort > expect &&
130         sed -e "s/:.*//" < all | uniq | git check-attr --stdin --all | sort > actual &&
131         test_cmp expect actual
134 test_expect_success 'root subdir attribute test' '
136         attr_check a/i a/i &&
137         attr_check subdir/a/i unspecified
141 test_expect_success 'setup bare' '
143         git clone --bare . bare.git &&
144         cd bare.git
148 test_expect_success 'bare repository: check that .gitattribute is ignored' '
150         (
151                 echo "f test=f"
152                 echo "a/i test=a/i"
153         ) >.gitattributes &&
154         attr_check f unspecified &&
155         attr_check a/f unspecified &&
156         attr_check a/c/f unspecified &&
157         attr_check a/i unspecified &&
158         attr_check subdir/a/i unspecified
162 test_expect_success 'bare repository: test info/attributes' '
164         (
165                 echo "f test=f"
166                 echo "a/i test=a/i"
167         ) >info/attributes &&
168         attr_check f f &&
169         attr_check a/f f &&
170         attr_check a/c/f f &&
171         attr_check a/i a/i &&
172         attr_check subdir/a/i unspecified
176 test_done