10

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!

Kuroki Kaze
  • 8,161
  • 4
  • 36
  • 48
Sergio Acosta
  • 11,418
  • 12
  • 62
  • 91
  • 1
    +1. Anyway, I've seen more subjective questions not belonging to the community wiki :) – Roberto Aloi Mar 10 '10 at 10:32
  • @KennyTM: you are right in the sense that I should be making aliases for the commands I use the most. But I know I will eventually forget I have the alias and try to type 'hg qpush' just because I'm already used to it. – Sergio Acosta Mar 10 '10 at 11:20

2 Answers2

9

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)
Sergio Acosta
  • 11,418
  • 12
  • 62
  • 91
jk.
  • 13,817
  • 5
  • 37
  • 50
  • Very helpful. The two first suggestions are precisely the kind of answers I was looking for: different alternatives to solve my problem. I like the hook idea, but I don't know how to write them yet. That way I can keep using the native commands but with a safety net. Thanks. – Sergio Acosta Mar 10 '10 at 11:18
  • Thanks jk, I read the chapter and edited your question with the hook I came up with after reading it. – Sergio Acosta Mar 10 '10 at 12:28
  • and so the student becomes the master – jk. Mar 10 '10 at 13:36
  • The second suggestion seems to interfere with the behavior of other hg commands. I couldn't clone a local repository after adding that hook. – Cogwheel Apr 21 '11 at 02:03
6

Put the following in your .hgrc:

[alias]
pushtoserver = push
push = 'Did you mean qpush or pushtoserver?'

Works like this:

$ hg push
alias 'push' resolves to unknown command 'Did you mean qpush or pushtoserver?'

$ hg pushtoserver
abort: repository default-push not found!

See also the alias section of the hgrc manpage.

jpsecher
  • 4,461
  • 2
  • 33
  • 42
Sofahamster
  • 761
  • 4
  • 6