Prevent missing files in your hg commit

Posted 5 years, 1 month ago at 17:46. 7 comments

The Mozilla RelEng team was having one of our patented digressional discussions in IRC yesterday when we got around to the subject of hg irritations. My personal annoyance was that I frequently need to check-in patches for other people who don’t have commit access, but I don’t always remember to check before pushing to make sure I didn’t miss adding any new files created by the patch.

Because Ted is more about solving problems than bitching about them, he suggested I write a hook to prevent myself from missing files. Here it is:

precommit = hg status | (! grep '^?')

Add that to your .hgrc file (and setup some good global hgignore rules) and you’re golden.

Current Tunes: Moist - Push | Filed under Build/Release, Mozilla, Software |

7 Replies

  1. Robert O'Callahan Jul 9th 2009

    Why don’t you just “hg import” the patch so new files are automatically added by hg?

  2. Man, it would be sweet if I always got them in an importable format. ;-)

  3. I’d love to know what some of the complaints were[0]… since we all know I’m about bitching more than solving problems. ;-)

    [0] Seriously. I’d like to know what I’m in for when I eventually have to support a mess of DVCS systems…

  4. Actually, I think hg status has a -u option that should make this even easier (and faster).

  5. Histrionic Jul 12th 2009

    Unless I’m mistaken, the command:

    $ hg status | (! grep ‘^?’)

    … is the same as:

    $ hg status –unknown

    … but saves piping to grep.

  6. hg status -u does accomplish the same output, yes, but it always returns 0, so the commit just plows ahead. The pipe to grep returns an exit status that actually prevents the commit.

  7. You might want to grep for ! (missing) files too, in case a patch removed a file.

Leave a Reply