Mercurial 子存储库:防止意外的递归提交和推送
我在一个团队工作,我们的 Mercurial 存储库中有一个代码,其中包含多个子存储库:
main/
main/subrepo1/
main/subrepo1/subrepo2/
Mercurial 的默认行为是,当在“main”中执行 hg commit
时,子存储库中的任何未完成的更改都会被删除。 subrepo1”和“subrepo2”也将被提交。同样,当推送“main”时,“subrepo1”和“subrepo2”中的任何传出提交也将被推送。
我们发现人们经常无意中在其子存储库中提交和推送更改(因为他们忘记了自己已进行更改,并且默认情况下 hg status
不显示递归更改)。我们还发现,这种全局提交/推送在我们的团队中几乎总是偶然的。
Mercurial 1.7 最近通过 hg status -S
和 hg moving -S
改进了这种情况,它们显示了子存储库的变化;但这仍然需要人们的关注。
如果子存储库中存在本来会提交/推送的更改/提交,Mercurial 中是否有一种方法可以使 hg commit
和 hg Push
中止?
I work on a team where we have a code in a mercurial repository with several subrepositories:
main/
main/subrepo1/
main/subrepo1/subrepo2/
The default behavior of Mercurial is that when a hg commit
is performed in "main", any outstanding changes in the subrepositories "subrepo1" and "subrepo2" will also be committed. Similarly, when "main" is pushed, any outgoing commits in "subrepo1" and "subrepo2" will also be pushed.
We find that people frequently inadvertently commit and push changes in their subrepositories (because they forgot they had made changes, and hg status
by default does not show recursive changes). We also find that such global commits / pushes are almost always accidental in our team.
Mercurial 1.7 recently improved the situation with hg status -S
and hg outgoing -S
, which show changes in subrepositories; but still, this requires people to be paying attention.
Is there a way in Mercurial to make hg commit
and hg push
abort if there are changes/commits in subrepostories that would otherwise be committed/pushed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
从 Mercurial 1.8 开始,有一个配置设置可以禁用递归提交。在父存储库
.hg/hgrc
中,您可以添加:如果父存储库中的提交发现子存储库中未提交的更改,则整个提交将中止,而不是静默提交子存储库。
Since Mercurial 1.8 there is a configuration setting that disables recursive commits. In the parent repositories
.hg/hgrc
you can add:If a commit in the parent repository finds uncommitted changes in a subrepository the whole commit is aborted, instead of silently committing the subrepositories.
Mercurial 2.0 会自动阻止您提交子存储库,除非您手动为
commit
指定--subrepos
(或者-S
)参数。例如,您尝试在子存储库中存在挂起的更改时执行提交,您会收到以下消息:
,但是,通过将
--subrepos
添加到命令中:您可以成功执行提交 仍然需要注意的事情:如果您更改了子存储库当前所在的版本,但没有更改子存储库的内容,Mercurial 将很乐意提交版本更改,而无需
--subrepos
标志。此外,递归推送仍然会在没有警告的情况下执行。Mercurial 2.0 automatically prevents you from committing subrepositories unless you manually specify the
--subrepos
(or, alternatively,-S
) argument tocommit
.For example, you try to perform a commit while there are pending changes in a subrepository, you get the following message:
You can successfully perform the commit, however, by adding
--subrepos
to the command:Some things to still be careful about: If you have changed the revision a subrepository is currently at, but not the contents of the subrepository, Mercurial will happily commit the version change without the
--subrepos
flag. Further, recursive pushes are still performed without warning.一种想法是在
.hgsub
文件中使用您具有只读访问权限的 URL。然后,当您确实想要推送子存储库时,只需 cd 进入它并执行hg Push THE_READ_WRITE_URL
即可。One notion is to use URLs to which you have read-only access in your
.hgsub
files. Then when you do actually want to push in the subrepo you can just cd into it and do ahg push THE_READ_WRITE_URL
.一种可能的解决方案是使用 VonC 的“预提交”思想。
设置两个脚本;第一个
check_subrepo_commit.sh
:第二个
check_subrepo_push.sh
:将以下内容添加到
.hgrc
中:默认情况下,
hg push如果子存储库中有未完成的更改,
和hg commit
将中止。运行如下命令:将覆盖检查,允许您执行全局提交/推送(如果您确实愿意)。
One possible solution, using VonC's "pre-commit" idea.
Setup two scripts; the first
check_subrepo_commit.sh
:The second,
check_subrepo_push.sh
:Add the following to your
.hgrc
:By default,
hg push
andhg commit
will abort if there are outstanding changes in subrepositories. Running a command like so:will override the check, allowing you to perform the global commit/push if you really want to.
可能是一个
预提交
钩子(不是预提交
)可以为您执行hg status -S
,并在检测到任何更改时阻止提交?May be a
pre-commit
hook (notprecommit
) could do thehg status -S
for you, and block the commit if it detects any changes?