tags:

views:

72

answers:

3

I want to know if there's a way to turn off the default push, but keep the default pull when using Mercurial. I don't want to accidentally pollute the master repository by inadvertently pushing from a an experimental repository.

+1  A: 

I was able to solve this by putting the following in my .hg/hgrc file, but I was wondering if there's a better/official way.

[paths]
default = http://server/hg/repo
default-push = .
mos
+1  A: 

I like your own answer of setting paths.default-push = . -- it is simple and it is clear that it will work.

Another option would be a pre-push hook:

[hooks]
pre-push = if [ $HG_PATS == "[]" -o $HG_PATS == "['default']" ]; then
               read -p "Really push to default? " -n 1; echo
               [ "$REPLY" == "y" ]
           fi

(Here I'm taking advantage of how you can split a long value over several lines by indenting them in a Mercurial config file.)

A push to default looks this

% hg push
Really push to default? n
warning: pre-push hook exited with status 1

where I typed the n. The hooks checks for both no arguments ($HG_PATS == "[]") and a default as the argument ($HG_PATS == "['default']") and will only prompt you in those cases. The $HG_PATS variable was introduced in Mercurial 1.6.

PS: I saw you updated the question and asked for a solution in PowerShell, but I'm afraid I know nothing about that language. However, you should be able to lift the important concepts from this answer yourself.

Martin Geisler
This is pretty good, but doesn't it completely remove the push ability? I want to be able to push; I just want to make sure that I don't accidentally push to the default.
mos
mos: You're right... I've updated the answer to let you push again and I've incorporated the best of Ry4an's answer as well.
Martin Geisler
Thanks for the update. I think it's time for me to ask a new question: how to get a powershell command to work in an hg hook.
mos
+2  A: 

Your solution probably is the quickest and is certainly effective. If there's any official way it would be using a preoutgoing hook:

[hooks]
preoutgoing = bash -c 'read -p "Really push to $HG_URL? " -n 1 RESP ; [ "$RESP" == "y" ]'

which will ask you if you want to push and provide the URL to which it would go as a reminder.

Ry4an
Hey, I really like this one, it's similar to Martin's, but gives me the option to continue when I manually type the url on the command line. If you can tell me how to do that in powershell, we're in business.
mos
I think the command to do complex scripting in powershell is wubi.exe. By which I mean, sorry, I dont know powershell. ;)
Ry4an
I did quite a bit of experimenting, but couldn't quite get it to work. I'll keep plugging away and update here if I solve it.
mos