Search code examples
configurationmercurialdevelopment-environmentmercurial-queue

How to avoid accidentally 'hg push' instead of 'hg qpush'?


For those of you that use Mercurial with the MQ extension:

This is the second time I accidentally submit changes to the central repository (hg push) instead of applying a patch to my working directory (hg qpush).

I think this is very unfortunate, because it is a very simple error to make and has very severe consequences (the least having to do a hg backout and an extra hg push for each submitted change in order to generate a new commit that "undoes" the las one to the central repository, but the history becomes convoluted and unpleasant.

My goal is to configure some alias or something in my environment in orden to make hg push harder to do by accident.

Do you have any suggestions? I was thinking something like:

[alias]
push=      <-- how to NOP the push command??
pushtoserver=push

As this is a completely subjective question, this goes as community wiki.

thanks!


Solution

  • some vague ideas:

    • you could remove the default push location from your repo
    • you could write a "did you mean qpush? yes, no" pre-push hook

    This hook (bash command line) asks for confirmation before pushing changes to the remote (tested with mercurial 1.4):

    [hooks]
    preoutgoing.confirm = read -p 'Are you sure you want to push to remote? (y/n): '; echo $REPLY | grep -q 'y'
    
    • you could alias push to qpush and alias pushtoserver to push (i think this works but can't try it now)