List remote branches in Mercurial
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
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/
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"
maybe you are looking for hg incoming -B
This worked quite well for me. This shows the bookmarks.