3 test_description='test labels in pathspecs'
6 test_expect_success 'setup a tree' '
35 git add $path || return 1
37 git commit -m "initial commit" &&
38 git ls-files >actual &&
39 test_cmp expect actual
42 test_expect_success 'pathspec with no attr' '
43 test_must_fail git ls-files ":(attr:)"
46 test_expect_success 'pathspec with labels and non existent .gitattributes' '
47 git ls-files ":(attr:label)" >actual &&
48 test_must_be_empty actual
51 test_expect_success 'setup .gitattributes' '
52 cat <<-\EOF >.gitattributes &&
64 git add .gitattributes &&
65 git commit -m "add attributes"
68 test_expect_success 'check specific set attr' '
69 cat <<-\EOF >expect &&
73 git ls-files ":(attr:label)" >actual &&
74 test_cmp expect actual
77 test_expect_success 'check specific unset attr' '
78 cat <<-\EOF >expect &&
82 git ls-files ":(attr:-label)" >actual &&
83 test_cmp expect actual
86 test_expect_success 'check specific value attr' '
87 cat <<-\EOF >expect &&
91 git ls-files ":(attr:label=foo)" >actual &&
92 test_cmp expect actual &&
93 git ls-files ":(attr:label=bar)" >actual &&
94 test_must_be_empty actual
97 test_expect_success 'check unspecified attr' '
98 cat <<-\EOF >expect &&
117 git ls-files ":(attr:!label)" >actual &&
118 test_cmp expect actual
121 test_expect_success 'check multiple unspecified attr' '
122 cat <<-\EOF >expect &&
131 git ls-files ":(attr:!labelB !labelA !label)" >actual &&
132 test_cmp expect actual
135 test_expect_success 'check label with more labels but excluded path' '
136 cat <<-\EOF >expect &&
141 git ls-files ":(attr:labelB)" ":(exclude)sub/" >actual &&
142 test_cmp expect actual
145 test_expect_success 'check label excluding other labels' '
146 cat <<-\EOF >expect &&
153 git ls-files ":(attr:labelB)" ":(exclude,attr:labelC)sub/" >actual &&
154 test_cmp expect actual
157 test_expect_success 'fail on multiple attr specifiers in one pathspec item' '
158 test_must_fail git ls-files . ":(attr:labelB,attr:labelC)" 2>actual &&
159 test_i18ngrep "Only one" actual
162 test_expect_success 'fail if attr magic is used places not implemented' '
163 # The main purpose of this test is to check that we actually fail
164 # when you attempt to use attr magic in commands that do not implement
165 # attr magic. This test does not advocate git-add to stay that way,
166 # though, but git-add is convenient as it has its own internal pathspec
168 test_must_fail git add ":(attr:labelB)" 2>actual &&
169 test_i18ngrep "unsupported magic" actual
172 test_expect_success 'abort on giving invalid label on the command line' '
173 test_must_fail git ls-files . ":(attr:☺)"
176 test_expect_success 'abort on asking for wrong magic' '
177 test_must_fail git ls-files . ":(attr:-label=foo)" &&
178 test_must_fail git ls-files . ":(attr:!label=foo)"
181 test_expect_success 'check attribute list' '
182 cat <<-EOF >>.gitattributes &&
183 * whitespace=indent,trail,space
185 git ls-files ":(attr:whitespace=indent\,trail\,space)" >actual &&
186 git ls-files >expect &&
187 test_cmp expect actual
190 test_expect_success 'backslash cannot be the last character' '
191 test_must_fail git ls-files ":(attr:label=foo\\ labelA=bar)" 2>actual &&
192 test_i18ngrep "not allowed as last character in attr value" actual
195 test_expect_success 'backslash cannot be used as a value' '
196 test_must_fail git ls-files ":(attr:label=f\\\oo)" 2>actual &&
197 test_i18ngrep "for value matching" actual