Skip to content

Commit 8752d89

Browse files
authored
Redirect to new repository owner (#21398)
Fixes #17655 If you rename `user1` to `user2` and visit `/user1` you get redirected to `/user2`. But if you visit `/user1/repo` you just get a 404 error. With this PR the user is redirected to `/user2/repo`.
1 parent 2d4c632 commit 8752d89

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

modules/context/repo.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,20 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
451451
owner, err = user_model.GetUserByName(ctx, userName)
452452
if err != nil {
453453
if user_model.IsErrUserNotExist(err) {
454+
// go-get does not support redirects
455+
// https://github.com/golang/go/issues/19760
454456
if ctx.FormString("go-get") == "1" {
455457
EarlyResponseForGoGetMeta(ctx)
456458
return
457459
}
458-
ctx.NotFound("GetUserByName", nil)
460+
461+
if redirectUserID, err := user_model.LookupUserRedirect(userName); err == nil {
462+
RedirectToUser(ctx, userName, redirectUserID)
463+
} else if user_model.IsErrUserRedirectNotExist(err) {
464+
ctx.NotFound("GetUserByName", nil)
465+
} else {
466+
ctx.ServerError("LookupUserRedirect", err)
467+
}
459468
} else {
460469
ctx.ServerError("GetUserByName", err)
461470
}

0 commit comments

Comments
 (0)