List remote branches in Mercurial

孤者浪人 提交于 2019-12-05 08:44:08

问题


Is there a way to list remote branches in Mercurial like there in Git?

git branch -r

I want to list the branches on a remote machine (e.g. Bitbucket), so using:

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

fails with abort: repository not local


回答1:


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.

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

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/




回答2:


The mercurial API allows it:

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



回答3:


To expand on @gvalkov’s answer, you can make this a real extension by writing a file 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

[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:

commands.norepo += " rheads"



回答4:


maybe you are looking for hg incoming -B This worked quite well for me. This shows the bookmarks.




回答5:


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. 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


来源:https://stackoverflow.com/questions/4296636/list-remote-branches-in-mercurial

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!