Skip to content
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

Document how using a specific branch of a repo with go modules interacts with multi-module repos #30851

Closed
grantwwu opened this issue Mar 14, 2019 · 17 comments

Comments

@grantwwu
Copy link

grantwwu commented Mar 14, 2019

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

$ go version
go version go1.12 darwin/amd64

Does this issue reproduce with the latest release?

I believe 1.12 is the latest release

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/grant.wu/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/grant.wu/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/rm/k4qc6x917tdf1ms2f8t2jw1h0000gp/T/go-build926919438=/tmp/go-build -gno-record-gcc-switches -fno-common"

Description

(I'm not following the bug template here because this is more of a documentation issue)

It's not clear how using a multi-module (or single-module-with-go.mod-not-at-vcs-root) repo interacts with trying to get a particular branch.

Noting that the wiki says:

To upgrade or downgrade to a more specific version, 'go get' allows version selection to be overridden by adding an @Version suffix or "module query" to the package argument, such as go get foo@v1.6.2, go get foo@e3702bed2, or go get foo@'<v1.6.2'.

(https://github.com/golang/go/wiki/Modules#how-to-upgrade-and-downgrade-dependencies)

it's not immediately obvious to me how this interacts with multi-module repos, which require prepending the path. i.e. if I do go get foo@bar/baz/quux, does Go think that I'm trying to get a module rooted at /bar/baz, using the branch quux, or the module rooted at /bar on branch baz/quux?

@bcmills
Copy link
Contributor

bcmills commented Mar 14, 2019

go get foo@bar/baz/quux would mean “get module foo at version or branch bar/baz/quux”. (As a general rule, you should never have slashes in the version part of your go get command.)

@bcmills
Copy link
Contributor

bcmills commented Mar 14, 2019

go get foo/bar/baz@quux, however, would mean “get module foo/bar/baz at version or branch quux”.

@bcmills
Copy link
Contributor

bcmills commented Mar 14, 2019

Folding this into #30850.

@bcmills bcmills closed this as completed Mar 14, 2019
@grantwwu
Copy link
Author

As a general rule, you should never have slashes in the version part of your go get command.

Git doesn't seem to enforce this requirement (that there are no slashes in a tag or branch name) anywhere. Is this an additional restriction (albeit not a very onerous one) Go is adding?

@bcmills
Copy link
Contributor

bcmills commented Mar 14, 2019

No, it's a heuristic to determine whether the thing you're writing as a go get command is likely to be correct.

Technically you could have a branch name with slashes in it. I sincerely doubt that many, if any, repositories containing Go code will have such branches.

@dvcrn
Copy link

dvcrn commented Oct 9, 2019

Branches with slashes are very common, especially with folks using something like git flow

@hausdorff
Copy link

hausdorff commented Oct 22, 2019

Yes, branches with / in them are definitely a thing.

Our situation is: we have to run CI for an OSS project, which requires access to secrets, which means that to run tests, we need to push branches to the central repository, because secrets are not exposed to branches in forks. To avoid multiple developers trampling over each other, we make branches of the form <username>/branchname. This is to say nothing of named branch release patterns, and so on.

@SourceCode
Copy link

Branches with slashes are ultra common in workflows. You must be able to isolate a specific branch and even a commit in that branch. An example of this is when a certain forward commit breaks something in a library and you require it frozen in time for whatever reason.

For 4 years we pulled a specific commit of a specific branch for an ORM because anything past would break use cases and this part of the application would not be revisited any time soon by engineers.

Details about / in a branch is as easy as looking up feature branches. - IE: feature/my-feature-ABC-123

In things like Gitlab or other automation tools this allows auto-closing/updating of tickets in other systems as well. Alerting engineers of completion, deployment, etc.

@cespare
Copy link
Contributor

cespare commented Oct 28, 2019

We used to use / for namespacing Git branches at my company, so I guess that's an existence proof that there are indeed repositories containing Go code that have branches with slashes.

That said, this turned out to be a bad idea. Git makes a file for each branch (in .git/refs/heads); if you use slashes in the name, git constructs nested directories. This means that you cannot have two different branches newfeature and newfeature/sub-thing because the directories collide. With a different namespacing character, this isn't a problem.

We switched from / to . a couple of years ago and that has worked well for us.

@SourceCode
Copy link

The problem with making those types of changes is that organizations of hundreds / thousands of engineers can't switch code bases, tooling, and existing setups for hundreds of repositories in any timely fashion and to change it because 1 language out of a handful isn't handling it properly seems like crazy talk.

@CyrusNajmabadi
Copy link

@bcmills can you reopen this? As people have pointed out (and the many downvotes show) this is definitely something people do and something that is a problem with go's 'heuristic' here. Given that it's completely legal and reasonable to have branch names with slashes in them (which several projects that i'm part of mandate), not being able to use the go tooling effectively here is a significant problem.

@bcmills
Copy link
Contributor

bcmills commented Jan 30, 2020

@CyrusNajmabadi, this is a documentation issue. If you are “not … able to use the go tooling effectively here”, please open a separate issue with steps to reproduce the problem.

@CyrusNajmabadi
Copy link

Done. Extracted here: #36902

@CyrusNajmabadi
Copy link

this is a documentation issue.

Personally, i disagree. This came in through 'docs' because people have run into this problem and are looking for the docs to tell them how to get themselves out of it (since the presumption is that the go tooling would certainly not be arbitrarily limiting totally normal git/github practices).

That there is no solution doesn't keep this as a doc problem (and the issue should not have been closed for that reason). The lack of a doc solution should have escalated this into the need for a product fix from the get-go (no pun intended) :)

@grantwwu
Copy link
Author

grantwwu commented Jan 30, 2020

Interpreting @bcmills more charitably - I think they were saying that this issue - as in, #30851 - was a documentation issue. Thanks for extracting out the issue into a new one.

I agree that branches with slashes with them is not as uncommon a use case as "I sincerely doubt that many, if any, repositories containing Go code will have such branches." would imply though. I recently changed jobs to a large tech company - as in, I am at a different job than I was when I filed this issue - and here, everyone is expected to prepend their username followed by a slash for their branches, and this is done automatically by internal tooling.

@celesteking
Copy link

That doesn't work:

$ go get github.com/homelight/dat@v2
go get github.com/homelight/dat@v2: no matching versions for query "v2"

Despite branch "v2" being present in the repo.

@bcmills
Copy link
Contributor

bcmills commented Oct 13, 2020

@celesteking, that's #29731.

@golang golang locked and limited conversation to collaborators Oct 13, 2021
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

9 participants