Skip to content

cmd/install: Failure to fetch from git repo using semver tag when module is in subdirectory #49622

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

Closed
wkaluza opened this issue Nov 16, 2021 · 1 comment

Comments

@wkaluza
Copy link

wkaluza commented Nov 16, 2021

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

$ go version
go version go1.17.2 linux/amd64

Does this issue reproduce with the latest release?

Yes ( go1.17beta1-2430-g6c36c332fe )

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/wkaluza/.cache/go-build"
GOENV="/home/wkaluza/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/wkaluza/go/pkg/mod"
GONOPROXY="github.com/wkaluza/*"
GONOSUMDB="github.com/wkaluza/*"
GOOS="linux"
GOPATH="/home/wkaluza/go"
GOPRIVATE="github.com/wkaluza/*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.2"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1159245153=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.17.2 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.17.2
uname -sr: Linux 5.11.0-40-generic
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.3 LTS
Release:	20.04
Codename:	focal
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Ubuntu GLIBC 2.31-0ubuntu9.2) stable release version 2.31.
lldb --version: lldb version 10.0.0
gdb --version: GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2

What did you do?

I attempted to run go install of a package whose module is located in a subdirectory of the git repo.

I created two specimen repositories to illustrate the problem:

Both repositories contain a default branch main and a semver tag v0.0.1.

The command go install github.com/wkaluza/go_issue_root/cmd/[email protected] works fine and places the executable wise_app_root in $GOPATH/bin. Attempting to run github.com/wkaluza/go_issue_subdir/subdir/cmd/[email protected] fails.

Curiously, installing a non-semver tag does not show this behaviour and works for both repos. Likewise, installations using "latest", a branch name or the commit digest (SHA-1) are not affected by the project structure. The following script can be used to replicate the failure:

#!/usr/bin/env bash

set -euo pipefail

function clean_test_env {
  rm -f $GOPATH/bin/wise_app_root
  rm -f $GOPATH/bin/wise_app_subdir

  go clean -cache -modcache -testcache
}

function run_tests {
  local revision1="$1"
  local revision2="${2:-$revision1}"

  local URL_ROOT="github.com/wkaluza/go_issue_root/cmd/wise_app_root"
  local URL_SUBDIR="github.com/wkaluza/go_issue_subdir/subdir/cmd/wise_app_subdir"

  echo ""
  echo "Install app from repo root directory (revision: $revision1)"
  echo "go install $URL_ROOT@$revision1"
  echo ""

  clean_test_env
  go install "$URL_ROOT@$revision1"
  $GOPATH/bin/wise_app_root

  echo ""
  echo "Install app from repo subdirectory (revision: $revision2)"
  echo "go install $URL_SUBDIR@$revision2"
  echo ""

  clean_test_env
  go install "$URL_SUBDIR@$revision2"
  $GOPATH/bin/wise_app_subdir
}

function main {

  ### All of these work fine:
  # run_tests latest
  # run_tests main
  # run_tests \
  #   3f2f5eb664072317111c17ec80aca61e04f2d943 \
  #   60038133a59943847cd9a830f218ca3491943c5b
  # run_tests branch_not_main
  # run_tests tag_not_semver

  ### A semver tag fails for the subdir case
  run_tests v0.0.1

  echo Success
}

# Entry point
main

What did you expect to see?

I expected go install to work with semver-tagged revisions irrespective of project structure and install the executable wise_app_subdir in $GOPATH/bin.

What did you see instead?

$ go install github.com/wkaluza/go_issue_subdir/subdir/cmd/[email protected]

go: downloading github.com/wkaluza/go_issue_subdir v0.0.1
go install: github.com/wkaluza/go_issue_subdir/subdir/cmd/[email protected]: module github.com/wkaluza/[email protected] found, but does not contain package github.com/wkaluza/go_issue_subdir/subdir/cmd/wise_app_subdir
@seankhliao
Copy link
Member

This is working as intended, see https://golang.org/ref/mod#vcs-version

If a module is defined in a subdirectory within the repository, that is, the module subdirectory portion of the module path is not empty, then each tag name must be prefixed with the module subdirectory, followed by a slash.

@golang golang locked and limited conversation to collaborators Nov 16, 2022
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