diff options
Diffstat (limited to 'modules/context/repo.go')
-rw-r--r-- | modules/context/repo.go | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go index 8de5b9821b..1ae98545a7 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -133,6 +133,26 @@ func earlyResponseForGoGetMeta(ctx *Context) { }))) } +// RedirectToRepo redirect to a differently-named repository +func RedirectToRepo(ctx *Context, redirectRepoID int64) { + ownerName := ctx.Params(":username") + previousRepoName := ctx.Params(":reponame") + + repo, err := models.GetRepositoryByID(redirectRepoID) + if err != nil { + ctx.Handle(500, "GetRepositoryByID", err) + return + } + + redirectPath := strings.Replace( + ctx.Req.URL.Path, + fmt.Sprintf("%s/%s", ownerName, previousRepoName), + fmt.Sprintf("%s/%s", ownerName, repo.Name), + 1, + ) + ctx.Redirect(redirectPath) +} + // RepoAssignment returns a macaron to handle repository assignment func RepoAssignment(args ...bool) macaron.Handler { return func(ctx *Context) { @@ -176,11 +196,18 @@ func RepoAssignment(args ...bool) macaron.Handler { repo, err := models.GetRepositoryByName(owner.ID, repoName) if err != nil { if models.IsErrRepoNotExist(err) { - if ctx.Query("go-get") == "1" { - earlyResponseForGoGetMeta(ctx) - return + redirectRepoID, err := models.LookupRepoRedirect(owner.ID, repoName) + if err == nil { + RedirectToRepo(ctx, redirectRepoID) + } else if models.IsErrRepoRedirectNotExist(err) { + if ctx.Query("go-get") == "1" { + earlyResponseForGoGetMeta(ctx) + return + } + ctx.Handle(404, "GetRepositoryByName", err) + } else { + ctx.Handle(500, "LookupRepoRedirect", err) } - ctx.Handle(404, "GetRepositoryByName", err) } else { ctx.Handle(500, "GetRepositoryByName", err) } |