Skip to content

cmd/go: .git in module names is stripped when used as repo url #71635

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
torrca opened this issue Feb 9, 2025 · 5 comments
Closed

cmd/go: .git in module names is stripped when used as repo url #71635

torrca opened this issue Feb 9, 2025 · 5 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@torrca
Copy link

torrca commented Feb 9, 2025

Go-get uses only a section of module path argument

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

master

What operating system and processor architecture are you using?

Any.

What did you do?

Run Go-get directly on a module path containing a .git suffix. For example:

$ GOPROXY=direct go get -x example.url/project.git

What did you expect to see?

The module path passed to the Go tool used in the ls-remote command and subsequent operations. E.g.:

# get https://example.url/?go-get=1
cd /tmp/go/pkg/mod
git ls-remote https://example.url/project.git
⋮

What did you see instead?

A section of the passed module path, without the .git suffix at the end:

# get https://example.url/?go-get=1
cd /tmp/go/pkg/mod
git ls-remote https://example.url/project	# <-- This
⋮

Investigation

This line[1] and this one[2] seem to be causing the issue. Such behavior assumes the .git suffix is not part of the module path, using the submatch instead of the string passed to the Go command.

---
[1]:

repo := match["repo"]

[2]:
regexp: lazyregexp.New(`(?P<root>(?P<repo>([a-z0-9.\-]+\.)+[a-z0-9.\-]+(:[0-9]+)?(/~?[\w.\-]+)+?)\.(?P<vcs>bzr|fossil|git|hg|svn))(/~?[\w.\-]+)*$`),

@seankhliao seankhliao changed the title Go-get uses only a section of module path argument cmd/go: .git in module names is stripped when used as repo url Feb 9, 2025
@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Feb 9, 2025
@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Feb 9, 2025
@rsc
Copy link
Contributor

rsc commented Feb 11, 2025

This is working as designed. The .git suffix is special syntax that indicates that git should be used for what comes before it. It is not part of the repo name. See https://pkg.go.dev/cmd/go#hdr-Remote_import_paths.

If you want to make an arbitrary path work, the best answer is to use an HTTPS page with a redirecting meta tag (also described in that doc section). Another option is to make your git server allow the .git to be dropped, as happens in this case.

If you must express to the go command an instruction to access of accessing example.url/project.git using git, you should be able to use example.com/url/project.git.git as the module path. That's obviously not ideal, but it's what the rules require.

We can't change the rules without potentially breaking all the existing uses of the .git name in modules. Most usage is in private modules that we can't see, so the effects are particularly difficult to quantify. It would certainly be a breaking change, so we're not going to do that.

@rsc rsc closed this as completed Feb 11, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/644095 mentions this issue: _content/ref: clarify vcs repo url

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/648475 mentions this issue: cmd/go: clarify vcs suffix to repo mapping

gopherbot pushed a commit that referenced this issue Feb 12, 2025
For #71635

Change-Id: I12ec2a810cfcaf2565b0d9c518b0921ec54e9f12
Reviewed-on: https://go-review.googlesource.com/c/go/+/648475
Reviewed-by: Michael Matloob <matloob@golang.org>
Auto-Submit: Sam Thanawalla <samthanawalla@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
@torrca
Copy link
Author

torrca commented Feb 14, 2025

Understood.

gopherbot pushed a commit to golang/website that referenced this issue Feb 20, 2025
The text says "up to" without including the vcs identifier,
which matches current cmd/go behavior, but the example includes
the vcs identifier in the url.

For golang/go#71635

Change-Id: If8277b1305c496f3ba20e6c58f5f920cf1ba48a9
Reviewed-on: https://go-review.googlesource.com/c/website/+/644095
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants