3 test_description=gitattributes
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"
23 echo "onoff test -test"
24 echo "offon -test test"
30 ) >a/.gitattributes &&
32 echo "h test=a/b/h" &&
33 echo "d/* test=a/b/d/*"
35 ) >a/b/.gitattributes &&
37 echo "global test=global"
38 ) >"$HOME"/global-gitattributes &&
39 cat <<-EOF >expect-all
45 b/g: test: unspecified
47 a/b/d/g: test: a/b/d/*
53 a/b/d/no: test: a/b/d/*
54 a/b/d/yes: notest: set
55 a/b/d/yes: test: unspecified
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' '
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' '
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' '
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 &&
147 test_expect_success 'bare repository: check that .gitattribute is ignored' '
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 |
163 test_cmp ../specified-all actual
166 test_expect_success 'bare repository: test info/attributes' '
170 ) >info/attributes &&
173 attr_check a/c/f f &&
174 attr_check a/i a/i &&
175 attr_check subdir/a/i unspecified