Using negative patterns for Subversion's svn:ignore property
By jcscoobyrs on Thu, 07/16/2009 - 10:35Using Subversion's svn:ignore versioned property is pretty straight forward. Use a line-delimited list of patterns you want Subversion to not interest itself in. Here is an example to tell Subversion to ignore all files ending in .abc and .def:
svn propset svn:ignore "*.abc *.def" . property 'svn:ignore' set on '.'
(Note: On Windows, multi-line commands like the one above do not work. You need to use "svn propedit svn:ignore ." and then use the editor to add the two lines to the property value.) Like I said earlier, pretty straight forward. But what if you wanted to say something like: Hey Subversion...will you please ignore all files not ending in .xyz? Looking up the svn:ignore property in the Subversion book, linked to above, you will not find any mention of negation syntax. So it's not as simple as throwing in a "!*.xyz" into your svn:ignore property value. Well, after doing a little digging in the Subversion sources, and the mention in the Subversion book, you see that Subversion uses the fnmatch function to do its bidding. After looking around the internet for more information on what exactly fnmatch supports, I started playing around and I found a juicy little tidbit that will do exactly this. Here is an example:
svn propset svn:ignore "*[!x][!y][!z] *.xyz?*" . property 'svn:ignore' set on '.'
Yes...it's a little verbose but it works. The idea is to take any character of the extension, enclose it in square brackets behind an exclamation symbol. Just to make sure this sinks in, if you wanted to ignore all but .html files for a directory, here is an example:
svn propset svn:ignore "*[!h][!t][!m][!l] *.html?*" . property 'svn:ignore' set on '.'
There you have it. You can use this negation approach anywhere in the pattern, not just the end as the examples have shown. Maybe I can convince Mike Pilato to include this in the book...
Subversion:
Share this post:













