-2

Using:

% go version
go version go1.16.4 darwin/amd64

I've got a private bitbucket.org repository with a url like:

git@bitbucket.org:chmorgan/some_repo.git

Per the bitbucket url format you would do 'git clone git@bitbucket.org:chmorgan/some_repo.git' to clone it and cloning works fine.

When I try to make a new module I get:

go mod init git@bitbucket.org:chmorgan/some_repo.git
go: invalid module path "git@bitbucket.org:chmorgan/some_repo.git": contains disallowed path separator character ':'

Note that I've already configured git in ~/.gitconfig:

[url "git@bitbucket.org:"]
        insteadOf = https://bitbucket.org/

This used to work with earlier golfing versions, I think it worked with golang 1.12 or 1.13. Anyone know what's up?

Chris Morgan
  • 1,277
  • 1
  • 13
  • 33
  • 4
    `go mod init` should be given the import path that others would use to import your package e.g. `myco.com/some/path/packagename` – colm.anseo Jun 01 '21 at 00:40
  • 2
    The [go mod name documentation says](https://golang.org/ref/mod#go-mod-file-ident) *Each path element is a non-empty string made of up ASCII letters, ASCII digits, and limited ASCII punctuation (-, ., _, and ~).* The [remote import path documentation](https://golang.org/cmd/go/#hdr-Remote_import_paths) says that bitbucket has the special syntax `bitbucket.org/user/project` or `bitbucket.org/user/project/sub/directory`. – Charlie Tumahai Jun 01 '21 at 00:40
  • 1
    What made you think that the argument to `git clone` would make a good Go module name? Go packages (and modules) are often distributed via git (among other VCSs) but git and go still are different. – Volker Jun 01 '21 at 05:01
  • 1
    I'm not sure what you were doing before, but this never worked in any version because `git@bitbucket.org:chmorgan/some_repo.git` is not a valid import path. Perhaps this is new validation, but that only mens you weren't correctly using modules before or there would have been other errors. – JimB Jun 01 '21 at 13:43
  • @JimB yeah this definitely worked a handful of months ago. I've been using that pattern across a half dozen modules or more over several months. Not saying its right of course just that its crazy that it just happened to work and now I agree that it appears validation is new. – Chris Morgan Jun 02 '21 at 00:37
  • @Volker agreed, just doing the best I can with the docs I'm aware of. – Chris Morgan Jun 02 '21 at 00:42

1 Answers1

1

The argument to go mod init is the “module path”, which is used as a prefix of the package import path for every package within the module. As a result, the argument to go mod init must be valid as a package import path.

(See https://golang.org/doc/code for more detail.)

The package import path we would normally use for a repo cloned from git@bitbucket.org:chmorgan/some_repo.git is bitbucket.org/chmorgan/some_repo.

bcmills
  • 4,391
  • 24
  • 34