列出Mercurial中的远程分支

Rao*_*oul 29 mercurial branch

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

git branch -r
Run Code Online (Sandbox Code Playgroud)

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

hg branches -R `hg showconfig paths.default` --color false
Run Code Online (Sandbox Code Playgroud)

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

gva*_*kov 20

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]))
Run Code Online (Sandbox Code Playgroud)

上面的代码片段产生:

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
Run Code Online (Sandbox Code Playgroud)

  • 恩,那就对了.谢谢.我只是不确定它是什么语言. (2认同)

小智 18

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

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

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

BitBucket有自己的API,可以获取分支,查看他们的帮助,并像https://api.bitbucket.org/1.0/repositories/mirror/mercurial/branches/这样的URL进行查询.


Jes*_*ick 5

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

\n\n
from mercurial import hg, commands, cmdutil, node\ncmdtable = {}\ncommand = cmdutil.command(cmdtable)\n@command(\'rheads\', commands.remoteopts, \'hg rheads [SOURCE]\')\ndef rheads(ui, repo, source=\'default\', **opts):\n    """print (possibly remote) heads\n\n    Prints a series of lines consisting of hashes and branch names.\n    Specify a local or remote repository, defaulting to the configured remote.\n    """\n    other = hg.peer(ui or repo, opts, ui.expandpath(source))\n    for tag, heads in other.branchmap().iteritems():\n        for h in heads:\n            ui.write("%s %s\\n" % (node.short(h), tag))\n
Run Code Online (Sandbox Code Playgroud)\n\n

当配置~/.hgrc

\n\n
[extensions]\nrheads = \xe2\x80\xa6/rheads.py\n
Run Code Online (Sandbox Code Playgroud)\n\n

你可以像这样运行它:

\n\n
hg rheads\n
Run Code Online (Sandbox Code Playgroud)\n\n

我尝试使其成为可以在任何存储库外部调用的命令,只需指定 URL 作为参数,但无法使语法正常工作:

\n\n
[extensions]\nrheads = \xe2\x80\xa6/rheads.py\n
Run Code Online (Sandbox Code Playgroud)\n