代码之家  ›  专栏  ›  技术社区  ›  Antony Hatchkins Alexander Hamilton

测试mercurial中的未提交更改

  •  8
  • Antony Hatchkins Alexander Hamilton  · 技术社区  · 15 年前

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

    (我会用这种方式 git diff --quiet 在GIT中)

    6 回复  |  直到 6 年前
        1
  •  10
  •   Ry4an Brase    15 年前

    在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)
    

    或者,您可以安装 prompt extension 然后这样做:

    $ 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
    
        2
  •  4
  •   whiteinge    14 年前

    你也可以跑步 hg id . 如果哈希以 + 表示工作副本有更改。这甚至适用于旧版本的hg。

    听起来你已经在使用zsh了;嗯,几天前我帮助更新了内置的mercurial支持 VCS_INFO 在提示中输入VCS信息。下一个版本的计划是支持显示对工作目录的更改(等等)。如果你不想等,你可以 grab the necessary files from CVS .

    目前,我的提示包括以下内容(仅使用内置的zsh功能):

       (hg)[1801+ branchname somemq.patch, anycurrentbookmarks]
    
        3
  •  2
  •   Xk2c    10 年前

    我现在使用这个bash片段有一段时间了:

    if [[ $(hg status 2>/dev/null) ]]
    then
        # do something
    fi
    
        4
  •  2
  •   etalon11    6 年前

    我使用:

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

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

        5
  •  1
  •   xixixao    9 年前

    两个 id summary 比…慢 status ,这是我目前知道的最快的方法,忽略未跟踪的文件:

    [[ -z `hg status | grep -v '^?'` ]] && echo no-changes || echo has-changes
    
        6
  •  0
  •   Antony Hatchkins Alexander Hamilton    12 年前

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

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