diff options
author | Unknwon <u@gogs.io> | 2015-02-22 09:49:25 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-02-22 09:49:25 -0500 |
commit | 059338139ca4a70cb1138dc09039abb5dac0d0f2 (patch) | |
tree | 4b80829314df3b9f7e21b67ccf5fc30146f0c4e4 /routers/repo | |
parent | c753fdceaf0549aa865cff4e1f42be5d907bbdb1 (diff) | |
download | gitea-059338139ca4a70cb1138dc09039abb5dac0d0f2.tar.gz gitea-059338139ca4a70cb1138dc09039abb5dac0d0f2.zip |
routers: able to migrate repo from local path
- modules/middleware/context.go: add HandleAPI method
Diffstat (limited to 'routers/repo')
-rw-r--r-- | routers/repo/repo.go | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 48f7b09bc0..dfd827bbb9 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -181,20 +181,26 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { } } - u, err := url.Parse(form.HttpsUrl) - - if err != nil || u.Scheme != "https" { - ctx.Data["Err_HttpsUrl"] = true - ctx.RenderWithErr(ctx.Tr("form.url_error"), MIGRATE, &form) + // Remote address can be HTTPS URL or local path. + remoteAddr := form.CloneAddr + if strings.HasPrefix(form.CloneAddr, "http") { + u, err := url.Parse(form.CloneAddr) + if err != nil { + ctx.Data["Err_CloneAddr"] = true + ctx.RenderWithErr(ctx.Tr("form.url_error"), MIGRATE, &form) + return + } + if len(form.AuthUserName) > 0 || len(form.AuthPasswd) > 0 { + u.User = url.UserPassword(form.AuthUserName, form.AuthPasswd) + } + 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 } - if len(form.AuthUserName) > 0 || len(form.AuthPasswd) > 0 { - u.User = url.UserPassword(form.AuthUserName, form.AuthPasswd) - } - - repo, err := models.MigrateRepository(ctxUser, form.RepoName, form.Description, form.Private, - form.Mirror, u.String()) + repo, err := models.MigrateRepository(ctxUser, form.RepoName, form.Description, form.Private, form.Mirror, remoteAddr) if err == nil { log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName) ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + form.RepoName) |