【问题标题】:go get doesn't work with .gitconfig that references a custom gitconfiggo get 不适用于引用自定义 gitconfig 的 .gitconfig
【发布时间】:2020-12-18 10:41:53
【问题描述】:

我使用 git clone 克隆了一个存储库,该存储库依赖于另一个私有存储库。在当前 repo 中,我尝试 go get 那个依赖项 (go get -u ./...),它给我一个错误:

致命:无法读取“https://bitbucket.org”的用户名:终端 提示已禁用

信息

  • 我使用git clone git@my-name.bitbucket.org:company/repo.git 将repo 克隆到~/Desktop/BitBucket/Company 目录。
  • 我有GOPRIVATE="bitbucket.org/company/*"
  • 没有includeIf,一切正常。如果我用 company .gitconfig 替换 .gitconfig 它工作正常。但我需要管理多个帐户...
  • 命令git config --get user.name(在repo 内)返回My Name。所以go get有问题

我的 ma​​in .gitconfig 文件(在 $HOME 目录中):

[includeIf "gitdir/i:~/Desktop/BitBucket/Company/"]
        path = ~/.git/BitBucket/Company/.gitconfig

我的 .gitconfig 文件(用于公司回购 $HOME/.git/BitBucket/Company/.gitconfig):

[user]
        name = My Name
        email = my.name@company.com
[url "git@my-name.bitbucket.org:"]
        insteadOf = https://bitbucket.org/

我的 ssh 配置 文件($HOME/.ssh/config):

Host my-name.bitbucket.org
  Hostname bitbucket.org
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/keys/BitBucket/my_name/id_rsa

我的错误是什么?

我还发现了这篇文章:https://medium.com/easyread/today-i-learned-fix-go-get-private-repository-return-error-terminal-prompts-disabled-8c5549d89045。您可以查看第一条评论:

仅供参考,这在使用引用自定义的 .gitconfig 时不起作用 .gitconfig-自定义。它必须存在于 ~/.gitconfig ..... 那是 令人沮丧。

我尝试将 company .gitconfig 移动到主目录(+ 将其重命名为 .gitconfig-company)。没有任何效果。

【问题讨论】:

  • 您只想将您的专业帐户用于bitbucket.org/company/* 网址,对吗?您是否尝试仅重写 https://bitbucket.org/company/ urls ?与git@my-name.bitbucket.org:company/ ? (注意:我没有测试过,不确定这个 rewting 规则是否有效)
  • 测试您的设置的一种方法是:运行git clone https://bitbucket.org/company/repo,看看它是否提示输入密码。您可以打开选项以获得更详细的输出:git clone -v ..., GIT_TRACE=1 git clone ..., ...
  • @LeGEC 我试过用这种方式重写 url,但没有解决问题。

标签: git git-config go-get


【解决方案1】:

如果您使用go get 克隆存储库,请注意gitdir: 和gitdir/i: 模式与正在克隆的存储库不匹配。这是因为该模式匹配 .git 目录,而当您克隆时,尚未创建 .git 目录。

您可以尝试将这样的指令放入您的配置中:

[url "git@my-name.bitbucket.org:company/"]
        insteadOf = https://bitbucket.org/company/

如果您需要克隆其他(公共)存储库,则为 Bitbucket 设置非工作密钥。

【讨论】:

  • 感谢您的回复。我使用git clone 克隆存储库,并且在此存储库中我有一个依赖项,我尝试使用go get。我已经尝试过您的解决方案,但不幸的是我看到了同样的错误。
  • “模式与被克隆的存储库不匹配”似乎是一个很大的疏忽,因为克隆是使用个人/企业凭据很重要的一个很好的例子。
猜你喜欢
  • 2021-03-19
  • 2020-04-14
  • 2013-09-13
  • 2012-01-10
  • 2015-12-08
  • 1970-01-01
  • 2012-05-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多