How do I make mercurial ignore any file with .xxx extension
Asked Answered
C

4

21

I want Mercurial to ignore any file with a certain extension.

For example, I wanted to ignore files with a .SUO extension. (There's no need to version-control Visual Studio user settings.)

So I changed my .hgignore file to this:

syntax: glob
*.suo

However, this has no effect, and Mercurial still sees my .suo file.

What am I doing wrong here?

Co answered 20/5, 2011 at 3:28 Comment(2)
Are the files you are trying to ignore currently tracked (added) in your repo?Eloyelreath
By the way, this is on Windows, right?Landa
L
27

If, when running hg status before altering your .hgignore file, the .suo file had a ? in front of it, then it should be ignored now. If anything else (M or A for example) it is already tracked by the repository and will not magically stop being tracked. In such a case you'll need to do hg remove on the file to delete it and have hg stop tracking it, or just do hg forget on it to have hg stop tracking it but keep the file. Either should be followed by a commit.

The only files that will be omitted from the status listing if their path matches a pattern in the .hgignore file are files that are not tracked. It would make no sense to omit a file that is tracked, because you would never see whether it had been modified, added, or removed.

Edit: Mercurial does only track files (you can't make it track empty directories), but the patterns in .hgignore are simply run against strings of the file paths relative to the root of the repository. The very same relative paths that it shows you when you run hg status. So it does work how you say you want it to work because the following lines are a standard part of my own .hgignore files:

syntax: glob
*\obj\*
*\bin\*
*.csproj.user
*.suo

Again, when you run hg status and it shows a .suo file, what single character is at the beginning of that line? Is it a M, A, R, ! or ? character? What is the path after it?

Landa answered 20/5, 2011 at 3:36 Comment(2)
But this isn't the behaviour I want. I want the ignored files to NOT be shown in the hg status list. This totally works fine for ignoring entire folders, such a debug, so why not .suo files? I guess the answer must have something to do with the fact that Mercurial notices only files, not folders?Co
Note that you don't need to delete the file in question to make Mercurial stop tracking it, you just have to ask Mercurial to forget it. This will leave the file in place but stop the tracking. Remove (hg remove) is equivalent to hg forget and a file-system delete.Ordovician
M
8

Mercurial uses entries in a file called .hgignore to determine what files it completely ignores. It is normally located in the root file for your repository (and not in the .hg directory, which you might think).

You can find out more here:

http://www.selenic.com/mercurial/hgignore.5.html

Normally, we use regular expression syntax to ensure that case is not a factor in extensions:

# use regexp syntax.
syntax: regexp
(?i)\.dcu
(?i)\.identcache
(?i)\.dof
(?i)\.dsk
(?i)\.bak
(?i)\.old

That way, it ensures that even if for some reason the case of the extension changes, it is still ignored.

Madisonmadlen answered 20/5, 2011 at 4:3 Comment(3)
I tried the code above, and it still doesn't work. Even if I create a file called 'test.dcu', it still includes it in the list.Co
Then your .hgignore file is being, well, ignored.Madisonmadlen
Are you doing it from the command line? Maybe reset the command windows environment?Madisonmadlen
C
5

Example for ignoring/excluding files with .o extension:

.*\.o$

should translate to .*\.suo$ for .suo extensions.
I have used this method successfully

Columbian answered 3/4, 2012 at 17:43 Comment(0)
R
2

Check where .hgignore file is located and ensure it is either in $HOME or project root folder. Check the CASE (vs case) of the extension. I doubt if pattern matching is case insensitive.

edit: tested, the pattern matching is NOT case sensitive. Hence, add "*.SUO" if you want to ignore files with ".SUO" extension.

Roundhouse answered 20/5, 2011 at 3:33 Comment(2)
The file in question is all lower-case. I tried changing it to uppercase but it still doesn't work.Co
Also the .hgignore is in the project root folder, and it works perfectly with: '/bin$ [linebreak] /obj$ [linebreak] wwwroot$'. It seems to only not work with file extension ignores.Co

© 2022 - 2024 — McMap. All rights reserved.