9

I'd like to make it so that every time I create a new repository, certain filters automatically get added to my .hgignore files by default.

For example, for C# projects, I would like these to be added:

glob:bin/*
glob:obj/*

Is this possible? How?

If it can't be automated, is it at least safe to copy the .hgignore file from one repository to another?

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
devuxer
  • 41,681
  • 47
  • 180
  • 292

5 Answers5

9

I use ~/.hgignore and just cp that into my repo.

In my ~/.hgrc:

[ui]
ignore.other = ~/.hgignore

I just put the really obvious stuff in that one. And copy it for project specific stuff.

I don't think its quite what you're asking for as there is no automation, but it does the trick.

Windows users, see Ry4an's comment below.

dlamotte
  • 6,145
  • 4
  • 31
  • 40
  • I'm not familiar enough with the command line language yet to really get what you're saying. I'll have to read up, but meanwhile, is there any way to do what you're saying with TortoiseHG? – devuxer Nov 23 '09 at 20:27
  • You can edit the global config file in tortoisehg too. Settings -> global -> edit file. – Macke Nov 23 '09 at 21:03
  • 5
    Dan, that's got nothing to do with the command line. Just create a file in your home folder named ,hgrc or optionally if you're on windows (I'm guessing you are) named mercurial.ini and put the two lines from his answer in there. Then create a file in your home folder named .hgignore and put in them your two lines from the question. TortoiseHG is a great app, but Mercurial still uses text files for configuration, and you need to create them with a text editor sometimes. – Ry4an Brase Nov 23 '09 at 21:04
4

Just to clarify, it is safe to copy a .hgignore from one repos to another, it is just a plain old simple text file.

Mizipzor
  • 51,151
  • 22
  • 97
  • 138
3

You could use a post-init hook to do it for you:

[hooks]
post-init.ignore-bin = echo 'glob:bin/*' >> .hgignore
post-init.ignore-obj = echo 'glob:obj/*' >> .hgignore

This form only works with the mkdir sample && cd sample && hg init style of creating a repo If you use the faster hg init sample form it will dump the new .hgignore file into the current directory.

You could write a more intelligent hook script if you prefer using hg init name.

Steve Losh
  • 19,642
  • 2
  • 51
  • 44
  • Not a bad idea. I like it for advanced users, but I don't think new users would be able to "get it". – dlamotte Nov 23 '09 at 21:26
1

hg add .hgignore ?

Perhaps you could clone from a repo that only had that file checked in. :)

Otherwise you'd have to write a small extension that did this in hg init somehow

Macke
  • 24,812
  • 7
  • 82
  • 118
  • What about copying an .hgignore file from one repository folder to another (just using the file system)? It *seems* to just be a simple text file. Any reason that wouldn't work properly? – devuxer Nov 23 '09 at 20:22
  • Thanks, I did try it...just wanted to make sure there were no side effects I wasn't aware of. – devuxer Nov 23 '09 at 20:31
  • nope. I thought you wanted something more clever. However, xyld's idea is pretty good too. – Macke Nov 23 '09 at 21:02
  • 2
    DanThMan: Mercurial uses only simple and transparent text files for its user-configurable data. That holds for `.hg/hgrc`, `.hgignore`, `.hgtags`. – Martin Geisler Nov 28 '09 at 12:56
0

In the TortoiseHg settings under the tab TortoiseHg users can specify the path of a Repo Skeleton. You can put your predefined .hgignore there, and it will be automatically copied during hg init.

See also: https://foss.heptapod.net/mercurial/tortoisehg/thg/-/issues/3569

Dominik
  • 116
  • 10