Tahir Hassan's Blog

My Technical Notes

Tuesday, 19 August 2014

Ignoring Visual Studio Packages within SVN Directory.

Nuget advices that the svn:ignore pattern for the packages directory should be:


*[!c][!o][!n][!f][!i][!g]
*.config?*


That pattern is supposed to stop any file/folders with names which don't end in .config, but unfortunately allows names which are five or less characters in length. It also allows any file name where the sixth last character is c, or the fifth last character is o or ... the last character is g.

To get around this, we first need to outlaw any names which are six or less characters in length, and we need to outlaw any name which does not end specifically in config. The way we do this is by ensuring that the seventh last character is not a dot or the sixth last character is not a c or the fifth last character is not a o or ... or the last character is not a g.

Here is how it looks:


?
??
???
????
?????
??????
*[!.]??????
*?[!c]?????
*??[!o]????
*???[!n]???
*????[!f]??
*?????[!i]?
*??????[!g]

I have written a short F# script which generates this for a given file extension:

let allowExtensionOnly (ext: string) =
let length = ext.Length
let replicateQuestionMark i = String.replicate i "?"
let partOne = seq { 1..length } |> Seq.map replicateQuestionMark
let partTwo =
"." + ext |> Seq.mapi (fun i c ->
"*" + (replicateQuestionMark i) + (sprintf "[!%c]" c) + (replicateQuestionMark (length - i)))
String.concat "\r\n" ( seq { yield! partOne; yield! partTwo; } )


Calling allowExtensionOnly "config" will produce the above list.