I'd like to ignore all files with a specific extension (e.g. *.config) since they are generated, except for files named "packages.config", which is static. In essence, a developer should not accidentally checkin in something like app.config, bob.config, web.config or any other file with the extension of ".config"
What is the appropiate pattern for svn:ignore?
What I tried
If I set the svn:ignore to
*.exe
*.dll
[Bb]in
[Oo]bj
[Rr]elease
[Dd]ebug
*.config
then all files are ignored, including packages.config. This is expected. So then I wanted to verify I can exclude all configuration files with packages in the filename.
*.exe
*.dll
[Bb]in
[Oo]bj
[Rr]elease
[Dd]ebug
packages.config
which does the trick.
However, I was unable to get the inverse of that pattern. I searched the internet for examples and found mention using "^" and another using "!".
I tried
*.exe
*.dll
[Bb]in
[Oo]bj
[Rr]elease
[Dd]ebug
!packages.config
which didn't have the desired effect. At this point I realize that I clearly don't understand how to achieve this. So I tried adding !packages.config
and then *.config
.
*.exe
*.dll
[Bb]in
[Oo]bj
[Rr]elease
[Dd]ebug
!packages.config
*.config
and *.config
and then !packages.config
*.exe
*.dll
[Bb]in
[Oo]bj
[Rr]elease
[Dd]ebug
*.config
!packages.config
and adding ^packages.config
*.exe
*.dll
[Bb]in
[Oo]bj
[Rr]elease
[Dd]ebug
^packages.config
that didn't work.
Sources
Many of the websites I visited focused on how to exclude files.
In a word: You can't...
However, if you already have packages.config
in your repository, then it won't be ignored even if svn ignore is set to *.config
. You can't ignore stuff already in the repository.
However, from what you want, it sounds like you can use my pre-commit hook for finer control over your situation. My hook takes a list of rules specified in a control file. For file rules, the last rule that matches the file's name is the access they're granted. In your situation, you would have two rules:
[FILE Configuration files must be named "packages.config"]
file = **/*.config
access = no-add
users = @ALL
[FILE Configuration files must be named "packages.config"]
file = **/packages.config
access = read-write
users = @ALL
If someone tried to add bob.config
, to the repository, my first rule is in effect. bob.config
matches *.config
, and that rule says you can't add any files that end in .config
.
However, if someone tries to add packages.config
to the repository, it will work because although packages.config
matches the first rule and the first rule prohibits it, packages.config
also matches the second rule which allows it. The second rule wins over the first rule.
As a bonus, my pre-commit hook will prohibit adding in bob.config
even if the user tried to ignore the ignore (which users are free to do).