]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0003-attributes.sh
trace.c: ensure NULL is not passed to printf
[thirdparty/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"
cf94ccda 38 ) >a/b/.gitattributes
6df42ab9
PO
39 (
40 echo "global test=global"
e806c435 41 ) >"$HOME"/global-gitattributes
cf94ccda
JH
42
43'
44
45test_expect_success 'attribute test' '
46
47 attr_check f f &&
48 attr_check a/f f &&
49 attr_check a/c/f f &&
50 attr_check a/g a/g &&
51 attr_check a/b/g a/b/g &&
52 attr_check b/g unspecified &&
53 attr_check a/b/h a/b/h &&
520ea857
MM
54 attr_check a/b/d/g "a/b/d/*" &&
55 attr_check onoff unset &&
56 attr_check offon set &&
57 attr_check no unspecified &&
58 attr_check a/b/d/no "a/b/d/*" &&
ec775c41 59 attr_check a/b/d/yes unspecified
cf94ccda
JH
60
61'
62
6df42ab9
PO
63test_expect_success 'core.attributesfile' '
64 attr_check global unspecified &&
65 git config core.attributesfile "$HOME/global-gitattributes" &&
66 attr_check global global &&
67 git config core.attributesfile "~/global-gitattributes" &&
68 attr_check global global &&
69 echo "global test=precedence" >> .gitattributes &&
70 attr_check global precedence
71'
72
b4666852
DP
73test_expect_success 'attribute test: read paths from stdin' '
74
a48fcd83 75 cat <<EOF > expect &&
b4666852
DP
76f: test: f
77a/f: test: f
78a/c/f: test: f
79a/g: test: a/g
80a/b/g: test: a/b/g
81b/g: test: unspecified
82a/b/h: test: a/b/h
83a/b/d/g: test: a/b/d/*
969f9d73
HG
84onoff: test: unset
85offon: test: set
ec775c41
HG
86no: test: unspecified
87a/b/d/no: test: a/b/d/*
88a/b/d/yes: test: unspecified
b4666852
DP
89EOF
90
91 sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
92 test_cmp expect actual
93'
94
82881b38
MO
95test_expect_success 'root subdir attribute test' '
96
97 attr_check a/i a/i &&
98 attr_check subdir/a/i unspecified
99
100'
101
2d35d556
RS
102test_expect_success 'setup bare' '
103
104 git clone --bare . bare.git &&
105 cd bare.git
106
107'
108
109test_expect_success 'bare repository: check that .gitattribute is ignored' '
110
111 (
112 echo "f test=f"
113 echo "a/i test=a/i"
114 ) >.gitattributes &&
115 attr_check f unspecified &&
116 attr_check a/f unspecified &&
117 attr_check a/c/f unspecified &&
118 attr_check a/i unspecified &&
119 attr_check subdir/a/i unspecified
120
121'
122
123test_expect_success 'bare repository: test info/attributes' '
124
125 (
126 echo "f test=f"
127 echo "a/i test=a/i"
128 ) >info/attributes &&
129 attr_check f f &&
130 attr_check a/f f &&
131 attr_check a/c/f f &&
132 attr_check a/i a/i &&
133 attr_check subdir/a/i unspecified
134
135'
136
cf94ccda 137test_done