测试 Mercurial 中未提交的更改
如果 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在mercurial 1.4及更高版本中,您可以使用summary命令,当存在更改时,它会提供如下输出:
以及此提交后:
或者,您可以安装提示扩展 并执行类似以下操作:
这将输出
!
或?
或不输出任何内容。当然,这两者都只是替代文本输出。我找不到任何直接使用退出代码的东西,但是自从 $?检查你可以执行的管道中的最后一个命令?
哪个将设置$?如果未提交任何更改,则非零:
In mercurial 1.4 and later you can use the summary command, which gives output like this when changes exist:
and this post-commit:
Alternately, you could install the prompt extension and do something like this:
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?
which will set $? non-zero if any changes are uncommitted:
您还可以运行
hg id
。如果哈希值以+
结尾,则表明工作副本已更改。这甚至应该适用于旧版本的 hg。听起来您已经在使用 zsh;好吧,几天前我帮助更新了 Mercurial 对内置 VCS_INFO 用于将 VCS 信息放入提示中。下一个版本预计将支持显示工作目录的更改(以及其他内容)。如果您不想等待,可以从 CVS 获取必要的文件。
目前我的提示包括这个(仅使用内置的 zsh 功能):
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):
我现在使用这个 bash-snippet 一段时间了:
I use this bash-snippet for some time now:
我使用:
如果跟踪文件没有更改,则命令输出为空字符串。
I use:
If no changes with tracked files, then the command output is an empty string.
id
和summary
都比status
慢,所以这是我目前知道的最快的方法,忽略未跟踪的文件:Both
id
andsummary
are slower thanstatus
, so this is the fastest way I currently know, ignoring untracked files:应该有比简单更优雅的东西
There should be something more elegant than simply