Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go mod: something goes wrong with private git projects when imports with the suffix .git #34812

Closed
anotherGoogleFan opened this issue Oct 10, 2019 · 5 comments

Comments

@anotherGoogleFan
Copy link

anotherGoogleFan commented Oct 10, 2019

What version of Go are you using (go version)?

$ go version
go version go1.13.1 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\huangtao\AppData\Local\go-build
set GOENV=C:\Users\huangtao\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=*.example.net
set GONOSUMDB=*.example.net
set GOOS=windows
set GOPATH=E:\GoProjects
set GOPRIVATE=*.example.net
set GOPROXY=direct,https://goproxy.cn,https://goproxy.io,https://proxy.golang.org
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\huangtao\AppData\Local\Temp\go-build102197674=/tmp/go-build -gno-record-gcc-switches

What did you do?

There're 2 private git projects, A and B. Both use go mod.
Project A's go mod, for example, like this:

module git.example.net/go/a

go 1.13

xxxxxxx(replace and requires here)

In project A, I import project B.

import "git.example.net/go/b.git/xxx"

Project B's go mod, for example, like this:

module git.example.net/go/b

go 1.13

xxxxxxx(replace and requires here)

And I build the project A.

What did you expect to see?

build pass

What did you see instead?

go: git.example.net/go/a/repository imports
        git.example.net/go/b.git/xxx: git.example.net/go/b.git@v0.0.0-20191009034226-6b9a95059d66: parsing go.mod:
        module declares its path as: git.example.net/go/b
                but was required as: git.example.net/go/b.git
@bcmills
Copy link
Contributor

bcmills commented Oct 10, 2019

The error message here is telling you exactly what is wrong: B's go.mod file declares its import path to be git.example.net/go/b, but you are instead importing it as git.example.net/go/b.git.

The path in the module directive must match the path used in import statements. The .git suffix is part of the import path, not just an annotation.

@bcmills bcmills closed this as completed Oct 10, 2019
@anotherGoogleFan
Copy link
Author

@bcmills Thanks for response.
But may I ask what should I do in this situation if I need to use the project git.example.net/go/b without changing it? If I import without .git suffix, I can only get another error:

git.example.net/a/repository imports
        git.example.net/go/b: cannot find module providing package git.example.net/go/b

@bcmills
Copy link
Contributor

bcmills commented Oct 11, 2019

what should I do in this situation if I need to use the project git.example.net/go/b without changing it?

Your options include:

  1. Set up an HTTPS server on git.example.net serving <meta> tags as described in https://golang.org/cmd/go/#hdr-Remote_import_paths.

    • This is the most robust solution, but requires that you (or someone) configure a server on that host.
    • This approach should make import "git.example.net/go/b/xxx" work without modifying the code.
  2. Change B's go.mod file from

    module git.example.net/go/b
    

    to

    module git.example.net/go/b.git
    

    and update theimport statements within A and B accordingly.

    • This should make import "git.example.net/go/b.git/xxx" work without modifying the server.
  3. Add a replace directive to A's go.mod file:

    replace git.example.net/go/b v0.0.0-20191009034226-6b9a95059d66 => git.example.net/go/b.git v0.0.0-20191009034226-6b9a95059d66
    
    • This would not fix any downstream consumers of A, who would need to copy that replacement into their own go.mod file.

@anotherGoogleFan
Copy link
Author

@bcmills
Thanks for response.
I tried the 3rd option you supported, and when I add the replace

replace git.example.net/go/b.git  => git.example.net/go/b latest

I got another error

git.example.net/go/a/repository imports
        git.example.net/go/b/xxx: unrecognized import path "git.example.net/go/b" (https fetch: Get https://git.example.net/go/b?go-get=1: x509: certificate signed by unknown authority)

But when I tried

go get -u -v git.example.net/go/b

and it goes well. It seems something strange happened here.

@bcmills
Copy link
Contributor

bcmills commented Oct 11, 2019

when I add the replace

You'll want to replace b with b.git, not the other way around.

I don't know why go get -u -v git.example.net/go/b would behave differently.

@golang golang locked and limited conversation to collaborators Oct 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants