Merge branch 'jk/for-each-ref-icase'
[git/git-svn.git] / t / t6135-pathspec-with-attrs.sh
blob77b8cef66198a870f669441857207af7142c0fbb
1 #!/bin/sh
3 test_description='test labels in pathspecs'
4 . ./test-lib.sh
6 test_expect_success 'setup a tree' '
7 cat <<-\EOF >expect &&
8 fileA
9 fileAB
10 fileAC
11 fileB
12 fileBC
13 fileC
14 fileNoLabel
15 fileSetLabel
16 fileUnsetLabel
17 fileValue
18 fileWrongLabel
19 sub/fileA
20 sub/fileAB
21 sub/fileAC
22 sub/fileB
23 sub/fileBC
24 sub/fileC
25 sub/fileNoLabel
26 sub/fileSetLabel
27 sub/fileUnsetLabel
28 sub/fileValue
29 sub/fileWrongLabel
30 EOF
31 mkdir sub &&
32 while read path
34 : >$path &&
35 git add $path || return 1
36 done <expect &&
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 &&
53 fileA labelA
54 fileB labelB
55 fileC labelC
56 fileAB labelA labelB
57 fileAC labelA labelC
58 fileBC labelB labelC
59 fileUnsetLabel -label
60 fileSetLabel label
61 fileValue label=foo
62 fileWrongLabel label☺
63 EOF
64 git add .gitattributes &&
65 git commit -m "add attributes"
68 test_expect_success 'check specific set attr' '
69 cat <<-\EOF >expect &&
70 fileSetLabel
71 sub/fileSetLabel
72 EOF
73 git ls-files ":(attr:label)" >actual &&
74 test_cmp expect actual
77 test_expect_success 'check specific unset attr' '
78 cat <<-\EOF >expect &&
79 fileUnsetLabel
80 sub/fileUnsetLabel
81 EOF
82 git ls-files ":(attr:-label)" >actual &&
83 test_cmp expect actual
86 test_expect_success 'check specific value attr' '
87 cat <<-\EOF >expect &&
88 fileValue
89 sub/fileValue
90 EOF
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 &&
99 .gitattributes
100 fileA
101 fileAB
102 fileAC
103 fileB
104 fileBC
105 fileC
106 fileNoLabel
107 fileWrongLabel
108 sub/fileA
109 sub/fileAB
110 sub/fileAC
111 sub/fileB
112 sub/fileBC
113 sub/fileC
114 sub/fileNoLabel
115 sub/fileWrongLabel
117 git ls-files ":(attr:!label)" >actual &&
118 test_cmp expect actual
121 test_expect_success 'check multiple unspecified attr' '
122 cat <<-\EOF >expect &&
123 .gitattributes
124 fileC
125 fileNoLabel
126 fileWrongLabel
127 sub/fileC
128 sub/fileNoLabel
129 sub/fileWrongLabel
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 &&
137 fileAB
138 fileB
139 fileBC
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 &&
147 fileAB
148 fileB
149 fileBC
150 sub/fileAB
151 sub/fileB
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
167 # parsing.
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
200 test_done