]>
git.ipfire.org Git - thirdparty/git.git/blob - t/t6135-pathspec-with-attrs.sh
3 test_description
='test labels in pathspecs'
6 test_expect_success
'setup a tree' '
34 echo content >$path &&
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
'pathspec with labels and non existent .gitattributes (2)' '
52 test_must_fail git grep content HEAD -- ":(attr:label)"
55 test_expect_success
'setup .gitattributes' '
56 cat <<-\EOF >.gitattributes &&
68 git add .gitattributes &&
69 git commit -m "add attributes"
72 test_expect_success
'check specific set attr' '
73 cat <<-\EOF >expect &&
77 git ls-files ":(attr:label)" >actual &&
78 test_cmp expect actual
81 test_expect_success
'check specific set attr (2)' '
82 cat <<-\EOF >expect &&
86 git grep -l content HEAD ":(attr:label)" >actual &&
87 test_cmp expect actual
90 test_expect_success
'check specific unset attr' '
91 cat <<-\EOF >expect &&
95 git ls-files ":(attr:-label)" >actual &&
96 test_cmp expect actual
99 test_expect_success
'check specific unset attr (2)' '
100 cat <<-\EOF >expect &&
102 HEAD:sub/fileUnsetLabel
104 git grep -l content HEAD ":(attr:-label)" >actual &&
105 test_cmp expect actual
108 test_expect_success
'check specific value attr' '
109 cat <<-\EOF >expect &&
113 git ls-files ":(attr:label=foo)" >actual &&
114 test_cmp expect actual &&
115 git ls-files ":(attr:label=bar)" >actual &&
116 test_must_be_empty actual
119 test_expect_success
'check specific value attr (2)' '
120 cat <<-\EOF >expect &&
124 git grep -l content HEAD ":(attr:label=foo)" >actual &&
125 test_cmp expect actual &&
126 test_must_fail git grep -l content HEAD ":(attr:label=bar)"
129 test_expect_success
'check unspecified attr' '
130 cat <<-\EOF >expect &&
149 git ls-files ":(attr:!label)" >actual &&
150 test_cmp expect actual
153 test_expect_success
'check unspecified attr (2)' '
154 cat <<-\EOF >expect &&
171 HEAD:sub/fileWrongLabel
173 git grep -l ^ HEAD ":(attr:!label)" >actual &&
174 test_cmp expect actual
177 test_expect_success
'check multiple unspecified attr' '
178 cat <<-\EOF >expect &&
187 git ls-files ":(attr:!labelB !labelA !label)" >actual &&
188 test_cmp expect actual
191 test_expect_success
'check label with more labels but excluded path' '
192 cat <<-\EOF >expect &&
197 git ls-files ":(attr:labelB)" ":(exclude)sub/" >actual &&
198 test_cmp expect actual
201 test_expect_success
'check label excluding other labels' '
202 cat <<-\EOF >expect &&
209 git ls-files ":(attr:labelB)" ":(exclude,attr:labelC)sub/" >actual &&
210 test_cmp expect actual
213 test_expect_success
'fail on multiple attr specifiers in one pathspec item' '
214 test_must_fail git ls-files . ":(attr:labelB,attr:labelC)" 2>actual &&
215 test_i18ngrep "Only one" actual
218 test_expect_success
'fail if attr magic is used places not implemented' '
219 # The main purpose of this test is to check that we actually fail
220 # when you attempt to use attr magic in commands that do not implement
221 # attr magic. This test does not advocate git-add to stay that way,
222 # though, but git-add is convenient as it has its own internal pathspec
224 test_must_fail git add ":(attr:labelB)" 2>actual &&
225 test_i18ngrep "magic not supported" actual
228 test_expect_success
'abort on giving invalid label on the command line' '
229 test_must_fail git ls-files . ":(attr:☺)"
232 test_expect_success
'abort on asking for wrong magic' '
233 test_must_fail git ls-files . ":(attr:-label=foo)" &&
234 test_must_fail git ls-files . ":(attr:!label=foo)"
237 test_expect_success
'check attribute list' '
238 cat <<-EOF >>.gitattributes &&
239 * whitespace=indent,trail,space
241 git ls-files ":(attr:whitespace=indent\,trail\,space)" >actual &&
242 git ls-files >expect &&
243 test_cmp expect actual
246 test_expect_success
'backslash cannot be the last character' '
247 test_must_fail git ls-files ":(attr:label=foo\\ labelA=bar)" 2>actual &&
248 test_i18ngrep "not allowed as last character in attr value" actual
251 test_expect_success
'backslash cannot be used as a value' '
252 test_must_fail git ls-files ":(attr:label=f\\\oo)" 2>actual &&
253 test_i18ngrep "for value matching" actual