一种可能的解决方案,使用 VonC 的“预提交”想法。
设置两个脚本;第一个check_subrepo_commit.sh
:
#!/bin/bash
# If the environment variable "SUBREPO" is set, allow changes.
[ "x$SUBREPO" != "x" ] && exit 0
# Otherwise, ensure that subrepositories have not changed.
LOCAL_CHANGES=`hg status -a -m`
GLOBAL_CHANGES=`hg status -S -a -m`
if [ "x${LOCAL_CHANGES}" != "x$GLOBAL_CHANGES" ]; then
echo "Subrepository changes exist!"
exit 1
fi
exit 0
第二个,check_subrepo_push.sh
:
#!/bin/bash
# If the environment variable "SUBREPO" is set, allow changes.
[ "x$SUBREPO" != "x" ] && exit 0
# Otherwise, ensure that subrepositories have not changed.
LOCAL_CHANGES=`hg outgoing | grep '^changeset:'`
GLOBAL_CHANGES=`hg outgoing -S | grep '^changeset:'`
if [ "x${LOCAL_CHANGES}" != "x$GLOBAL_CHANGES" ]; then
echo "Global changes exist!"
exit 1
fi
exit 0
将以下内容添加到您的.hgrc
:
[hooks]
pre-commit.subrepo = check_subrepo_commit.sh
pre-push.subrepo = check_subrepo_push.sh
默认情况下,如果子存储库中有未完成的更改hg push
,hg commit
则会中止。像这样运行命令:
SUBREPO=1 hg commit
将覆盖检查,如果您真的愿意,允许您执行全局提交/推送。