Dulwich 远程回购认证

Dulwich Remote Repo Authentication

是否有任何通过 HTTPS 访问和获取远程存储库的好示例?我有一个 Git 存储库,我可以使用我的用户名和密码从命令行克隆它,但我希望能够使用 Dulwich 执行此操作,并且在创建 HTTPS 客户端时只提供我的用户名和密码。

另一个要求是使用 MemoryRepo 选项而不是写入文件系统来完成。

Dulwich 0.16.0 及更高版本在 URL 中支持 usernames/paswords。

在旧版本中,您可以通过指定自定义 HTTP 处理程序来执行此操作:

    import urllib2

    password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()

    # Add the username and password.
    password_mgr.add_password(realm, top_level_url, username, password)

    handler = urllib2.HTTPBasicAuthHandler(password_mgr)

    opener = urllib2.build_opener([handler])

    client, path = get_transport_and_path(remote_location)
    client.opener = opener
    remote_refs = client.fetch(path, target_repo)