Skip to content

cmd/go: can't parse go.mod with branch or commit hash specifier #42411

Closed
@dwschulze

Description

@dwschulze

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

$ go version
1.15

Does this issue reproduce with the latest release?

Yes

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

GOHOSTARCH="amd64"
GOHOSTOS="linux"
Ubuntu 20.04

go env Output
$ go env

What did you do?

Note that I'm using a private server for my git repo. It was created with git init --bare. There is no web server, no github, no gitlab. I have ssh access with my public key and have modified my ~/.gitconfig appropriately. I can access modules as long as I specify a SemVer number, but if I want code from a branch other than master then go doesn't know how to parse the specified for the branch name or the commit hash.

I want to use a branch of a module In go.mod if I specify the branch name I get an error:

require (
	192.168.0.12/gitrepo/go-module-test-dateutil.git @dev2
...
)
 go run main.go
go: errors parsing go.mod:
/home/dean/src/golang/examples/package-module-test/go-module-package-test-drivers/module-driver/go.mod:4:2: require 192.168.0.12/gitrepo/go-module-test-dateutil.git: version "@dev2" invalid: unknown revision @dev2

If I take out the space before the @ I get

require (
	192.168.0.12/gitrepo/go-module-test-dateutil.git@dev2
...
)
$ go run main.go
go: errors parsing go.mod:
/home/dean/src/golang/examples/package-module-test/go-module-package-test-drivers/module-driver/go.mod:4:2: usage: require module/path v1.2.3

I get the same errors if I use the commit hash of the last commit on the branch instead of the branch name.

What did you expect to see?

Should recognize that I'm specifying a branch name or commit hash

What did you see instead?

Parse errors on go.mod

If this is not the correct way to specify a branch or commit what is the correct syntax?

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.modules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions