0

In have a git repo in bitbucket.org

reponame/
    .git/
    integration1/
    integration2/
    integration-common/
    └── util
        ├── go.mod
        └── readascii.go

The module directory is a subdirectory of the git repository. The repository is tagged with v0.0.1.

Here's the go.mod

module bitbucket.org/orgname/reponame/integration-common/util
go 1.14

When I do go get for this module I get the following error

go get bitbucket.org/orgname/reponame/integration-common/util@v0.0.1

go: downloading bitbucket.org/orgname/reponame v0.0.1
go get bitbucket.org/orgname/reponame/integration-common/util@v0.0.1: module bitbucket.org/orgname/reponame@v0.0.1 found, but does not contain package bitbucket.org/orgname/reponame/integration-common/util

I can see the integration-common/util/ directory in bitbucket.org under the tag v0.0.1 if I look with the web browser. The go.mod has the contents shown above.

What is even more odd is that go get does manage to download the other directories in the repository (integration1/ and integration2/). For some reason it thinks v0.0.1 doesn't contain the integration-common/ directory, even though bitbucket shows it there for that tag.

I download with ssh, not https, because https reqires 2fa on our bitbucket repo:

~/.gitconfig:

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

I know bitbucket is weird when it comes to using go get. Is there something I missed, or is this a bug with go get and bitbucket?

Dean Schulze
  • 9,633
  • 24
  • 100
  • 165

1 Answers1

0

The tag v0.0.1 applies to the module at the root of the repo (bitbucket.org/orgname/reponame).

The go.mod file in the integration-common/util subdirectory causes that subdirectory to become its own module, with its own space of versions and its own set of version tags, which would need to be of the form integration-common/util/v0.0.1 (see https://golang.org/doc/modules/managing-source#tmp_4).

That is:

  • The v0.0.1 tag applies to module bitbucket.org/orgname/reponame, which does not contain the package because it is underneath a directory containing another go.mod file.
  • The module bitbucket.org/orgname/reponame/integration-common/util exists and contains that package, but it does not have a version v0.0.1 because the version tags for the subdirectory-module require an explicit prefix corresponding to that subdirectory.

In general, it is simplest to have only one go.mod file — at the repo root — and to avoid nesting additional modules in subdirectories.

bcmills
  • 4,391
  • 24
  • 34