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.
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 = .
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.
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.