Search code examples
c#regexmercurialhgignore

.hgignore Filtering out all similar folder structures


I've got many C# class libraries in one repository. I want to blanket ignore all files that exist in a /obj/Debug/ folder, no matter where they may exist. They may exist at basically any depth within the individual projects.

Examples:

RepositoryMainFolder\MainProject\obj\Debug\ RepositoryMainFolder\RepositoryMainFolder.Internal.ProjectA\SbiLib.Internal.ProjectA\obj\Debug\ RepositoryMainFolder\RepositoryMainFolder.Internal.ProjectB\RepositoryMainFolder.Internal.ProjectB\obj\Debug\

So far I've tried a few methods, but this seems like what I'm after, but it doesn't seem to work.

.hgignore:

syntax: glob
RepositoryMainFolder/*/obj/Debug/*
RepositoryMainFolder/*/obj/x64/Debug/*

I've already tried doing the same thing under the regex syntax and it doesn't work either.


Solution

  • Well, glob syntax is "shell-style"; on both Windows and Unixen, for example, * does not recurse into subdirectories, but matches a single file/folder. Apparently Mercurial supports the ** glob, which does recurse:

    syntax: glob
    RepositoryMainFolder/**/obj/Debug/
    RepositoryMainFolder/**/obj/x64/Debug/
    

    With Mercurial, the globs are not absolute paths, though -- so you can simply write:

    syntax: glob
    /obj/Debug/
    /obj/x64/Debug/
    

    Or even just

    syntax: glob
    /obj/
    

    With a regular expression, * is not a wildcard per se, but a quantifier that means zero-or-more of whatever came before. . matches any character in a regex, so you could write:

    syntax: regexp
    RepositoryMainFolder/.*/obj/Debug/
    RepositoryMainFolder/.*/obj/x64/Debug/