git-check-attr: Add tests of command-line parsing
[git/git.git] / t / t0003-attributes.sh
CommitLineData
cf94ccda
JH
1#!/bin/sh
2
3test_description=gitattributes
4
5. ./test-lib.sh
6
7attr_check () {
8
9 path="$1"
10 expect="$2"
11
12 git check-attr test -- "$path" >actual &&
13 echo "$path: test: $2" >expect &&
82ebb0b6 14 test_cmp expect actual
cf94ccda
JH
15
16}
17
18
19test_expect_success 'setup' '
20
21 mkdir -p a/b/d a/c &&
22 (
ec775c41 23 echo "[attr]notest !test"
cf94ccda 24 echo "f test=f"
82881b38 25 echo "a/i test=a/i"
969f9d73
HG
26 echo "onoff test -test"
27 echo "offon -test test"
ec775c41 28 echo "no notest"
cf94ccda
JH
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/*"
ec775c41 37 echo "d/yes notest"
dcc04366 38 ) >a/b/.gitattributes &&
6df42ab9
PO
39 (
40 echo "global test=global"
e806c435 41 ) >"$HOME"/global-gitattributes
cf94ccda
JH
42
43'
44
c0b13b21
MH
45test_expect_success 'command line checks' '
46
09d7dd7a
MH
47 test_must_fail git check-attr &&
48 test_must_fail git check-attr -- &&
49 test_must_fail git check-attr -- f &&
50 echo "f" | test_must_fail git check-attr --stdin &&
51 echo "f" | test_must_fail git check-attr --stdin -- f &&
52 echo "f" | test_must_fail git check-attr --stdin test -- f &&
53 echo "f" | test_must_fail git check-attr --stdin test f &&
c0b13b21
MH
54 test_must_fail git check-attr "" -- f
55
56'
57
cf94ccda
JH
58test_expect_success 'attribute test' '
59
60 attr_check f f &&
61 attr_check a/f f &&
62 attr_check a/c/f f &&
63 attr_check a/g a/g &&
64 attr_check a/b/g a/b/g &&
65 attr_check b/g unspecified &&
66 attr_check a/b/h a/b/h &&
520ea857
MM
67 attr_check a/b/d/g "a/b/d/*" &&
68 attr_check onoff unset &&
69 attr_check offon set &&
70 attr_check no unspecified &&
71 attr_check a/b/d/no "a/b/d/*" &&
ec775c41 72 attr_check a/b/d/yes unspecified
cf94ccda
JH
73
74'
75
6df42ab9
PO
76test_expect_success 'core.attributesfile' '
77 attr_check global unspecified &&
78 git config core.attributesfile "$HOME/global-gitattributes" &&
79 attr_check global global &&
80 git config core.attributesfile "~/global-gitattributes" &&
81 attr_check global global &&
82 echo "global test=precedence" >> .gitattributes &&
83 attr_check global precedence
84'
85
b4666852
DP
86test_expect_success 'attribute test: read paths from stdin' '
87
a48fcd83 88 cat <<EOF > expect &&
b4666852
DP
89f: test: f
90a/f: test: f
91a/c/f: test: f
92a/g: test: a/g
93a/b/g: test: a/b/g
94b/g: test: unspecified
95a/b/h: test: a/b/h
96a/b/d/g: test: a/b/d/*
969f9d73
HG
97onoff: test: unset
98offon: test: set
ec775c41
HG
99no: test: unspecified
100a/b/d/no: test: a/b/d/*
101a/b/d/yes: test: unspecified
b4666852
DP
102EOF
103
104 sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
105 test_cmp expect actual
106'
107
82881b38
MO
108test_expect_success 'root subdir attribute test' '
109
110 attr_check a/i a/i &&
111 attr_check subdir/a/i unspecified
112
113'
114
2d35d556
RS
115test_expect_success 'setup bare' '
116
117 git clone --bare . bare.git &&
118 cd bare.git
119
120'
121
122test_expect_success 'bare repository: check that .gitattribute is ignored' '
123
124 (
125 echo "f test=f"
126 echo "a/i test=a/i"
127 ) >.gitattributes &&
128 attr_check f unspecified &&
129 attr_check a/f unspecified &&
130 attr_check a/c/f unspecified &&
131 attr_check a/i unspecified &&
132 attr_check subdir/a/i unspecified
133
134'
135
136test_expect_success 'bare repository: test info/attributes' '
137
138 (
139 echo "f test=f"
140 echo "a/i test=a/i"
141 ) >info/attributes &&
142 attr_check f f &&
143 attr_check a/f f &&
144 attr_check a/c/f f &&
145 attr_check a/i a/i &&
146 attr_check subdir/a/i unspecified
147
148'
149
cf94ccda 150test_done