mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
fix: go work duplicate prefix get err (#4487)
This commit is contained in:
parent
fd07a9c6e4
commit
9c4ed394a7
@ -82,13 +82,15 @@ func getRealModule(workDir string, execRun execx.RunFunc) (*Module, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if workDir[len(workDir)-1] != os.PathSeparator {
|
||||||
|
workDir = workDir + string(os.PathSeparator)
|
||||||
|
}
|
||||||
for _, m := range modules {
|
for _, m := range modules {
|
||||||
realDir, err := pathx.ReadLink(m.Dir)
|
realDir, err := pathx.ReadLink(m.Dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read go.mod, dir: %s, error: %w", m.Dir, err)
|
return nil, fmt.Errorf("failed to read go.mod, dir: %s, error: %w", m.Dir, err)
|
||||||
}
|
}
|
||||||
|
realDir += string(os.PathSeparator)
|
||||||
if strings.HasPrefix(workDir, realDir) {
|
if strings.HasPrefix(workDir, realDir) {
|
||||||
return &m, nil
|
return &m, nil
|
||||||
}
|
}
|
||||||
|
@ -98,6 +98,60 @@ func Test_getRealModule(t *testing.T) {
|
|||||||
GoVersion: "go1.20",
|
GoVersion: "go1.20",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "go work duplicate prefix",
|
||||||
|
args: args{
|
||||||
|
workDir: "D:\\code\\company\\core-ee\\service",
|
||||||
|
execRun: func(arg, dir string, in ...*bytes.Buffer) (string, error) {
|
||||||
|
return `
|
||||||
|
{
|
||||||
|
"Path": "gitee.com/unitedrhino/core",
|
||||||
|
"Dir": "D:\\code\\company\\core",
|
||||||
|
"GoMod": "D:\\code\\company\\core\\go.mod",
|
||||||
|
"GoVersion": "1.21.4"
|
||||||
|
}
|
||||||
|
{
|
||||||
|
"Path": "gitee.com/unitedrhino/core-ee",
|
||||||
|
"Dir": "D:\\code\\company\\core-ee",
|
||||||
|
"GoMod": "D:\\code\\company\\core-ee\\go.mod",
|
||||||
|
"GoVersion": "1.21.4"
|
||||||
|
}`, nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: &Module{
|
||||||
|
Path: "gitee.com/unitedrhino/core-ee",
|
||||||
|
Dir: "D:\\code\\company\\core-ee",
|
||||||
|
GoMod: "D:\\code\\company\\core-ee\\go.mod",
|
||||||
|
GoVersion: "1.21.4",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "go work duplicate prefix2",
|
||||||
|
args: args{
|
||||||
|
workDir: "D:\\code\\company\\core-ee",
|
||||||
|
execRun: func(arg, dir string, in ...*bytes.Buffer) (string, error) {
|
||||||
|
return `
|
||||||
|
{
|
||||||
|
"Path": "gitee.com/unitedrhino/core",
|
||||||
|
"Dir": "D:\\code\\company\\core",
|
||||||
|
"GoMod": "D:\\code\\company\\core\\go.mod",
|
||||||
|
"GoVersion": "1.21.4"
|
||||||
|
}
|
||||||
|
{
|
||||||
|
"Path": "gitee.com/unitedrhino/core-ee",
|
||||||
|
"Dir": "D:\\code\\company\\core-ee",
|
||||||
|
"GoMod": "D:\\code\\company\\core-ee\\go.mod",
|
||||||
|
"GoVersion": "1.21.4"
|
||||||
|
}`, nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: &Module{
|
||||||
|
Path: "gitee.com/unitedrhino/core-ee",
|
||||||
|
Dir: "D:\\code\\company\\core-ee",
|
||||||
|
GoMod: "D:\\code\\company\\core-ee\\go.mod",
|
||||||
|
GoVersion: "1.21.4",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user