31

In my project's .hgignore, I want to exclude /static/ (i.e., the static folder at the root of the directory), but not /templates/static/. How would I configure .hgignore to allow this?

4
  • 5
    What have you tried? Have you tried something like syntax:regexp with ^/static/.*? Commented Jan 29, 2012 at 5:50
  • 9
    Can this be done with glob?
    – user
    Commented Jun 30, 2013 at 12:57
  • 3
    @buffer No. According to the manpage, a glob cannot be rooted. But you can switch between syntaxes within the .hgignore. Commented Sep 14, 2015 at 12:24
  • 1
    If you're using glob syntax by default in your .hgignore, you can use re:^static/ to ignore the static folder only in your repo root. Commented Apr 3, 2017 at 19:50

2 Answers 2

35

You can include syntax: regexp at the beginning of .hgignore and then use perl regex syntax to root a directory by using ^. So just ^static should do the work.

2
  • 16
    I would change that to ^static/, otherwise it will ignore all directories whose name starts with static, which may cause confusion down the road. Commented Jan 30, 2012 at 9:51
  • 9
    If your .hgignore is in glob syntax you can just put syntax: regexp and syntex: glob before and after the line ^static/. Apparently it's allowed to switch between syntaxes. See manpage: "The chosen syntax stays in effect when parsing all patterns that follow, until another syntax is selected." Commented Sep 14, 2015 at 12:18
2

As of Mercurial 4.9, you can use syntax: rootglob to insert rooted glob patterns.

New rootglob: filename pattern for a glob that is rooted at the root of the repository. See hg help patterns and hg help hgignore for details

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.