attic: problems with pretxncommit hook

Greg Ward greg at gerg.ca
Mon Mar 1 13:32:16 CST 2010


Hi Bill --

I've been using attic on-and-off for a while now, and I have recently
found one show-stopping problem: it does not work with pretxncommit
hooks.  For example, say I have a pretxncommit hook to enforce some
bit of local policy -- no spaces in filenames, no case collisions, no
trailing whitespace, no commits on Tuesdays after 7pm, commit message
must contain the string  "fnord", whatever.  Could be anything.
attic's use of temporary throwaway commits fails when the hook steps
in and rejects its commit.

Example: my test repo is configured like this:

  $ cat .hg/hgrc
  [hooks]
  pretxncommit = .hg/pretxncihook

  [extensions]
  attic = ~/src/hgattic/attic.py

and my hook is dead simple:

 $ cat .hg/pretxncihook
  #!/bin/sh
  # reject commits where the commit message does not include "bug"
  if ! $HG tip --template '{desc}\n' | grep -q 'bug'; then
      echo "hook fail: no bug in commit message"
      exit 1
  fi

I can shelve a patch just fine:

  $ hg st
  M foo
  ? foo~
  $ hg shelve
  patch default shelved
  $ hg st
  ? foo~

But as soon as I try to *unshelve* it, bad news:

  $ hg unshelve
  hook fail: no bug in commit message
  transaction abort!
  rollback completed
  abort: pretxncommit hook exited with status 1

This was particularly confusing when it first bit me: "huh?!? I didn't
try to commit anything -- I'm just applying the patch in
.hg/attic/default to my working dir!!".  Only when I dug into the
source for attic did I see that it's using temporary commits.

As near as I can tell, though, it's impossible for this to work in
general.  There's no way to construct a changeset that will satisfy
any arbitrary pretxncommit hook.  So, umm, why *does* attic create
temporary changesets?  Is there perhaps another way to do it?

Thanks --

Greg


More information about the Mercurial-devel mailing list