我想知道是否有办法关闭默认推送,但在使用Mercurial时保持默认拉动。我不想无意中从实验性存储库推送而不小心污染主存储库。
答案 0 :(得分:7)
我能够通过在我的.hg/hgrc
文件中添加以下内容来解决这个问题,但我想知道是否有更好/官方的方式。
[paths]
default = http://server/hg/repo
default-push = .
答案 1 :(得分:3)
您的解决方案可能是最快的,而且肯定是有效的。如果有任何官方方式,它将使用preoutgoing
钩子:
[hooks]
preoutgoing = bash -c 'read -p "Really push to $HG_URL? " -n 1 RESP ; [ "$RESP" == "y" ]'
会询问您是否要推送并提供其作为提醒的网址。
答案 2 :(得分:2)
我喜欢你自己设定paths.default-push = .
的答案 - 这很简单,很明显它会起作用。
另一种选择是预推钩:
[hooks]
pre-push = if [ $HG_PATS == "[]" -o $HG_PATS == "['default']" ]; then
read -p "Really push to default? " -n 1; echo
[ "$REPLY" == "y" ]
fi
(这里我利用了如何通过在Mercurial配置文件中缩进长行来将多个行拆分。)
推送到默认设置看起来
% hg push
Really push to default? n
warning: pre-push hook exited with status 1
我键入了n
。钩子检查没有参数($HG_PATS == "[]"
)和默认值作为参数($HG_PATS == "['default']"
),并且只会在这些情况下提示您。 Mercurial 1.6中引入了$HG_PATS
变量。
答案 3 :(得分:0)
之前发布的答案,在hgrc设置中
default-push = .
几乎没有,但不太正确。它可以破坏,例如如果你找到你的主目录。
以下是我当前禁用default-push的BKM:
我已经修改了在〜/ .hgrc中设置paths.default-push的想法,使其更加自我记录并且不易出错 - 因为正如我在下面指出的那样,设置default-push =。并不总是禁用推送。
在。hgrc 中
[paths]
# my main project master repo
project-master = ...
#DISABLING IMPLICIT PUSH
# to prevent embarassment from accidentally pushing to the project master repo
# instead of, in my case, a repo that has fine grain commits
# that the rest of the team does not want to see in the project master repo
#default-push = .
# this works mostly, but NOT if you use hg on your home directory
# since '.' in ~/.hgrc seems to be interpreted as -R ~
#default-push = /NONEXISTENT_default-push_--_must_specify_push_target_explicity
# this works ok, but I can clean up the error message using blanks
# keeping this around because blanks in pathnames confuses many UNIX tools
default-push = /'NONEXISTENT default-push -- must specify push target explicitly'
# this amounts to disabling implicit push targets.