列出Mercurial中的远程分支

时间:2010-11-28 12:03:08

标签: mercurial branch

有没有办法在Git中列出Mercurial中的远程分支?

git branch -r

我想列出远程机器上的分支(例如Bitbucket),所以使用:

hg branches -R `hg showconfig paths.default` --color false

中止失败:存储库不是本地

5 个答案:

答案 0 :(得分:18)

不,如果不将其克隆到本地,则无法列出远程存储库的分支。

如果对具有远程存储库的计算机有SSH访问权限,则可以直接使用Mercurial:ssh server hg -R path/to/repo branches

如果存储库是使用hgweb提供的,那么可以使用原始样式从中获取分支列表,以便于解析:https://www.mercurial-scm.org/repo/hg/branches?style=raw

BitBucket有自己的API,可以获取分支,请参阅their help并进行类似https://api.bitbucket.org/1.0/repositories/mirror/mercurial/branches/等网址的查询

答案 1 :(得分:18)

mercurial API允许它:

from mercurial import ui, hg, node

peer = hg.peer(ui.ui(), {}, 'http://hg.python.org/cpython')
for name, rev in peer.branchmap().items():
    print name, node.short(rev[0])

以上代码段产生:

default aaa68dce117e
legacy-trunk b77918288f7d
3.2 4787b9b2f860
3.0 4cd9f5e89061
3.1 5a6fa1b8767f
2.3 364638d6434d
2.2 61b0263d6881
2.1 e849d484029f
2.0 5fd74354d73b
2.7 260f3ad7af4b
2.6 f130ce67387d
2.5 b48e1b48e670
2.4 ceec209b26d4

答案 2 :(得分:3)

要扩展@ gvalkov的答案,您可以通过编写文件rheads.py使其成为真正的扩展名:

from mercurial import hg, commands, cmdutil, node
cmdtable = {}
command = cmdutil.command(cmdtable)
@command('rheads', commands.remoteopts, 'hg rheads [SOURCE]')
def rheads(ui, repo, source='default', **opts):
    """print (possibly remote) heads

    Prints a series of lines consisting of hashes and branch names.
    Specify a local or remote repository, defaulting to the configured remote.
    """
    other = hg.peer(ui or repo, opts, ui.expandpath(source))
    for tag, heads in other.branchmap().iteritems():
        for h in heads:
            ui.write("%s %s\n" % (node.short(h), tag))

使用

~/.hgrc中配置时
[extensions]
rheads = …/rheads.py

你可以像以下一样运行它:

hg rheads

我试图让它成为一个可以在任何存储库外部调用的命令,只是将URL指定为参数,但无法使语法起作用:

commands.norepo += " rheads"

答案 3 :(得分:2)

也许你正在寻找hg incoming -B这对我很有用。这显示了书签。

答案 4 :(得分:0)

请注意,这不会显示仅远程分支,它只会显示本地存储库知道的分支。

作为谷歌搜索“ hg命令行列表分支”时出现的唯一相关问题,我想我将在此保留。当您运行以下命令时-

hg log | grep "branch" | grep -v "summary" | sort --unique

它输出;

branch:      branch1
branch:      branch2
branch:      branch3
branch:      branch4
branch:      branch5
相关问题