Search code examples
mercurialpattern-matchingglob

Ignoring the same filename in root and subdirectories


In a Mac project, there are .DS_Store files at multiple levels, like so:

project/.DS_Store
project/subdir/.DS_Store
project/subdir/other_file.txt
project/.hgignore

When I use the following for a .hgignore file, the top-level .DS_Store doesn't get ignored. Is there any way to ignore both .DS_Store files with a single glob line in the .hgignore file? It seems like this should be easy, and adding another .DS_Store line feels clumsy.

syntax: glob

**/.DS_Store

The following works, but I prefer the readability of the glob syntax for ignore files:

syntax: regexp

.*\.DS_Store

Solution

  • Use the glob expression, but don't limit it to being inside a folder, like this:

    syntax:glob
    .DS_Store
    

    That will match any file with the exact name of .DS_Store anywhere in the repo.