测试 Mercurial 中未提交的更改

发布于 2024-08-20 14:39:28 字数 93 浏览 3 评论 0原文

如果 Mercurial 的工作树中有未提交的更改,那么检查脚本的最佳方法是什么。

(就像我在 git 中使用 git diff --quiet 的方式)

What's the best way to check in script if there're uncommitted changes in mercurial's working tree.

(the way I would with git diff --quiet in git)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(6

長街聽風 2024-08-27 14:39:28

在mercurial 1.4及更高版本中,您可以使用summary命令,当存在更改时,它会提供如下输出:

$ hg summary
parent: 0:ad218537bdef tip
 commited
branch: default
commit: 1 modified
update: (current)

以及此提交后:

$ hg summary
parent: 1:ef93d692f646 tip
 sfsdf
branch: default
commit: (clean)
update: (current)

或者,您可以安装提示扩展 并执行类似以下操作:

$ hg prompt '{status}'

这将输出 !? 或不输出任何内容。

当然,这两者都只是替代文本输出。我找不到任何直接使用退出代码的东西,但是自从 $?检查你可以执行的管道中的最后一个命令?

hg summary | grep -q 'commit: (clean)'

哪个将设置$?如果未提交任何更改,则非零:

$ hg summary | grep -q 'commit: (clean)' ; echo $?
0
$ echo more >> that 
$ hg summary | grep -q 'commit: (clean)' ; echo $?
1

In mercurial 1.4 and later you can use the summary command, which gives output like this when changes exist:

$ hg summary
parent: 0:ad218537bdef tip
 commited
branch: default
commit: 1 modified
update: (current)

and this post-commit:

$ hg summary
parent: 1:ef93d692f646 tip
 sfsdf
branch: default
commit: (clean)
update: (current)

Alternately, you could install the prompt extension and do something like this:

$ hg prompt '{status}'

which will output a ! or ? or nothing as appropriate.

Both of those, of course, are just alternate text outputs. I couldn't find anything that used the exit code directly, but since $? checks the last command in a pipe you could do?

hg summary | grep -q 'commit: (clean)'

which will set $? non-zero if any changes are uncommitted:

$ hg summary | grep -q 'commit: (clean)' ; echo $?
0
$ echo more >> that 
$ hg summary | grep -q 'commit: (clean)' ; echo $?
1
征棹 2024-08-27 14:39:28

您还可以运行hg id。如果哈希值以 + 结尾,则表明工作副本已更改。这甚至应该适用于旧版本的 hg。

听起来您已经在使用 zsh;好吧,几天前我帮助更新了 Mercurial 对内置 VCS_INFO 用于将 VCS 信息放入提示中。下一个版本预计将支持显示工作目录的更改(以及其他内容)。如果您不想等待,可以从 CVS 获取必要的文件

目前我的提示包括这个(仅使用内置的 zsh 功能):

   (hg)[1801+ branchname somemq.patch, anycurrentbookmarks]

You can also run hg id. If the hash ends with a + it indicates the working copy has changes. This should even work with old versions of hg.

It sounds like you're already using zsh; well, a couple days ago I helped to update the Mercurial support for the built-in VCS_INFO for putting VCS info in your prompt. Slated for the next release is support for showing changes to the working directory (among other things). If you don't want to wait you can grab the necessary files from CVS.

At the moment my prompt includes this (using only built-in zsh functionality):

   (hg)[1801+ branchname somemq.patch, anycurrentbookmarks]
浅语花开 2024-08-27 14:39:28

我现在使用这个 bash-snippet 一段时间了:

if [[ $(hg status 2>/dev/null) ]]
then
    # do something
fi

I use this bash-snippet for some time now:

if [[ $(hg status 2>/dev/null) ]]
then
    # do something
fi
楠木可依 2024-08-27 14:39:28

我使用:

hg status -m -a -r -d -u

如果跟踪文件没有更改,则命令输出为空字符串。

I use:

hg status -m -a -r -d -u

If no changes with tracked files, then the command output is an empty string.

空城仅有旧梦在 2024-08-27 14:39:28

idsummary 都比 status 慢,所以这是我目前知道的最快的方法,忽略未跟踪的文件:

[[ -z `hg status | grep -v '^?'` ]] && echo no-changes || echo has-changes

Both id and summary are slower than status, so this is the fastest way I currently know, ignoring untracked files:

[[ -z `hg status | grep -v '^?'` ]] && echo no-changes || echo has-changes
好久不见√ 2024-08-27 14:39:28

应该有比简单更优雅的东西

[ `hg st |wc -l` -eq 0 ] && echo hi

There should be something more elegant than simply

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