Mercurial 子存​​储库:防止意外的递归提交和推送

发布于 2024-10-15 19:18:54 字数 640 浏览 3 评论 0原文

我在一个团队工作,我们的 Mercurial 存储库中有一个代码,其中包含多个子存储库:

main/
main/subrepo1/
main/subrepo1/subrepo2/

Mercurial 的默认行为是,当在“main”中执行 hg commit 时,子存储库中的任何未完成的更改都会被删除。 subrepo1”和“subrepo2”也将被提交。同样,当推送“main”时,“subrepo1”和“subrepo2”中的任何传出提交也将被推送。

我们发现人们经常无意中在其子存储库中提交和推送更改(因为他们忘记了自己已进行更改,并且默认情况下 hg status 不显示递归更改)。我们还发现,这种全局提交/推送在我们的团队中几乎总是偶然的。

Mercurial 1.7 最近通过 hg status -Shg moving -S 改进了这种情况,它们显示了子存储库的变化;但这仍然需要人们的关注。

如果子存储库中存在本来会提交/推送的更改/提交,Mercurial 中是否有一种方法可以使 hg commithg 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

川水往事 2024-10-22 19:18:54

从 Mercurial 1.8 开始,有一个配置设置可以禁用递归提交。在父存储库 .hg/hgrc 中,您可以添加:

[ui]
commitsubrepos = no

如果父存储库中的提交发现子存储库中未提交的更改,则整个提交将中止,而不是静默提交子存储库。

Since Mercurial 1.8 there is a configuration setting that disables recursive commits. In the parent repositories .hg/hgrc you can add:

[ui]
commitsubrepos = no

If a commit in the parent repository finds uncommitted changes in a subrepository the whole commit is aborted, instead of silently committing the subrepositories.

狼亦尘 2024-10-22 19:18:54

Mercurial 2.0 会自动阻止您提交子存储库,除非您手动为 commit 指定 --subrepos(或者 -S)参数。

例如,您尝试在子存储库中存在挂起的更改时执行提交,您会收到以下消息:

# hg commit -m 'change main repo'
abort: uncommitted changes in subrepo hello
(use --subrepos for recursive commit)

,但是,通过将 --subrepos 添加到命令中:

# hg commit --subrepos -m 'commit subrepos'
committing subrepository hello

您可以成功执行提交 仍然需要注意的事情:如果您更改了子存储库当前所在的版本,但没有更改子存储库的内容,Mercurial 将很乐意提交版本更改,而无需--subrepos 标志。此外,递归推送仍然会在没有警告的情况下执行。

Mercurial 2.0 automatically prevents you from committing subrepositories unless you manually specify the --subrepos (or, alternatively, -S) argument to commit.

For example, you try to perform a commit while there are pending changes in a subrepository, you get the following message:

# hg commit -m 'change main repo'
abort: uncommitted changes in subrepo hello
(use --subrepos for recursive commit)

You can successfully perform the commit, however, by adding --subrepos to the command:

# hg commit --subrepos -m 'commit subrepos'
committing subrepository hello

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.

漫漫岁月 2024-10-22 19:18:54

一种想法是在 .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 a hg push THE_READ_WRITE_URL.

痴梦一场 2024-10-22 19:18:54

一种可能的解决方案是使用 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

将覆盖检查,允许您执行全局提交/推送(如果您确实愿意)。

One possible solution, using VonC's "pre-commit" idea.

Setup two scripts; the first 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

The second, 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

Add the following to your .hgrc:

[hooks]
pre-commit.subrepo = check_subrepo_commit.sh
pre-push.subrepo = check_subrepo_push.sh

By default, hg push and hg commit will abort if there are outstanding changes in subrepositories. Running a command like so:

SUBREPO=1 hg commit

will override the check, allowing you to perform the global commit/push if you really want to.

我不是你的备胎 2024-10-22 19:18:54

可能是一个预提交钩子(不是预提交)可以为您执行hg status -S,并在检测到任何更改时阻止提交?

May be a pre-commit hook (not precommit) could do the hg status -S for you, and block the commit if it detects any changes?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文