【问题标题】:Git doesn't use credentials from git-credentials-store fileGit 不使用来自 git-credentials-store 文件的凭据
【发布时间】:2020-10-19 17:11:04
【问题描述】:

我正在尝试在 CI 中编译一些 Rust 代码,这依赖于另一个私有 git 存储库。 由于它在 CI 中,我无法手动输入凭据,所以我正在尝试使用 git-credentials-store。这是我在尝试设置 git-credentials-store 时所做的:

echo 'https://username:password@placeholder.com/repo.git' > git-credentials
git config credentials.helper 'store --file git-credentials'`

要构建项目,它必须从该私有 git 存储库中获取。 当它尝试构建时,它失败了,说这是它尝试的命令:

git fetch --tags --force --update-head-ok 'https://placeholder.com/git/repo.git' 'refs/heads/*:refs/heads/*'

这是错误信息:

fatal: could not read Username for 'https://placeholder.com': No such device or address

这是否表明它要求在标准输入中输入用户名?我希望该命令会使用 git-credentials 文件中的用户名和密码。

【问题讨论】:

  • 您的示例在一处使用placeholder.eu,在其他地方使用placeholder.com。我认为这是一个疏忽。
  • 是的,谢谢,已更正

标签: git continuous-integration credentials rust-cargo


【解决方案1】:

一般来说,凭证文件中的 URL 不应包含路径组件。 git credential-store 手册页给出了这种格式:

https://user:pass@example.com

除非设置了credential.useHTTPPath,否则Git 在查找凭据时通常不会考虑路径组件。如果您设置了路径组件,那么在这种情况下,您可能不会匹配 Git 请求的内容,这是相关域的通用凭据集。

【讨论】:

  • 感谢您的信息。不幸的是,我用这种语法得到了同样的错误。即echo 'https://username:password@placeholder.com' > git-credentials
  • 那么您的密码包含必须编码的特殊字符,或者您的凭据不正确。您可能还想使用GIT_TERMINAL_PROMPT0 来避免终端提示并获得更好的错误消息。
  • 谢谢,我好像是这样的。它必须以什么方式编码?
  • 密码必须是 URI 编码的。一般来说,如果它包含一个不是字母、数字、-_ 的字符,最好将这些字节值写为%,后跟两个表示其 ASCII 的十六进制字符(或UTF-8) 字节值。例如,= 将是 %3D@ 将是 %40
猜你喜欢
  • 2014-09-22
  • 2017-07-21
  • 2018-06-06
  • 2016-02-07
  • 1970-01-01
  • 2019-02-12
  • 2019-09-22
  • 1970-01-01
  • 2016-07-18
相关资源
最近更新 更多