Code

5acb2d5bbd308a741179c09ebe923a4bb16fb032
[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 &&
42         cat <<EOF >expect-all
43 f: test: f
44 a/f: test: f
45 a/c/f: test: f
46 a/g: test: a/g
47 a/b/g: test: a/b/g
48 b/g: test: unspecified
49 a/b/h: test: a/b/h
50 a/b/d/g: test: a/b/d/*
51 onoff: test: unset
52 offon: test: set
53 no: notest: set
54 no: test: unspecified
55 a/b/d/no: notest: set
56 a/b/d/no: test: a/b/d/*
57 a/b/d/yes: notest: set
58 a/b/d/yes: test: unspecified
59 EOF
61 '
63 test_expect_success 'command line checks' '
65         test_must_fail git check-attr &&
66         test_must_fail git check-attr -- &&
67         test_must_fail git check-attr test &&
68         test_must_fail git check-attr test -- &&
69         test_must_fail git check-attr -- f &&
70         echo "f" | test_must_fail git check-attr --stdin &&
71         echo "f" | test_must_fail git check-attr --stdin -- f &&
72         echo "f" | test_must_fail git check-attr --stdin test -- f &&
73         test_must_fail git check-attr "" -- f
75 '
77 test_expect_success 'attribute test' '
79         attr_check f f &&
80         attr_check a/f f &&
81         attr_check a/c/f f &&
82         attr_check a/g a/g &&
83         attr_check a/b/g a/b/g &&
84         attr_check b/g unspecified &&
85         attr_check a/b/h a/b/h &&
86         attr_check a/b/d/g "a/b/d/*" &&
87         attr_check onoff unset &&
88         attr_check offon set &&
89         attr_check no unspecified &&
90         attr_check a/b/d/no "a/b/d/*" &&
91         attr_check a/b/d/yes unspecified
93 '
95 test_expect_success 'core.attributesfile' '
96         attr_check global unspecified &&
97         git config core.attributesfile "$HOME/global-gitattributes" &&
98         attr_check global global &&
99         git config core.attributesfile "~/global-gitattributes" &&
100         attr_check global global &&
101         echo "global test=precedence" >> .gitattributes &&
102         attr_check global precedence
105 test_expect_success 'attribute test: read paths from stdin' '
107         grep -v notest < expect-all > expect &&
108         sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
109         test_cmp expect actual
112 test_expect_success 'attribute test: --all option' '
114         grep -v unspecified < expect-all | sort > expect &&
115         sed -e "s/:.*//" < expect-all | uniq |
116                 git check-attr --stdin --all | sort > actual &&
117         test_cmp expect actual
120 test_expect_success 'root subdir attribute test' '
122         attr_check a/i a/i &&
123         attr_check subdir/a/i unspecified
127 test_expect_success 'setup bare' '
129         git clone --bare . bare.git &&
130         cd bare.git
134 test_expect_success 'bare repository: check that .gitattribute is ignored' '
136         (
137                 echo "f test=f"
138                 echo "a/i test=a/i"
139         ) >.gitattributes &&
140         attr_check f unspecified &&
141         attr_check a/f unspecified &&
142         attr_check a/c/f unspecified &&
143         attr_check a/i unspecified &&
144         attr_check subdir/a/i unspecified
148 test_expect_success 'bare repository: test info/attributes' '
150         (
151                 echo "f test=f"
152                 echo "a/i test=a/i"
153         ) >info/attributes &&
154         attr_check f f &&
155         attr_check a/f f &&
156         attr_check a/c/f f &&
157         attr_check a/i a/i &&
158         attr_check subdir/a/i unspecified
162 test_done