Anatol
Anatol

Reputation: 2043

File Expansion in .gitattributes

.gitattributes allows running filters for several extensions like:

*.sh filter=myFunc
*.txt filter=myFunc

I thought (or better hoped) I can "oneline" this with file expansion:

*.{sh,txt} filter=myFunc

Unfortunately while the former works the later does not. Is there a way to match several extensions in one shot?

Upvotes: 3

Views: 652

Answers (2)

DecimalTurn
DecimalTurn

Reputation: 4278

Is there a way to match several extensions in one shot?

Technically, there is a way if they all have the same length (unlike in your example). For instance, you could do .ts and .js on the same line:

*.[jt]s filter=myFunc

In this case [...] is a character class that will match a single character inside the brackets, but as you can see, that's not easily scalable to many extensions.

Most of the times I've seen this technique used was to make sure that all possible capitalizations of an extension were taken into account.

E.g.:

*.[eE][xX][eE] -text

Upvotes: 3

torek
torek

Reputation: 490078

The short answer is no. Git's glob patterns do not include brace expansion. See the gitglossary entry for pathspec for what is allowed (and note that not all commands use pathspecs, some just use raw globs).

Upvotes: 3

Related Questions