core.hidedotfiles: hide '.git' dir by default
[git/dscho.git] / t / t0003-attributes.sh
blob46b0736b351d4676bdab16ec69ad1dfe42f3a900
1 #!/bin/sh
3 test_description=gitattributes
5 . ./test-lib.sh
7 attr_check () {
8 path="$1" expect="$2"
10 git check-attr test -- "$path" >actual 2>err &&
11 echo "$path: test: $2" >expect &&
12 test_cmp expect actual &&
13 test_line_count = 0 err
17 test_expect_success 'setup' '
18 mkdir -p a/b/d a/c b &&
20 echo "[attr]notest !test"
21 echo "f test=f"
22 echo "a/i test=a/i"
23 echo "onoff test -test"
24 echo "offon -test test"
25 echo "no notest"
26 ) >.gitattributes &&
28 echo "g test=a/g" &&
29 echo "b/g test=a/b/g"
30 ) >a/.gitattributes &&
32 echo "h test=a/b/h" &&
33 echo "d/* test=a/b/d/*"
34 echo "d/yes notest"
35 ) >a/b/.gitattributes &&
37 echo "global test=global"
38 ) >"$HOME"/global-gitattributes &&
39 cat <<-EOF >expect-all
40 f: test: f
41 a/f: test: f
42 a/c/f: test: f
43 a/g: test: a/g
44 a/b/g: test: a/b/g
45 b/g: test: unspecified
46 a/b/h: test: a/b/h
47 a/b/d/g: test: a/b/d/*
48 onoff: test: unset
49 offon: test: set
50 no: notest: set
51 no: test: unspecified
52 a/b/d/no: notest: set
53 a/b/d/no: test: a/b/d/*
54 a/b/d/yes: notest: set
55 a/b/d/yes: test: unspecified
56 EOF
59 test_expect_success 'command line checks' '
60 test_must_fail git check-attr &&
61 test_must_fail git check-attr -- &&
62 test_must_fail git check-attr test &&
63 test_must_fail git check-attr test -- &&
64 test_must_fail git check-attr -- f &&
65 echo "f" | test_must_fail git check-attr --stdin &&
66 echo "f" | test_must_fail git check-attr --stdin -- f &&
67 echo "f" | test_must_fail git check-attr --stdin test -- f &&
68 test_must_fail git check-attr "" -- f
71 test_expect_success 'attribute test' '
72 attr_check f f &&
73 attr_check a/f f &&
74 attr_check a/c/f f &&
75 attr_check a/g a/g &&
76 attr_check a/b/g a/b/g &&
77 attr_check b/g unspecified &&
78 attr_check a/b/h a/b/h &&
79 attr_check a/b/d/g "a/b/d/*" &&
80 attr_check onoff unset &&
81 attr_check offon set &&
82 attr_check no unspecified &&
83 attr_check a/b/d/no "a/b/d/*" &&
84 attr_check a/b/d/yes unspecified
87 test_expect_success 'unnormalized paths' '
88 attr_check ./f f &&
89 attr_check ./a/g a/g &&
90 attr_check a/./g a/g &&
91 attr_check a/c/../b/g a/b/g
94 test_expect_success 'relative paths' '
95 (cd a && attr_check ../f f) &&
96 (cd a && attr_check f f) &&
97 (cd a && attr_check i a/i) &&
98 (cd a && attr_check g a/g) &&
99 (cd a && attr_check b/g a/b/g) &&
100 (cd b && attr_check ../a/f f) &&
101 (cd b && attr_check ../a/g a/g) &&
102 (cd b && attr_check ../a/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' '
116 grep -v notest <expect-all >expect &&
117 sed -e "s/:.*//" <expect | git check-attr --stdin test >actual &&
118 test_cmp expect actual
121 test_expect_success 'attribute test: --all option' '
122 grep -v unspecified <expect-all | sort >specified-all &&
123 sed -e "s/:.*//" <expect-all | uniq >stdin-all &&
124 git check-attr --stdin --all <stdin-all | sort >actual &&
125 test_cmp specified-all actual
128 test_expect_success 'attribute test: --cached option' '
129 : >empty &&
130 git check-attr --cached --stdin --all <stdin-all | sort >actual &&
131 test_cmp empty actual &&
132 git add .gitattributes a/.gitattributes a/b/.gitattributes &&
133 git check-attr --cached --stdin --all <stdin-all | sort >actual &&
134 test_cmp specified-all actual
137 test_expect_success 'root subdir attribute test' '
138 attr_check a/i a/i &&
139 attr_check subdir/a/i unspecified
142 test_expect_success 'setup bare' '
143 git clone --bare . bare.git &&
144 cd bare.git
147 test_expect_success 'bare repository: check that .gitattribute is ignored' '
149 echo "f test=f"
150 echo "a/i test=a/i"
151 ) >.gitattributes &&
152 attr_check f unspecified &&
153 attr_check a/f unspecified &&
154 attr_check a/c/f unspecified &&
155 attr_check a/i unspecified &&
156 attr_check subdir/a/i unspecified
159 test_expect_success 'bare repository: check that --cached honors index' '
160 GIT_INDEX_FILE=../.git/index \
161 git check-attr --cached --stdin --all <../stdin-all |
162 sort >actual &&
163 test_cmp ../specified-all actual
166 test_expect_success 'bare repository: test info/attributes' '
168 echo "f test=f"
169 echo "a/i test=a/i"
170 ) >info/attributes &&
171 attr_check f f &&
172 attr_check a/f f &&
173 attr_check a/c/f f &&
174 attr_check a/i a/i &&
175 attr_check subdir/a/i unspecified
178 test_done