【问题标题】:Why does mercurial report back incomplete name of tag when this name contains dashes?为什么当标签名称包含破折号时,mercurial 会报告不完整的标签名称?
【发布时间】:2026-01-11 07:25:01
【问题描述】:

我注意到 Mercurial 不会报告完整的标签名称,它是作为 update 命令的参数提供的,以防标签不存在并且名称中包含破折号。这有什么合乎逻辑的理由吗?

$ hg init test_repo && cd test_repo && hg up 'some-tag-with-dashes'
abort: unknown revision 'some'!

Mercurial 版本 2.9.2

我在https://bz.mercurial-scm.org/show_bug.cgi?id=4339提出了这个问题

【问题讨论】:

  • 您的问题的答案是“是”,这是有逻辑的原因。

标签: mercurial


【解决方案1】:

这实际上有点古怪。发生的事情是首先 hg 将您的字符串查找为标签,然后查找分支名称,然后将其解析为 revset。 revset 解析得很好,但随后它会寻找一个名为“some”的标签,以便对其进行设置算术,然后以这种方式失败。

不过,我们应该可以做得更好,我会用我的想法更新有关此问题的bug

【讨论】:

    【解决方案2】:

    我刚刚检查过,似乎只有当您的some-tag-with-dashes 不存在时才会发生错误。错误消息显然可以改进,但它按预期工作:

    $ hg init
    $ touch file; hg add file; hg commit -m "add file"
    
    $ hg tag some-tag-with-dashes
    $ hg up some-tag-with-dashes
    0 files updated, 0 files merged, 1 files removed, 0 files unresolved
    
    $ hg up some-other-tag-with-dashes
    abort: unknown revision 'some'!
    

    当您执行hg tags 时,您的标签是否出现:

    $ hg tags 
    tip                                1:00acd65cf970
    some-tag-with-dashes               0:8a895a220fa5
    

    【讨论】:

    • 我刚刚检查过,似乎只有当您的 some-tag-with-dashes 不存在时才会发生错误。这就是我在问题中所说的。 错误消息显然可以改进,但它正在按预期工作。我知道它有效,但问题是关于误导性报告。