go get doesn't work with .gitconfig that references a custom gitconfig

818 views Asked by At

I clone a repository with git clone which has a dependency from another private repo. Inside current repo I try to go get that dependency (go get -u ./...) and it throws me an error:

fatal: could not read Username for 'https://bitbucket.org': terminal prompts disabled

Info

  • I used git clone [email protected]:company/repo.git to clone the repo to ~/Desktop/BitBucket/Company directory.
  • I have GOPRIVATE="bitbucket.org/company/*"
  • Everything works without includeIf. If I replace .gitconfig with company .gitconfig it works fine. But I need to manage multiple accounts...
  • The command git config --get user.name (inside the repo) returns My Name. So there is a problem with go get

My main .gitconfig file (in $HOME directory):

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

My .gitconfig file (for company repo $HOME/.git/BitBucket/Company/.gitconfig):

[user]
        name = My Name
        email = [email protected]
[url "[email protected]:"]
        insteadOf = https://bitbucket.org/

My ssh config file ($HOME/.ssh/config):

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

What is my mistake?

I also found this article: https://medium.com/easyread/today-i-learned-fix-go-get-private-repository-return-error-terminal-prompts-disabled-8c5549d89045. You can check the first comment:

FYI, this dont work when using .gitconfig that references a custom .gitconfig-custom. It has to live in ~/.gitconfig….. man that was frustrating.

I tried to move company .gitconfig to home directory (+ renamed it .gitconfig-company). Nothing works.

1

There are 1 answers

2
bk2204 On

If you're using go get to clone a repository, be aware that the gitdir: and gitdir/i: patterns don't match a repository that's being cloned. That's because the pattern matches directories that are .git directories, and when you're cloning, that .git directory hasn't been created yet.

You could try placing a directive like this into your config instead:

[url "[email protected]:company/"]
        insteadOf = https://bitbucket.org/company/

and then setting up a non-work key for Bitbucket if you need to clone other (public) repositories.