Monday, October 8, 2012

Mercurial file patterns

I wanted to add all the scripts in a directory tree to the local Mercurial repository. I was going to do something like this:
> find . -name \*.sh | xargs hg add
Which is nice enough (find and xargs go well together), but you can also do it using just Mercurial using patterns. e.g.
> hg add 'glob:**.sh'
The two most useful patterns (for me) are:
  • '*' match any text in the current directory only
  • '**' match anything in the entire tree
The patterns are much richer than this though; see hg help patterns for more on what's available (including regexes).

No comments:

Post a Comment