summaryrefslogtreecommitdiffstats
path: root/routers/repo/http.go
diff options
context:
space:
mode:
authorJames E. Blair <corvus@inaugust.com>2019-04-24 22:51:40 -0700
committerLauris BH <lauris@nix.lv>2019-04-25 08:51:40 +0300
commitdabee9b1a4347b0003c36f0f2a0548e5fa4002f7 (patch)
tree3145d39be1b48b0d64f195d62dc2787c1b3b37d3 /routers/repo/http.go
parent0064535ad28f85fb8c84a0237ea02bd432c6a1f6 (diff)
downloadgitea-dabee9b1a4347b0003c36f0f2a0548e5fa4002f7.tar.gz
gitea-dabee9b1a4347b0003c36f0f2a0548e5fa4002f7.zip
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>
Diffstat (limited to 'routers/repo/http.go')
-rw-r--r--routers/repo/http.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/routers/repo/http.go b/routers/repo/http.go
index 9475c25893..2bc50efd83 100644
--- a/routers/repo/http.go
+++ b/routers/repo/http.go
@@ -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
}