List remote branches in Mercurial
Solution 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/
Solution 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
Solution 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"
Solution 4
maybe you are looking for hg incoming -B
This worked quite well for me. This shows the bookmarks.
Raoul
I am a software engineer working with nodejs, JavaScript, Ruby and C# / ASP.Net. I take a keen interest in all aspects of software development particulary design patterns, agile development techniques. I have a distinctly anti-enterprise / bloat attitude to development and favour the more austere unix attitude to design principles.
Updated on June 28, 2020Comments
-
Raoul about 4 years
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