0

I am a newbie to Mercurial and I am writing a pretag hook to check policy on tag names.

I have the below code.

version_re = r'(ver-\d+\.\d+\.\d+|tip)$'
def invalidtag(ui, repo, hooktype, node, tag, **kwargs):
assert(hooktype == 'pretag')

....


if not re_.match(tag):
    ui.warn('Invalid tag name "%s".\n' % tag)
    return True
return False

This hooks works perfect when I am tagging. But this hook is also executed when I want to remove invalid tags with --remove options.

So, is there any way to avoid his situation?

Sujay SA
  • 11
  • 3

1 Answers1

0

When a tag is marked for removal the node passed to the hook is the nullid from mercurial.node. So you should be able to check this the node against the nullid from mercurial.node.

You should convert the node to the hexadecimal representation with the "hex" function from mercurial.node. This hex function has a different behavior than the built-in one from python.

rfkortekaas
  • 6,049
  • 2
  • 27
  • 34