Go Get似乎忽略了gitconfig

6ovsh4lw  于 2022-09-21  发布在  Go
关注(0)|答案(1)|浏览(282)

希望能得到一点帮助。我有一个托管在远程GitLab示例上的私有repo,我应该能够访问该示例。但无论我怎么尝试,go get似乎都在尝试使用HTTPS而不是SSH。我可以毫无问题地执行git clonegit fetchetc。但我一使用go get,它就失败了。

我做的第一件事是添加以下代码:git config --global --add url."git@git.mydomain.io:".insteadOf "https://git.mydomain.io/"

然后,我cd到我的项目目录并运行Go Get,它尝试通过HTTPS进行身份验证失败,并显示“FATAL:Can‘t Read Username for’https://git.my.domain‘:Terminal Prompt Disable”(致命:无法读取禁用的HTTPS终端提示的用户名):

PS C:UsersUsergosrcgit.my.domainpswkcollector> go get            
go: downloading git.my.domain/ps/mqtt v0.0.0-20220903204713-6f195510d46e
go: git.my.domain/ps/mqtt@v0.0.0-20220903204713-6f195510d46e: verifying module: git.my.domain/ps/mqtt@v0.0.0-20220903204713-6f195510d46e: reading https://sum.golang.orglookup/git.my.domain/ps/mqtt@v0.0.0-20220903204713-6f195510d46e: 404 Not Found
        server response:
        not found: git.my.domain/ps/mqtt@v0.0.0-20220903204713-6f195510d46e: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/v
cs/3a728c5d3b6137ea441372540f3e7bc1390c001346a70d5b7df3eda6d5e7316d: exit status 128:
                fatal: could not read Username for 'https://git.my.domain': terminal prompts disabled
        Confirm the import path was entered correctly.
        If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.
go: git.my.domain/ps/mqtt@v0.0.0-20220903204713-6f195510d46e: verifying module: git.my.domain/ps/mqtt@v0.0.0-20220903204713-6f195510d46e: reading https://sum.golang.org/lookup/git.my.domain/ps/mqtt@v0.0.0-20220903204713-6f195510d46e: 404 Not Found
        server response:
        not found: git.my.domain/ps/mqtt@v0.0.0-20220903204713-6f195510d46e: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/v
cs/3a728c5d3b6137ea441372540f3e7bc1390c001346a70d5b7df3eda6d5e7316d: exit status 128:
                fatal: could not read Username for 'https://git.my.domain': terminal prompts disabled
        Confirm the import path was entered correctly.
        If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.
go: module git.my.domain/ps/wk/collector/service: git ls-remote -q origin in C:UsersUsergopkgmodcachevcs7d02e96755cff57eaec3323ab70c24a12ab19
eac805790ed1220d62b15affcf8: exit status 128:
        remote:
        remote: ========================================================================
        remote:
        remote: The project you were looking for could not be found.
        remote:
        remote: ========================================================================
        remote:
        fatal: Could not read from remote repository.

        Please make sure you have the correct access rights
        and the repository exists.
go: module git.my.domain/ps/wk/collector/service/service: git ls-remote -q origin in C:UsersUsergopkgmodcachevcs7d02e96755cff57eaec3323ab70c2
4a12ab19eac805790ed1220d62b15affcf8: exit status 128:
        remote:
        remote: ========================================================================
        remote:
        remote: The project you were looking for could not be found.
        remote:
        remote: ========================================================================
        remote:
        fatal: Could not read from remote repository.

        Please make sure you have the correct access rights
        and the repository exists.

我简直要疯了。我尝试了让go get使用SSH的所有组合:

git config --global --add url."git@git.mydomain.io/".insteadOf "https://git.mydomain.io/"

git config --global --add url."git@git.mydomain.io".insteadOf "https://git.mydomain.io"

git config --global --add url."ssh://git@git.mydomain.io:".insteadOf "https://git.mydomain.io/"
...

有什么特别的事情需要我去做吗?我只是不明白为什么go get使用HTTPS,而git命令似乎正确地使用SSH。

=

编辑:好的,更多的到期让我意识到这是有效的:

[url "ssh://git@git.mydomain.io"] insteadOf = https://git.mydomain.io/

因为我收到了一个新的错误:

ssh: Could not resolve hostname git.mydomain.iops: Name or service not known
        fatal: Could not read from remote repository.

但是,一旦我添加了尾随斜杠来修复它,我就会返回到HTTPS错误。HTTPS上有没有什么事情发生在ssh之前?

k5ifujac

k5ifujac1#

尝试直接修改您的~/.gitconfig文件,确保您的私有repo条目如下所示

[url "git@gitlab.com:"] insteadOf = https://gitlab.com

也许是跟语法有关的东西。

还要将URL(不包括https://)添加到您的$GONOPROXY中。

相关问题