64
fileSetLabel label
65
fileValue label=foo
66
fileWrongLabel label☺
67
+ newFileA* labelA
68
+ newFileB* labelB
69
EOF
70
echo fileSetLabel label1 >sub/.gitattributes &&
71
git add .gitattributes sub/.gitattributes &&
72
git commit -m "add attributes"
73
'
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
+
85
test_expect_success 'check specific set attr' '
86
cat <<-\EOF >expect &&
87
fileSetLabel
162
test_expect_success 'check unspecified attr' '
163
cat <<-\EOF >expect &&
164
.gitattributes
165
+ .gitignore
166
fileA
167
fileAB
168
fileAC
188
test_expect_success 'check unspecified attr (2)' '
189
cat <<-\EOF >expect &&
190
HEAD:.gitattributes
191
+ HEAD:.gitignore
192
HEAD:fileA
193
HEAD:fileAB
194
HEAD:fileAC
214
test_expect_success 'check multiple unspecified attr' '
215
cat <<-\EOF >expect &&
216
.gitattributes
217
+ .gitignore
218
fileC
219
fileNoLabel
220
fileWrongLabel
254
test_i18ngrep "Only one" actual
255
'
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' '
258
# The main purpose of this test is to check that we actually fail
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 &&
264
test_i18ngrep "magic not supported" actual
265
'
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
+
350
test_expect_success 'abort on giving invalid label on the command line' '
351
test_must_fail git ls-files . ":(attr:☺)"
352
'