11

I have the following in my .hgignore file:

syntax: glob
obj/*
bin/*
*.suo
*.user
*.ncb

If I comment out the *. filters, the filtering works fine filtering out the files in the bin and obj folder, however, if I keep those filters in I receive the following error:

abort: c:\temp\.hgignore: invalid pattern (relre): *.suo

Note: The file is encoded in UTF-8

Christian Hudon
  • 1,881
  • 1
  • 21
  • 42
contactmatt
  • 18,116
  • 40
  • 128
  • 186

3 Answers3

14

The error message from Mercurial tells us that your syntax: glob line is not read by Mercurial. Patterns in ignore files default to regular expressions, and *.suo is indeed an invalid regular expression (a regex cannot start with *).

Since this is on Windows, and since the file is UTF-8 encoded, then the only reasonable explanation is that there is somehthing that makes Mercurial ignore the syntax: glob line. An UTF-8 BOM is such a "something"! A byte order mark is a small signature inserted into UTF-16 encoded files to signal the byte order of the file. This is not needed or recommended for UTF-8 encoded files, but Windows editors have a tendency to insert them anyway.

To fix this, please open the file in Notepad and choose "Save As". Then pick ANSI as the encoding. Your .hgignore file is pure ASCII, so this will effective be the same as UTF-8 without a BOM.

Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
  • I have my Mercurial.ini file in my user folder (i.e. C:\users\ME). In that folder under the [ui] heading i have my username defined. So you're saying that in that same file, adding syntax: glob will help? (Just verifying, because I can't test it until later tonight) – contactmatt Jan 10 '12 at 19:26
  • I just re-read your question more carefully and came up with a better explanation. You only need to re-save your `.hgignore` file. – Martin Geisler Jan 10 '12 at 21:22
  • I didn't get to try it last night, but I'm excited to try it tonight! – contactmatt Jan 11 '12 at 21:17
  • 1
    @contactmatt: any news about this issue? I'm curious to hear if I guessed correctly in my answer :-) – Martin Geisler Jan 19 '12 at 09:44
  • Thanks alot @Martin ! I opened the file in Notepad++, saved the file as an ANSI file, and tested to see if it ignored those files and it does. Great insight about the UTF-8 format! – contactmatt Jan 23 '12 at 00:44
  • Great, I'm glad to hear that we figure it out! – Martin Geisler Jan 23 '12 at 07:47
3

To ignore the complete bin and obj folders, you don't need the /* behind them.

My default .hgignore file for Visual Studio projects looks like this:

syntax: glob
bin
obj
*.suo
*.user
Christian Specht
  • 35,843
  • 15
  • 128
  • 182
1

mercurial is somehow not interpreting the line syntax: glob because of the BOM (Byte-Order-Mark inserted right in front of the file, on windows x86-x64 running on Intel platform uses little endian) on windows platform you have to save the file as ASCII as contactmatt has advised.

Interestingly you can see the 2 byte BOM (Byte-Order-Mark) in hex view of the file saved on windows platform using utf-8 encoding

enter image description here

Now try to save this file using notepad in ASCII encoding and you would see that Byte-Order-Mark would be removed and mercurial would stop complaining about it. Attaching hex view after saving the file in ASCII.

enter image description here

A.B.
  • 1,554
  • 1
  • 14
  • 21