mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-04 14:46:57 -05:00
Handle redirects in git clone commands (#6688)
Add support for repo_redirect objects in the git smart http handler so that when a user clones a repo that has been moved or renamed, they are redirected to the new location. This requires that the query string be included in the redirect as well, so that is added. Signed-off-by: James E. Blair <jeblair@redhat.com>
This commit is contained in:
parent
0064535ad2
commit
dabee9b1a4
@ -223,6 +223,9 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) {
|
||||
fmt.Sprintf("%s/%s", repo.MustOwnerName(), repo.Name),
|
||||
1,
|
||||
)
|
||||
if ctx.Req.URL.RawQuery != "" {
|
||||
redirectPath += "?" + ctx.Req.URL.RawQuery
|
||||
}
|
||||
ctx.Redirect(redirectPath)
|
||||
}
|
||||
|
||||
|
@ -89,9 +89,24 @@ func HTTP(ctx *context.Context) {
|
||||
reponame = reponame[:len(reponame)-5]
|
||||
}
|
||||
|
||||
repo, err := models.GetRepositoryByOwnerAndName(username, reponame)
|
||||
owner, err := models.GetUserByName(username)
|
||||
if err != nil {
|
||||
ctx.NotFoundOrServerError("GetRepositoryByOwnerAndName", models.IsErrRepoNotExist, err)
|
||||
ctx.NotFoundOrServerError("GetUserByName", models.IsErrUserNotExist, err)
|
||||
return
|
||||
}
|
||||
|
||||
repo, err := models.GetRepositoryByName(owner.ID, reponame)
|
||||
if err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
redirectRepoID, err := models.LookupRepoRedirect(owner.ID, reponame)
|
||||
if err == nil {
|
||||
context.RedirectToRepo(ctx, redirectRepoID)
|
||||
} else {
|
||||
ctx.NotFoundOrServerError("GetRepositoryByName", models.IsErrRepoRedirectNotExist, err)
|
||||
}
|
||||
} else {
|
||||
ctx.ServerError("GetRepositoryByName", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user