22540051d8db357379a7512a7d4c4e875227fe2e
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 &&
14 test_cmp expect actual
15
16}
17
18
19test_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
45test_expect_success 'command line checks' '
46
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
57
58'
59
60test_expect_success 'attribute test' '
61
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
75
76'
77
78test_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'
87
88test_expect_success 'attribute test: read paths from stdin' '
89
90 cat <<EOF > expect &&
91f: test: f
92a/f: test: f
93a/c/f: test: f
94a/g: test: a/g
95a/b/g: test: a/b/g
96b/g: test: unspecified
97a/b/h: test: a/b/h
98a/b/d/g: test: a/b/d/*
99onoff: test: unset
100offon: test: set
101no: test: unspecified
102a/b/d/no: test: a/b/d/*
103a/b/d/yes: test: unspecified
104EOF
105
106 sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
107 test_cmp expect actual
108'
109
110test_expect_success 'root subdir attribute test' '
111
112 attr_check a/i a/i &&
113 attr_check subdir/a/i unspecified
114
115'
116
117test_expect_success 'setup bare' '
118
119 git clone --bare . bare.git &&
120 cd bare.git
121
122'
123
124test_expect_success 'bare repository: check that .gitattribute is ignored' '
125
126 (
127 echo "f test=f"
128 echo "a/i test=a/i"
129 ) >.gitattributes &&
130 attr_check f unspecified &&
131 attr_check a/f unspecified &&
132 attr_check a/c/f unspecified &&
133 attr_check a/i unspecified &&
134 attr_check subdir/a/i unspecified
135
136'
137
138test_expect_success 'bare repository: test info/attributes' '
139
140 (
141 echo "f test=f"
142 echo "a/i test=a/i"
143 ) >info/attributes &&
144 attr_check f f &&
145 attr_check a/f f &&
146 attr_check a/c/f f &&
147 attr_check a/i a/i &&
148 attr_check subdir/a/i unspecified
149
150'
151
152test_done