fix issues

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2024-02-12 08:49:12 +08:00
parent 7696c03c25
commit c3a1c5ebe9
1 changed files with 13 additions and 8 deletions

View File

@ -127,16 +127,21 @@ func Parse(goGetterSrc string) (*Source, error) {
var sourceDir, sourceFile string
pathComponents := strings.Split(u.Path, "@")
switch len(pathComponents) {
case 1:
sourceDir = pathComponents[0]
case 2:
sourceDir = pathComponents[0]
sourceFile = pathComponents[1]
default:
return nil, InvalidURLError{err: fmt.Sprintf("parse url: invalid path %s", u.Path)}
if len(pathComponents) != 2 {
if strings.HasSuffix(u.Path, ".git") {
pathComponents = []string{u.Path, ""}
} else {
dir := filepath.Dir(u.Path)
if len(dir) > 0 {
dir = dir[1:]
}
pathComponents = []string{dir, filepath.Base(u.Path)}
}
}
sourceDir = pathComponents[0]
sourceFile = pathComponents[1]
return &Source{
Getter: getter,
User: u.User.String(),