简体   繁体   English

dulwich - 从远程 repo 身份验证克隆

[英]dulwich - clone from remote repo authentication

I couldn't find any resource on this topic.我找不到有关此主题的任何资源。 I need to clone from a private repository by providing the username and the password.我需要通过提供用户名和密码从私有存储库中克隆。 However when they are provided as keyword arguments to 'dulwich.get-client-from-path()' an error occurs saying 'unknown argument "username"'.但是,当它们作为关键字 arguments 提供给“dulwich.get-client-from-path()”时,会出现“未知参数“用户名””的错误。

This seems to be a simple thing to do, however I can't find the proper method.这似乎是一件简单的事情,但是我找不到合适的方法。

试试这个片段:

porcelain.clone("https://user:password@your_git_repo.git")

This works as well:这也有效:

porcelain.clone("https://example.com/repo.git", username="user", password="password")

I quickly checked to see if the credentials are stored locally:我迅速检查了凭据是否存储在本地:

  • When using the username and password syntax from this answer, neither username nor password seem to be stored anywhere.使用此答案中的usernamepassword语法时,用户名和密码似乎都没有存储在任何地方。
  • When using the method from harvin's answer , the username is stored locally (you can check this on the command line with git remote -v ).使用harvin's answer中的方法时,用户名存储在本地(您可以在命令行上使用git remote -v进行检查)。 The password does not seem to be stored.密码似乎没有被存储。
    • This is different from the behavior of executing git clone https://user:password@example.com/repo.git on the command line, which stores both username and password.这与在命令行上执行git clone https://user:password@example.com/repo.git的行为不同,后者存储了用户名和密码。

How I found out我是怎么发现的

  1. The Dulwich porcelain documentation does not mention the possibility to clone with authentication at all.德威porcelain文档根本没有提到通过身份验证进行克隆的可能性。
  2. The source code for porcelain.clone does take **kwargs . Ceramic.clone 的porcelain.clone代码确实需要**kwargs
    • They are passed to client.get_transport_and_path .它们被传递给client.get_transport_and_path
    • This passes them to client.get_transport_and_path_from_url .这会将它们传递给client.get_transport_and_path_from_url
    • This passes them to HttpGitClient.from_parsedurl .这会将它们传递给HttpGitClient.from_parsedurl If username and password are present in the URL, they are extracted and stored into the kwargs dictionary (this probably is what makes harvin's answer work).如果 URL 中存在用户名和密码,它们将被提取并存储到kwargs字典中(这可能是 harvin 的答案起作用的原因)。
    • The kwargs dictionary is then passed on again somewhere.然后kwargs字典在某个地方再次传递。 I did not check that location out, because the fact that the code knows about a username and a password key in kwargs was enough evidence for me to just try the snippet I posted above, and it worked.我没有检查那个位置,因为代码知道kwargs中的usernamepassword密钥这一事实足以证明我可以尝试我在上面发布的代码段,并且它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM