go: Can't use modules on a branch other than master

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

go version go1.15.1 linux/amd64

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

Ubuntu 18.04 with amd64

This code works as long as I’m on the master branch:

main.go:

package main

import (
	datemodlocal "192.168.0.12/gitrepo/go-module-test-dateutil.git"
	stringmodlocal "192.168.0.12/gitrepo/go-module-test-stringutil.git"
	"fmt"
	"github.com/dwschulze/go-module-test-dateutilmod"
	"github.com/dwschulze/go-module-test-stringutilmod"
)

func main() {

	fmt.Println("github:  " + stringmod.ToUpperCase("test"))
	fmt.Println("github:  " + datemod.GetTime().String())
	fmt.Println("local:  " + stringmodlocal.ToUpperCase("test"))
	fmt.Println("local:  " + datemodlocal.GetTime().String())
}

go.mod:

module module-driver

require (
	192.168.0.12/gitrepo/go-module-test-dateutil.git v0.0.1
	192.168.0.12/gitrepo/go-module-test-stringutil.git v0.0.1
	github.com/dwschulze/go-module-test-dateutilmod v0.0.1
	github.com/dwschulze/go-module-test-stringutilmod v0.0.1
)

go 1.15

I need to use the branch dev2 for development. The docs don’t show what needs to be done to the import path or the require statement in go.mod. If I change the import statement to:

`datemodlocal "192.168.0.12/gitrepo/go-module-test-dateutil.git@dev2"`

I get:

$ go run main.go
package command-line-arguments
        imports 192.168.0.12/gitrepo/go-module-test-dateutil.git@dev2: can only use path@version syntax with go get

If I move the @dev2 to the require statement in go.mod

`192.168.0.12/gitrepo/go-module-test-dateutil.git@dev2 v0.0.1`

I get

$ go run main.go
go: 192.168.0.12/gitrepo/go-module-test-dateutil.git@dev2@v0.0.1: unrecognized import path "192.168.0.12/gitrepo/go-module-test-dateutil.git@dev2": https fetch: Get "https://192.168.0.12/gitrepo/go-module-test-dateutil.git@dev2?go-get=1": dial tcp 192.168.0.12:443: connect: connection refused

That error message says https which is strange since in my ~/.gitconfig I have

[url "dean@192.168.0.12:"] insteadOf = https://192.168.0.12/

Setting GOPRIVATE has no effect. If I put the @dev2 in both places I get the same error messages.

The docs seem to indicate that modules can be used on branches, but they don’t show how the import path or the require statement in go.mod need to be changed.

Go modules need to be able to be used on branches other than master.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 26 (10 by maintainers)

Most upvoted comments

The blog you pointed to doesn’t say anything about pushing your module to a private vcs, let alone what the code should look like in main.go and go.mod. I need code that works, not examples of go get ... or go mod download ....

I’ll ask again: Have you verified that this works in code? I think you have a serious bug here.

Please prove or disprove this with a simple main.go and go.mod that uses a branch other than master from a private repo.