1

I'm now using private repository for my collaboration projects.
I set up my personal GitLab like gitlab.xity.dev/QuietJoon/testgoget,
and I tried to provide it for my team.
(the repository https://gitlab.xity.dev/QuietJoon/testgoget is public for this question)

Problems

However, when I tried go get -v gitlab.xity.dev/QuietJoon/testgoget,
it says

get "gitlab.xity.dev/QuietJoon/testgoget": found meta tag get.metaImport{Prefix:"gitlab.xity.dev/QuietJoon/testgoget", VCS:"git", RepoRoot:"http://gitlab.xity.dev/QuietJoon/testgoget.git"} at //gitlab.xity.dev/QuietJoon/testgoget?go-get=1
package gitlab.xity.dev/QuietJoon/testgoget: cannot download, http://gitlab.xity.dev/QuietJoon/testgoget.git uses insecure protocol

Also, I tried go get -v gitlab.xity.dev/QuietJoon/testgoget.git with explicit .git suffix And I get

# cd .; git ls-remote https://gitlab.xity.dev/QuietJoon/testgoget
fatal: repository 'https://gitlab.xity.dev/QuietJoon/testgoget/' not found
# cd .; git ls-remote git+ssh://gitlab.xity.dev/QuietJoon/testgoget

you can see go get tries https first,
but go get strip suffix of .git therefore it says the repository not found, and advance to next git+ssh protocol. I could get git clone gitlab.xity.dev/QuietJoon/testgoget.git without any authentication process,

git ls-remote https://gitlab.xity.dev/QuietJoon/testgoget.git
c238e4b9818eabe6309a2c5cf274808ec39bf7d5        HEAD
c238e4b9818eabe6309a2c5cf274808ec39bf7d5        refs/heads/master

My Incomplete Solution

After I set global git redirection configuration (like git config --global url."https://gitlab.xity.dev".insteadOf "http://gitlab.xity.dev")
I could get the package with -insecure flag

$ go get -v -insecure gitlab.xity.dev/QuietJoon/testgoget
get "gitlab.xity.dev/QuietJoon/testgoget": found meta tag get.metaImport{Prefix:"gitlab.xity.dev/QuietJoon/testgoget", VCS:"git", RepoRoot:"http://gitlab.xity.dev/QuietJoon/testgoget.git"} at //gitlab.xity.dev/QuietJoon/testgoget?go-get=1
gitlab.xity.dev/QuietJoon/testgoget (download)
gitlab.xity.dev/QuietJoon/testgoget

When I does not provide http://gitlab.xity.dev/QuietJoon/testgoget like

$ curl -I http://gitlab.xity.dev/QuietJoon/testgoget
HTTP/1.1 404 Not Found
Server: nginx/1.16.0
Date: Tue, 09 Jun 2020 06:16:25 GMT
Content-Type: text/html
Content-Length: 153
Connection: keep-alive
$ curl -I http://gitlab.xity.dev/QuietJoon/testgoget.git
HTTP/1.1 404 Not Found
Server: nginx/1.16.0
Date: Tue, 09 Jun 2020 06:17:30 GMT
Content-Type: text/html
Content-Length: 153
Connection: keep-alive
$ git clone http://gitlab.xity.dev/QuietJoon/testgoget
Cloning into 'testgoget'...
fatal: repository 'http://gitlab.xity.dev/QuietJoon/testgoget/' not found
$ git clone http://gitlab.xity.dev/QuietJoon/testgoget.git
Cloning into 'testgoget'...
fatal: repository 'http://gitlab.xity.dev/QuietJoon/testgoget.git/' not found

Yes, this may work because go get uses git clone, and go get adds .git suffix to given url when the protocol is insecure.

Other solutions

I could solve this by using git clone it at %GOPATH%/src manually.

However, this is not my personal project, but collaborative project.
Therefore, I can't tell everyone to do it above. (because me and everyone else are Golang beginners)
I want to using this only with regular Golang manner * only with import "gitlab.xity.dev/XXX/YYY". (import "gitlab.xity.dev/XXX/YYY.git" also seems to be bad manner for Golang), * not manual git redirection configuration and go get -insecure by oneself

Questions

1. How can I help go get to access https instead of http?

I've surveyed many helps like Q&A like this, and add global git configuration like

[url "https://gitlab.xity.dev"]
        insteadOf = http://gitlab.xity.dev

but this does not help go get properly without -insecure flag.
I understand that go get never realize that there is such git configuration.

Then, How can I help go get to prefer trying https instead of http?

2. Why go get prefer to access http instead of https even it says it does not like to access insecure protocol?

Even go get complains about insecure protocol, why it does not try to access https at first instead of http?
I'm not sure that this is bug of go get or not.

3. Why go get strip the suffix .git even I give it explicitly?

When I give .git suffix explicitly, go get drops given suffix and says that it couldn't found repository properly.

$ go get -v gitlab.xity.dev/QuietJoon/testgoget.git
# cd .; git ls-remote https://gitlab.xity.dev/QuietJoon/testgoget
fatal: repository 'https://gitlab.xity.dev/QuietJoon/testgoget/' not found

But you can see that go get does not need explicit .git when it tries insecure protocol like

$ go get -v gitlab.xity.dev/QuietJoon/testgoget
get "gitlab.xity.dev/QuietJoon/testgoget": found meta tag get.metaImport{Prefix:"gitlab.xity.dev/QuietJoon/testgoget", VCS:"git", RepoRoot:"http://gitlab.xity.dev/QuietJoon/testgoget.git"} at //gitlab.xity.dev/QuietJoon/testgoget?go-get=1
package gitlab.xity.dev/QuietJoon/testgoget: cannot download, http://gitlab.xity.dev/QuietJoon/testgoget.git uses insecure protocol

What makes the difference?

Conditions & Environment

I tried this with * go version go1.14.4 windows/amd64 * go version go1.14.3 darwin/amd64 * go version go1.12.7 linux/amd64 * go version go1.14.4 linux/amd64

I've set GOPRIVATE for gitlab.xity.dev like

go env
...
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=gitlab.xity.dev
set GONOSUMDB=gitlab.xity.dev
set GOOS=windows
set GOPATH=t:\go
set GOPRIVATE=gitlab.xity.dev
set GOPROXY=https://proxy.golang.org,direct
set GOSUMDB=sum.golang.org
...

I think that GOPRIVATE is not used yet in this situation.

QuietJoon
  • 490
  • 5
  • 16
  • 1
    It uses http because https://gitlab.xity.dev/QuietJoon/testgoget?go-get=1 tells it to (note the query parameter). Our private Gitlab instance doesn't do this, so this is probably a Gitlab configuration issue. – Peter Jun 09 '20 at 10:32
  • @Peter Thanks for your accurate answer. I had some problem with my Gitlab configuration, but I didn't realized that the configuration issue could affect to this problem. – QuietJoon Jun 10 '20 at 01:29

0 Answers0