.hgignore for Mac OS X applications

2008-03-20 05:37:06 UTC

If you use version control (and you should), then you're familiar with the pollution that an Xcode build folder can put into your status output:

? build/.DS_Store
? build/Debug/UTI Plist Helper.app/Contents/Info.plist
? build/Debug/UTI Plist Helper.app/Contents/MacOS/UTI Plist Helper
? build/Debug/UTI Plist Helper.app/Contents/PkgInfo
? build/Debug/UTI Plist Helper.app/Contents/Resources/English.lproj/InfoPlist.strings
? build/Debug/UTI Plist Helper.app/Contents/Resources/English.lproj/MainMenu.nib/classes.nib
? build/Debug/UTI Plist Helper.app/Contents/Resources/English.lproj/MainMenu.nib/info.nib
? build/Debug/UTI Plist Helper.app/Contents/Resources/English.lproj/MainMenu.nib/keyedobjects.nib
â‹®

Good version-control systems offer a way to ignore any file that matches a certain pattern. In the case of an Xcode project, you want to ignore the build folder and a few other things: .DS_Store files, backup nibs (those Foo~.nib packages that IB creates when you save), etc.

In Mercurial, the way to do that is to create a .hgignore file, and populate it with the patterns you want hg to ignore.

In order to save you repetitive work, here's a .hgignore file, already fully-populated, that you can use when versioning your Xcode-based project with Mercurial:

File: hgignore.bz2

syntax: glob

.DS_Store

*.swp
*~.nib

build

*.pbxuser
*.perspective
*.perspectivev3

What to do with this file

  1. Download it, and save the .bz2 file somewhere such as your Documents folder.
  2. cd into the top level of a repository.
  3. Extract the file using this command line: bunzip2 < ~/Documents/hgignore.bz2 > .hgignore
  4. Add the file: hg add .hgignore
  5. Commit it.

Thereafter, not only do you have a .hgignore file keeping your status output clean, but it's versioned, so it's easy for you to track and revert changes to the ignore file over time.

6 Responses to “.hgignore for Mac OS X applications”

  1. Mark Grimes Says:

    I use git, so not sure if syntax is the same but you might want to exclude default.pbxuser from your all inclusive *.pbxuser
    Also shouldn't it be *.perspectivev3 these days?

  2. Peter Hosey Says:

    Mark: Having a .hgignore doesn't prevent you from versioning files that match an ignore pattern. If you have a default.pbxuser that you want to version, go right ahead and do that—nothing's stopping you.

    As for .perspectivev3: Yup, you're right. I'm still developing primarily on Tiger, so I forgot about that. I'll update the file and the post with it.

  3. Andrew Says:

    According to hgrc(5), you can put

    [ui]
    ignore = ~/.htignore

    in your ~/.hgrc, and have this apply to all of your projects automatically.

  4. Peter Hosey Says:

    Andrew: Sure, but then each developer has to repeat that process. If you version .hgignore instead, they get its benefits automatically, from the moment they clone your repository.

    Of course, this way, you have to do it for each new project. It's a trade-off. I think this way results in less work over the long term.

  5. Till Says:

    I would like to use only one ignore file: ~/.hgignore. But then again I'd like it to ignore all files that have a tmp or temp soewhere within there path. Any idea how to achieve this?

  6. Peter Hosey Says:

    Till: Read Andrew's comment, and use a regex pattern:

    syntax: regexp

    .*/te?mp/.*

Leave a Reply

Do not delete the second sentence.