简体   繁体   English

列出Mercurial中的远程分支

[英]List remote branches in Mercurial

Is there a way to list remote branches in Mercurial like there in Git? 有没有办法在Git中列出Mercurial中的远程分支?

git branch -r

I want to list the branches on a remote machine (eg Bitbucket), so using: 我想列出远程机器上的分支(例如Bitbucket),所以使用:

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

fails with abort: repository not local 中止失败:存储库不是本地的

The mercurial API allows it: 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]))

The above snippet produces: 上面的代码片段产生:

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

No, it is not possible to list branches of a remote repository without cloning it to local. 不,如果不将其克隆到本地,则无法列出远程存储库的分支。

If there is SSH access to the machine having the remote repository, then Mercurial could be used directly: ssh server hg -R path/to/repo branches . 如果对具有远程存储库的计算机有SSH访问权限,则可以直接使用Mercurial: ssh server hg -R path/to/repo branches

If the repository is served with hgweb, then a list of branches can be fetched from that, using the raw style for easy parsing: https://www.mercurial-scm.org/repo/hg/branches?style=raw 如果存储库是使用hgweb提供的,那么可以使用原始样式从中获取分支列表,以便于解析: https ://www.mercurial-scm.org/repo/hg/branches?style = raw

BitBucket has its own API, where it is possible to get the branches, see their help and make a query like to a URL like https://api.bitbucket.org/1.0/repositories/mirror/mercurial/branches/ BitBucket有自己的API,可以获取分支,查看他们的帮助,并像https://api.bitbucket.org/1.0/repositories/mirror/mercurial/branches/这样的URL进行查询。

To expand on @gvalkov's answer, you can make this a real extension by writing a file rheads.py : 要扩展@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))

When configured in ~/.hgrc with ~/.hgrc配置时

[extensions]
rheads = …/rheads.py

you can run it like: 你可以运行它:

hg rheads

I tried to make it a command that can be invoked outside any repository, just specifying the URL as an argument, but could not get the syntax to work: 我试图使它成为一个可以在任何存储库外调用的命令,只是将URL指定为参数,但无法使语法工作:

commands.norepo += " rheads"

maybe you are looking for hg incoming -B This worked quite well for me. 也许你正在寻找hg incoming -B这对我很有用。 This shows the bookmarks. 这显示了书签。

Please note, this will not display remote only branches, it will only show branches that your local repository is aware of. 请注意,这不会显示仅远程分支,它只显示本地存储库知道的分支。

As the only relevant question to appear when googling "hg command line list branches", I thought I'd leave this here. 作为搜索“hg命令行列表分支”时出现的唯一相关问题,我以为我会把它留在这里。 When you run the following - 当你运行以下 -

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

it outputs; 它输出;

branch:      branch1
branch:      branch2
branch:      branch3
branch:      branch4
branch:      branch5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM