diff --git a/mod.go b/mod.go index a10023f..807444a 100644 --- a/mod.go +++ b/mod.go @@ -53,6 +53,11 @@ func PkgSourceDir(pkgPath, modDir string, replace bool) (dir string, err error) continue } suffix := strings.TrimPrefix(pkgPath, pkg.Mod.Path) + // github.com/issue9/web 与 github.com/issue9/webuse 也匹配,但不是同一个包 + // 只有 github.com/issue9/web 与 github.com/issue9/web/v4 这种才行 + if suffix != "" && suffix[0] != '/' { + continue + } if !replace { return filepath.Join(pkgSource, pkg.Mod.Path+"@"+pkg.Mod.Version+suffix), nil diff --git a/mod_test.go b/mod_test.go index a2cc7eb..acdca16 100644 --- a/mod_test.go +++ b/mod_test.go @@ -34,6 +34,9 @@ func TestPkgSourceDir(t *testing.T) { a.NotError(err).FileExists(dir). True(strings.HasSuffix(filepath.ToSlash(dir), "assert/v4@v4.3.0/rest")) + dir, err = PkgSourceDir("github.com/issue9/assertxx", "./", false) + a.ErrorIs(err, fs.ErrNotExist) + // replace dir, err = PkgSourceDir("github.com/issue9/web/v2", "./testdata/go.mod", true)