Mercurial gives "invalid pattern" error for simple GLOB syntax
Asked Answered
D

3

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

Deerhound answered 10/1, 2012 at 4:46 Comment(0)
S
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.

Salisbury answered 10/1, 2012 at 7:28 Comment(6)
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)Deerhound
I just re-read your question more carefully and came up with a better explanation. You only need to re-save your .hgignore file.Salisbury
I didn't get to try it last night, but I'm excited to try it tonight!Deerhound
@contactmatt: any news about this issue? I'm curious to hear if I guessed correctly in my answer :-)Salisbury
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!Deerhound
Great, I'm glad to hear that we figure it out!Salisbury
R
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
Rhinoplasty answered 10/1, 2012 at 6:48 Comment(0)
D
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

Deville answered 24/7, 2016 at 18:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.