aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorQuan Tong <quantonganh@gmail.com>2023-11-01 18:08:23 +0700
committerGopher Robot <gobot@golang.org>2023-11-06 18:00:45 +0000
commitd5b5ab929bf49403de3e2b61e9e771e775893d01 (patch)
tree5934e87c5effad4307c224dcc580fcab230670fa /src
parent4cd201b14b6216e72ffa175747c20d1191e5eb57 (diff)
downloadgo-d5b5ab929bf49403de3e2b61e9e771e775893d01.tar.xz
cmd/go: handle '@' in local path when running 'go mod edit -replace'
The existing implementation considers everything after '@' as a version. Fixes #61500 Change-Id: I72c32529c2726c2b59c089f5ffd6a2e361ef2c65 Reviewed-on: https://go-review.googlesource.com/c/go/+/538916 Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/go/internal/modcmd/edit.go7
-rw-r--r--src/cmd/go/testdata/script/mod_edit.txt19
2 files changed, 23 insertions, 3 deletions
diff --git a/src/cmd/go/internal/modcmd/edit.go b/src/cmd/go/internal/modcmd/edit.go
index 96bd608c01..db131b0881 100644
--- a/src/cmd/go/internal/modcmd/edit.go
+++ b/src/cmd/go/internal/modcmd/edit.go
@@ -315,6 +315,9 @@ func parsePath(flag, arg string) (path string) {
// parsePathVersionOptional parses path[@version], using adj to
// describe any errors.
func parsePathVersionOptional(adj, arg string, allowDirPath bool) (path, version string, err error) {
+ if allowDirPath && modfile.IsDirectoryPath(arg) {
+ return arg, "", nil
+ }
before, after, found := strings.Cut(arg, "@")
if !found {
path = arg
@@ -322,9 +325,7 @@ func parsePathVersionOptional(adj, arg string, allowDirPath bool) (path, version
path, version = strings.TrimSpace(before), strings.TrimSpace(after)
}
if err := module.CheckImportPath(path); err != nil {
- if !allowDirPath || !modfile.IsDirectoryPath(path) {
- return path, version, fmt.Errorf("invalid %s path: %v", adj, err)
- }
+ return path, version, fmt.Errorf("invalid %s path: %v", adj, err)
}
if path != arg && !allowedVersionArg(version) {
return path, version, fmt.Errorf("invalid %s version: %q", adj, version)
diff --git a/src/cmd/go/testdata/script/mod_edit.txt b/src/cmd/go/testdata/script/mod_edit.txt
index ebc032a73c..2d09b06c61 100644
--- a/src/cmd/go/testdata/script/mod_edit.txt
+++ b/src/cmd/go/testdata/script/mod_edit.txt
@@ -61,6 +61,10 @@ go mod edit -replace=x.1=y.1/v2@v2.3.6
cmpenv go.mod $WORK/go.mod.edit4
go mod edit -dropreplace=x.1
cmpenv go.mod $WORK/go.mod.edit5
+go mod edit -replace=x.1=../y.1/@v2
+cmpenv go.mod $WORK/go.mod.edit6
+! go mod edit -replace=x.1=y.1/@v2
+stderr '^go: -replace=x.1=y.1/@v2: invalid new path: malformed import path "y.1/": trailing slash$'
# go mod edit -fmt
cp $WORK/go.mod.badfmt go.mod
@@ -218,6 +222,21 @@ retract (
)
require x.3 v1.99.0
+-- $WORK/go.mod.edit6 --
+module x.x/y/z
+
+go $goversion
+
+exclude x.1 v1.2.0
+
+retract (
+ v1.6.0
+ [v1.3.0, v1.4.0]
+)
+
+require x.3 v1.99.0
+
+replace x.1 => ../y.1/@v2
-- $WORK/local/go.mod.edit --
module local-only