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
Can't use modules on a branch other than master #41535
Comments
https://golang.org/ref/mod#vcs-branch see https://github.com/golang/go/wiki/Questions for the appropriate channels to ask questions |
Sean - that link doesn't address the use of branches with modules. No combination of adding the branch name to the import path in main.go or the require statement in go.mod works. I'm writing code, not doing Has anyone even tried to use modules on a branch other than master? |
@dwschulze, per https://golang.org/ref/mod#version-queries (emphasis mine):
Import paths are paths, not versions: they indicate only the broad API in use, not the specific version of the API. (Version information goes in the |
The error message from your second attempt (with the version in the Please try the import and module path Per https://golang.org/ref/mod#vcs-branch, use the command |
Do I understand you correctly: In order to use modules on a branch I have to do a |
@dwschulze, see https://blog.golang.org/using-go-modules or http://golang.org/wiki/Modules#how-to-upgrade-and-downgrade-dependencies for an overview of usage. |
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 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 |
@dwschulze, most of the tests for module-mode behavior are in the
I'm asking you: have you tried the specific commands that I suggested above? If so, please post the output — if you are correct that there is a serious bug, then we need specific steps to reproduce it, ideally as a script test that we can commit to the repo along with a fix. |
For the record, I have been using go modules on non master branches for more than a year now and it works fine. It takes a while to get used to go modules though, so please take the time needed to learn. In particular, the version query @Branch will work in a go.mod file, but not in an import statement, and not in combination with a version query. You must use either a branch name or a version number, not both. |
Let me see if I have this correct. If I use master then I don't have to download anything. I type Do I understand you correctly that if I want to use a branch other than master that I have to execute
What finally worked was
It downloaded a pseudo version from the branch But now there's some magic going on that I don't understand. If I delete the directories under GOPATH/pkg/mod where the code was downloaded to I can run the code again and it downloads the code from the I also created a v0.0.2 tag on the Is there another secret cache somewhere that prevents me from having to run |
@beoran - How do you use version numbers on your branches, or do you not use version numbers on branches? Omitting version numbers seems like it would defeat one of the biggest features of Go modules. In my case I will have to use version numbers on non-master branches. |
What is running on 192.168.0.12? A plain git repository, or a web based solution like gitlab or gitea? Is sshd also running? You cannot go get a specific version of a main package, but you can go download or go run it. Look at your go.mod file as well as your GOPATH directory to see what is happening. If you want to use go mod versions with git, you need to create git tags like 0.4.5 or 1.2.3 and go mod will recognize them as versions. You can place such version tags on any commit in any branch. But as I said before, to modules are relatively complex, please study the documentation well. If the documentation is not clear enough, then maybe there is something we can do about it. |
@dwschulze the module system resolves all versions to commits (which it records as a pseudoversion) or tags (which it assumes will never move). Branches are resolved to the latest commit and recorded at such, there is no way for you to say "always use the latest commit from branch x" |
@dwschulze, originally you posted an example The error message in #41535 (comment) says The module path declared in your |
@beoran - There is no web server running on the git repo. It was created with --bare and is accessed through ssh. The necessary information is spread throughout the documentation. It needs to be in one place (using modules with private repos). It needs to be complete. Some things like |
We can probably edit https://github.com/golang/go/wiki/Modules and add a chapter on local use, perhaps with your input once you figure it out. |
the new reference page should be https://golang.org/ref/mod with the relevant sections being:
gitconfig is relevant to all private repos, not just module mode, though it might help to put it in there
Indicates you fixed the actual error instead of repeating the same commands with the exact same state |
At first I liked that go installs dependencies automagically. After reading this and running into similar issues, there is a reason no other language works this way. Stop trying to be too smart with many different things that can break, have a simple and well-documented workflow!
Sorry, learning a new language is annoying... |
Since this started working with the dev2 branch, but I don't know why it works when I no longer tell it about the branch I thought I'd try this out on a different machine. Using the same main.go and go.mod on the different machine here is what happened:
v0.0.3 is only on the
This looks like what beoran was talking about. The Go toolchain can't deal with a non-master branch and version numbers. So I changed it to v0.0.1 which is on
Tried again leaving off the branch name:
Try with GOPRIVATE set:
I've got to conclude that Go modules don't work with non-master branches. The latest attempt doesn't even work with a version that is on master. |
@fizmat - I agree that Go tries to be too smart when it comes to dependencies. Go mixes concerns. The download IP address is in the source code as an import statement. Having an IP address of a dependency in the source code is an architectural smell, IMO. It's tight coupling as well. Maven avoids this kind of coupling by moving IP addresses to the build.xml so they're not in the source code. |
@beoran - I'm going to write this up once I get some time (I've got to get some work done - this has been quite a diversion). I'll show all the steps and where it quit working. It worked on one machine, but not on another. I have no idea why it finally started working on one machine. |
Could you please give us the output of 'git tag' and 'git branch' on the http://192.168.0.12/gitrepo/go-module-test-dateutil.git? As I said before, the go toolchain can handle versions that are not on the master branch of git perfectly fine, although a go proxy might be needed in some cases. I would recommend reading the docs that @seankhliao posted, they are new and seem to explain everything in great detail. |
$ git remote --v
Note that ubuntu-18-extssd has IP address 192.168.0.12. I've read those docs and they don't address the problems that I'm seeing or the way I need to use modules (use ssh to access git on a host with a private IP address on non-master branch). |
with a remote like:
your workflow should be something like: #!/bin/sh
set -ex
# clean environment
export T=$(mktemp -d)
CACHE=$(mktemp -d)
export GOMODCACHE=${CACHE}
# git host access
IP=34.72.69.170
U=arccy
export GOPRIVATE=${IP}
git config --global url."${U}@${IP}:".insteadOf "https://${IP}/"
# develop
cd ${T}
go mod init test/41535
cat << EOF > main.go
package main
import "fmt"
import test41535 "${IP}/repos/test41535.git"
func main() {
fmt.Println("hello", test41535.Version)
}
EOF
# (optional) show all tagged versions of dependency
go list -m -versions ${IP}/repos/test41535.git
# get a specific version
go get -d ${IP}/repos/test41535.git@dev2
# run
go run . |
I've written up a long answer covering how to use packages and modules from git repos on private servers. Towards I cover the issue of using branches other than master. |
Seems like you rseolved how to use |
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:
go.mod:
I need to use the branch
dev2
for development. The docs don't show what needs to be done to the import path or therequire
statement ingo.mod
. If I change the import statement to:I get:
If I move the
@dev2
to therequire
statement ingo.mod
I get
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 ingo.mod
need to be changed.Go modules need to be able to be used on branches other than
master
.The text was updated successfully, but these errors were encountered: