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

Difference between github and local git repository #28214

Closed
mvasi90 opened this issue Oct 15, 2018 · 3 comments
Closed

Difference between github and local git repository #28214

mvasi90 opened this issue Oct 15, 2018 · 3 comments

Comments

@mvasi90
Copy link

mvasi90 commented Oct 15, 2018

What version of Go I am using (go version)?

Go 1.11.1 (go/vgo)

My company doesn't use HTTP protocol.
My company only uses UNIX sockets.
All the development is centralized.

I want support several versions of projects/packages with git (local repository) through modules.
The go documentation says that go understand git tags but I'm not seeing it.

Example:
I have a local module named x (without domain name).
This module have two branches (master and v2). Each branch have last commit tags: v1.2.0 and v2.2.0
Now I'm creating a second project/module named y. This project imports x module and when I'm trying to build it give me an error because go wants a goproxy or domain name.
To solve this issue I'm using inside go.mod: replace x v2.2.0 => ../x Note: project name and module is the same
But the replace for me is a hack because go doesn't automatically detect the versions. I can specify any fake path with different version.

My question is: How I can use local git repository instead remote git repository without proxy?
For example:
Module y imports module x using its git repo (or existent clone) and automatically detects the tag version when specify vx.x.x inside go.mod

Note: Doing replace x v.2.2.0 => path is unnecessary work. Is faster avoiding modules and using older dependency specifying the path of existing project. (Is the same as modules with replace but doing less work)

@FiloSottile
Copy link
Contributor

In order to fetch modules, go get needs to know how to reach them from the import path. If your import path does not include a domain name, go get can't fetch it automatically. As you correctly found out, replace is not meant to tell go get where to find a git repository, but just to replace the directory tree of a specific version.

You might be able to set up a custom import domain like go.internal.company.tld/XXX maybe resolved via /etc/hosts to localhost that returns meta tags pointing to locations on your local disk. See go help importpath.

The other alternative is to use GOPROXY. See go help goproxy. You can use a file:// protocol for GOPROXY and just set up a directory tree locally according to the docs.

@thepudds
Copy link
Contributor

@mvasi90 Regarding your comment:

I have a local module named x (without domain name).

Regardless of what else you might be doing, I think you will run into trouble if you do not use a domain name for a module path, even if you are developing purely on your local filesystem. If you do not have a dot in your module paths and import paths, then some things work with modules, but other things don't. See for example #27503, including this #27503 (comment) from @bcmills:

Dotless paths in general are reserved for the standard library; go get has (to my knowledge) never worked with them, but go get is also the main entry point for working with versioned modules.

Note that in general, you can do local development with inter-related modules without a remote git server. Here is a an example go.mod showing that:

module example.com/me/hello
require (
  example.com/me/goodbye v0.0.0
)

replace example.com/me/goodbye => ../goodbye

which is from a more complete and runnable example here.

Does that give you want you are looking for? Note that is just going to use whatever is on the filesystem (e.g., it will use whatever files you would see if you were to cd into that directory and ls).

I'm not sure that is want you want, though, because it sounds like you might want to do local development without a remote git server, but where version information is still specified?

To my knowledge, if you try to do something like specify a version with a local directory on the right side of a replace statment:
replace example.com/me/goodbye => ../goodbye v1.0.0

then you will get an error such as:
replacement module directory path "../goodbye" cannot have version

Finally, I noticed that in some of your examples you were specifying the version on the left side of a replace statement. That is allowed, but not required, and usually not desired (because it makes the replace statement less robust if a version later changes).

In any event, sorry if this is not 100% helpful, but I was curious if any of the above might hint towards a solution that works for you.

@mvasi90
Copy link
Author

mvasi90 commented Oct 21, 2018

Thank you @thepudds. There is no better solution.

go get needs domains to fetch versions automatically. Although go understand git tags not working without domains and if you are using replace don't choose repo versions automatically.

To solve it, any developer can build his own tools with git API and choose automatically desired version of git repository or git clone.
That's all.

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

4 participants