1
0
mirror of https://github.com/golang/go synced 2024-11-12 04:40:22 -07:00

cmd/go: fix bugs in replacement path handling

These are tested in golang.org/cl/357169 and golang.org/cl/358540.

Change-Id: I5add3f202db71731487f2688234c547abe1fd287
Reviewed-on: https://go-review.googlesource.com/c/go/+/361416
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Michael Matloob 2021-10-19 14:05:29 -04:00
parent 6b223e872a
commit 755ede0c5b
2 changed files with 2 additions and 2 deletions

View File

@ -968,7 +968,7 @@ func makeMainModules(ms []module.Version, rootDirs []string, modFiles []*modfile
for _, r := range modFiles[i].Replace { for _, r := range modFiles[i].Replace {
if replacedByWorkFile[r.Old.Path] { if replacedByWorkFile[r.Old.Path] {
continue continue
} else if prev, ok := replacements[r.Old]; ok && !curModuleReplaces[r.Old] { } else if prev, ok := replacements[r.Old]; ok && !curModuleReplaces[r.Old] && prev != r.New {
base.Fatalf("go: conflicting replacements for %v:\n\t%v\n\t%v\nuse \"go mod editwork -replace %v=[override]\" to resolve", r.Old, prev, r.New, r.Old) base.Fatalf("go: conflicting replacements for %v:\n\t%v\n\t%v\nuse \"go mod editwork -replace %v=[override]\" to resolve", r.Old, prev, r.New, r.Old)
} }
curModuleReplaces[r.Old] = true curModuleReplaces[r.Old] = true

View File

@ -378,7 +378,7 @@ func canonicalizeReplacePath(r module.Version, modRoot string) module.Version {
return r return r
} }
abs := filepath.Join(modRoot, r.Path) abs := filepath.Join(modRoot, r.Path)
if rel, err := filepath.Rel(workFilePath, abs); err == nil { if rel, err := filepath.Rel(filepath.Dir(workFilePath), abs); err == nil {
return module.Version{Path: rel, Version: r.Version} return module.Version{Path: rel, Version: r.Version}
} }
// We couldn't make the version's path relative to the workspace's path, // We couldn't make the version's path relative to the workspace's path,