diff options
Diffstat (limited to 'routers/repo')
-rw-r--r-- | routers/repo/repo.go | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/routers/repo/repo.go b/routers/repo/repo.go index f7e7e32093..dab9dba1f5 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -6,7 +6,6 @@ package repo import ( "fmt" - "net/url" "os" "path" "strings" @@ -164,26 +163,24 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { return } - // Remote address can be HTTP/HTTPS/Git URL or local path. - // Note: remember to change api/v1/repo.go: MigrateRepo - // FIXME: merge these two functions with better error handling - remoteAddr := form.CloneAddr - if strings.HasPrefix(form.CloneAddr, "http://") || - strings.HasPrefix(form.CloneAddr, "https://") || - strings.HasPrefix(form.CloneAddr, "git://") { - u, err := url.Parse(form.CloneAddr) - if err != nil { + remoteAddr, err := form.ParseRemoteAddr(ctx.User) + if err != nil { + if models.IsErrInvalidCloneAddr(err) { ctx.Data["Err_CloneAddr"] = true - ctx.RenderWithErr(ctx.Tr("form.url_error"), MIGRATE, &form) - return - } - if len(form.AuthUsername) > 0 || len(form.AuthPassword) > 0 { - u.User = url.UserPassword(form.AuthUsername, form.AuthPassword) + addrErr := err.(models.ErrInvalidCloneAddr) + switch { + case addrErr.IsURLError: + ctx.RenderWithErr(ctx.Tr("form.url_error"), MIGRATE, &form) + case addrErr.IsPermissionDenied: + ctx.RenderWithErr(ctx.Tr("repo.migrate.permission_denied"), MIGRATE, &form) + case addrErr.IsInvalidPath: + ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), MIGRATE, &form) + default: + ctx.Handle(500, "Unknown error", err) + } + } else { + ctx.Handle(500, "ParseRemoteAddr", err) } - remoteAddr = u.String() - } else if !com.IsDir(remoteAddr) { - ctx.Data["Err_CloneAddr"] = true - ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), MIGRATE, &form) return } |