@@ -64,12 +64,24 @@ test_expect_success 'setup .gitattributes' '
64
64
fileSetLabel label
65
65
fileValue label=foo
66
66
fileWrongLabel label☺
67
+ newFileA* labelA
68
+ newFileB* labelB
67
69
EOF
68
70
echo fileSetLabel label1 >sub/.gitattributes &&
69
71
git add .gitattributes sub/.gitattributes &&
70
72
git commit -m "add attributes"
71
73
'
72
74
75
+ test_expect_success ' setup .gitignore' '
76
+ cat <<-\EOF >.gitignore &&
77
+ actual
78
+ expect
79
+ pathspec_file
80
+ EOF
81
+ git add .gitignore &&
82
+ git commit -m "add gitignore"
83
+ '
84
+
73
85
test_expect_success ' check specific set attr' '
74
86
cat <<-\EOF >expect &&
75
87
fileSetLabel
@@ -150,6 +162,7 @@ test_expect_success 'check specific value attr (2)' '
150
162
test_expect_success ' check unspecified attr' '
151
163
cat <<-\EOF >expect &&
152
164
.gitattributes
165
+ .gitignore
153
166
fileA
154
167
fileAB
155
168
fileAC
@@ -175,6 +188,7 @@ test_expect_success 'check unspecified attr' '
175
188
test_expect_success ' check unspecified attr (2)' '
176
189
cat <<-\EOF >expect &&
177
190
HEAD:.gitattributes
191
+ HEAD:.gitignore
178
192
HEAD:fileA
179
193
HEAD:fileAB
180
194
HEAD:fileAC
@@ -200,6 +214,7 @@ test_expect_success 'check unspecified attr (2)' '
200
214
test_expect_success ' check multiple unspecified attr' '
201
215
cat <<-\EOF >expect &&
202
216
.gitattributes
217
+ .gitignore
203
218
fileC
204
219
fileNoLabel
205
220
fileWrongLabel
@@ -239,16 +254,99 @@ test_expect_success 'fail on multiple attr specifiers in one pathspec item' '
239
254
test_grep "Only one" actual
240
255
'
241
256
242
- test_expect_success ' fail if attr magic is used places not implemented' '
257
+ test_expect_success ' fail if attr magic is used in places not implemented' '
243
258
# The main purpose of this test is to check that we actually fail
244
259
# when you attempt to use attr magic in commands that do not implement
245
- # attr magic. This test does not advocate git-add to stay that way,
246
- # though, but git-add is convenient as it has its own internal pathspec
247
- # parsing .
248
- test_must_fail git add ":(attr:labelB)" 2>actual &&
260
+ # attr magic. This test does not advocate check-ignore to stay that way.
261
+ # When you teach the command to grok the pathspec, you need to find
262
+ # another command to replace it for the test .
263
+ test_must_fail git check-ignore ":(attr:labelB)" 2>actual &&
249
264
test_grep "magic not supported" actual
250
265
'
251
266
267
+ test_expect_success ' check that attr magic works for git stash push' '
268
+ cat <<-\EOF >expect &&
269
+ A sub/newFileA-foo
270
+ EOF
271
+ >sub/newFileA-foo &&
272
+ >sub/newFileB-foo &&
273
+ git stash push --include-untracked -- ":(exclude,attr:labelB)" &&
274
+ git stash show --include-untracked --name-status >actual &&
275
+ test_cmp expect actual
276
+ '
277
+
278
+ test_expect_success ' check that attr magic works for git add --all' '
279
+ cat <<-\EOF >expect &&
280
+ sub/newFileA-foo
281
+ EOF
282
+ >sub/newFileA-foo &&
283
+ >sub/newFileB-foo &&
284
+ git add --all ":(exclude,attr:labelB)" &&
285
+ git diff --name-only --cached >actual &&
286
+ git restore -W -S . &&
287
+ test_cmp expect actual
288
+ '
289
+
290
+ test_expect_success ' check that attr magic works for git add -u' '
291
+ cat <<-\EOF >expect &&
292
+ sub/fileA
293
+ EOF
294
+ >sub/newFileA-foo &&
295
+ >sub/newFileB-foo &&
296
+ >sub/fileA &&
297
+ >sub/fileB &&
298
+ git add -u ":(exclude,attr:labelB)" &&
299
+ git diff --name-only --cached >actual &&
300
+ git restore -S -W . && rm sub/new* &&
301
+ test_cmp expect actual
302
+ '
303
+
304
+ test_expect_success ' check that attr magic works for git add <path>' '
305
+ cat <<-\EOF >expect &&
306
+ fileA
307
+ fileB
308
+ sub/fileA
309
+ EOF
310
+ >fileA &&
311
+ >fileB &&
312
+ >sub/fileA &&
313
+ >sub/fileB &&
314
+ git add ":(exclude,attr:labelB)sub/*" &&
315
+ git diff --name-only --cached >actual &&
316
+ git restore -S -W . &&
317
+ test_cmp expect actual
318
+ '
319
+
320
+ test_expect_success ' check that attr magic works for git -add .' '
321
+ cat <<-\EOF >expect &&
322
+ sub/fileA
323
+ EOF
324
+ >fileA &&
325
+ >fileB &&
326
+ >sub/fileA &&
327
+ >sub/fileB &&
328
+ cd sub &&
329
+ git add . ":(exclude,attr:labelB)" &&
330
+ cd .. &&
331
+ git diff --name-only --cached >actual &&
332
+ git restore -S -W . &&
333
+ test_cmp expect actual
334
+ '
335
+
336
+ test_expect_success ' check that attr magic works for git add --pathspec-from-file' '
337
+ cat <<-\EOF >pathspec_file &&
338
+ :(exclude,attr:labelB)
339
+ EOF
340
+ cat <<-\EOF >expect &&
341
+ sub/newFileA-foo
342
+ EOF
343
+ >sub/newFileA-foo &&
344
+ >sub/newFileB-foo &&
345
+ git add --all --pathspec-from-file=pathspec_file &&
346
+ git diff --name-only --cached >actual &&
347
+ test_cmp expect actual
348
+ '
349
+
252
350
test_expect_success ' abort on giving invalid label on the command line' '
253
351
test_must_fail git ls-files . ":(attr:☺)"
254
352
'
0 commit comments