`git ls-remote` in GitPython

蹲街弑〆低调 提交于 2019-12-01 08:32:54

GitPython does not support ls-remote, but you can use git.cmd to run any git command and then parse the output manually:

import git
def lsremote(url):
    remote_refs = {}
    g = git.cmd.Git()
    for ref in g.ls_remote(url).split('\n'):
        hash_ref_list = ref.split('\t')
        remote_refs[hash_ref_list[1]] = hash_ref_list[0]
    return remote_refs

Example:

In [3]: refs = lsremote('https://github.com/gitpython-developers/GitPython.git')
In [4]: refs['HEAD']
Out[4]: u'9f4af7c6db25c5bbec7fdc8dfc0ea6803350d94c'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!