git-check-attr: Add missing "&&"
[git/git.git] / t / t0003-attributes.sh
1 #!/bin/sh
2
3 test_description=gitattributes
4
5 . ./test-lib.sh
6
7 attr_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
19 test_expect_success 'setup' '
20
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
43 '
44
45 test_expect_success 'command line checks' '
46
47 test_must_fail git check-attr "" -- f
48
49 '
50
51 test_expect_success 'attribute test' '
52
53 attr_check f f &&
54 attr_check a/f f &&
55 attr_check a/c/f f &&
56 attr_check a/g a/g &&
57 attr_check a/b/g a/b/g &&
58 attr_check b/g unspecified &&
59 attr_check a/b/h a/b/h &&
60 attr_check a/b/d/g "a/b/d/*" &&
61 attr_check onoff unset &&
62 attr_check offon set &&
63 attr_check no unspecified &&
64 attr_check a/b/d/no "a/b/d/*" &&
65 attr_check a/b/d/yes unspecified
66
67 '
68
69 test_expect_success 'core.attributesfile' '
70 attr_check global unspecified &&
71 git config core.attributesfile "$HOME/global-gitattributes" &&
72 attr_check global global &&
73 git config core.attributesfile "~/global-gitattributes" &&
74 attr_check global global &&
75 echo "global test=precedence" >> .gitattributes &&
76 attr_check global precedence
77 '
78
79 test_expect_success 'attribute test: read paths from stdin' '
80
81 cat <<EOF > expect &&
82 f: test: f
83 a/f: test: f
84 a/c/f: test: f
85 a/g: test: a/g
86 a/b/g: test: a/b/g
87 b/g: test: unspecified
88 a/b/h: test: a/b/h
89 a/b/d/g: test: a/b/d/*
90 onoff: test: unset
91 offon: test: set
92 no: test: unspecified
93 a/b/d/no: test: a/b/d/*
94 a/b/d/yes: test: unspecified
95 EOF
96
97 sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
98 test_cmp expect actual
99 '
100
101 test_expect_success 'root subdir attribute test' '
102
103 attr_check a/i a/i &&
104 attr_check subdir/a/i unspecified
105
106 '
107
108 test_expect_success 'setup bare' '
109
110 git clone --bare . bare.git &&
111 cd bare.git
112
113 '
114
115 test_expect_success 'bare repository: check that .gitattribute is ignored' '
116
117 (
118 echo "f test=f"
119 echo "a/i test=a/i"
120 ) >.gitattributes &&
121 attr_check f unspecified &&
122 attr_check a/f unspecified &&
123 attr_check a/c/f unspecified &&
124 attr_check a/i unspecified &&
125 attr_check subdir/a/i unspecified
126
127 '
128
129 test_expect_success 'bare repository: test info/attributes' '
130
131 (
132 echo "f test=f"
133 echo "a/i test=a/i"
134 ) >info/attributes &&
135 attr_check f f &&
136 attr_check a/f f &&
137 attr_check a/c/f f &&
138 attr_check a/i a/i &&
139 attr_check subdir/a/i unspecified
140
141 '
142
143 test_done