Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list all files having a git attribute set

git check-attr allows me to check if an attribute is set in .gitattributes for a specific set of files. e.g:

# git check-attr myAttr -- org/example/file1 org/example/file2
org/example/file1: myAttr: set
org/example/file2: myAttr: unspecified

Is there an easy way to list all files having myAttr set, including all wildcard matches?

like image 506
StackUnderflow Avatar asked Apr 17 '15 08:04

StackUnderflow


2 Answers

The other posts weren't working well for me, but I got there:

git ls-files | git check-attr -a --stdin

"Check every file in git and print all filters" one liner.

like image 106
ThorSummoner Avatar answered Sep 28 '22 19:09

ThorSummoner


You could set as an argument the list with all the files in your repository using git ls-files, like this:

git check-attr myAttr `git ls-files`

If your repository has too many files you might the following error:

-bash: /usr/bin/git: Argument list too long

which you can overcome with xargs:

git ls-files | xargs git check-attr myAttr

Finally, if you have too many files you will probably want to filter out the ones where you didn't specify the argument, to make the output more readable:

git ls-files | xargs git check-attr myAttr | grep -v 'unspecified$'

With grep, you could apply more filters to this output in order to match just the files that you want.

like image 42
Juan Avatar answered Sep 28 '22 19:09

Juan