diff options
author | Unknwon <u@gogs.io> | 2015-09-01 11:43:53 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-09-01 11:43:53 -0400 |
commit | 398569f6f8c9636a7497a250f02e9c6b0a27ea9a (patch) | |
tree | e706abe838eb5311c02cf47e5e5b99a9c221090e /modules/middleware | |
parent | dde9ace91b3e492386d4b31996ae970f5c9c10bd (diff) | |
download | gitea-398569f6f8c9636a7497a250f02e9c6b0a27ea9a.tar.gz gitea-398569f6f8c9636a7497a250f02e9c6b0a27ea9a.zip |
#1021 Forked repo unavailable after deleting original repo
Diffstat (limited to 'modules/middleware')
-rw-r--r-- | modules/middleware/repo.go | 62 |
1 files changed, 37 insertions, 25 deletions
diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 8a5d0f3b25..5b337a6ba8 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -190,6 +190,41 @@ func RepoRef() macaron.Handler { } } +func RetrieveBaseRepo(ctx *Context, repo *models.Repository) { + // Non-fork repository will not return error in this method. + if err := repo.GetBaseRepo(); err != nil { + if models.IsErrRepoNotExist(err) { + repo.IsFork = false + repo.ForkID = 0 + return + } + ctx.Handle(500, "GetBaseRepo", err) + return + } else if err = repo.BaseRepo.GetOwner(); err != nil { + ctx.Handle(500, "BaseRepo.GetOwner", err) + return + } + + bsaeRepo := repo.BaseRepo + baseGitRepo, err := git.OpenRepository(models.RepoPath(bsaeRepo.Owner.Name, bsaeRepo.Name)) + if err != nil { + ctx.Handle(500, "OpenRepository", err) + return + } + if len(bsaeRepo.DefaultBranch) > 0 && baseGitRepo.IsBranchExist(bsaeRepo.DefaultBranch) { + ctx.Data["BaseDefaultBranch"] = bsaeRepo.DefaultBranch + } else { + baseBranches, err := baseGitRepo.GetBranches() + if err != nil { + ctx.Handle(500, "GetBranches", err) + return + } + if len(baseBranches) > 0 { + ctx.Data["BaseDefaultBranch"] = baseBranches[0] + } + } +} + func RepoAssignment(redirect bool, args ...bool) macaron.Handler { return func(ctx *Context) { var ( @@ -292,32 +327,9 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Repo.Repository.NumTags = len(tags) if repo.IsFork { - // Non-fork repository will not return error in this method. - if err = repo.GetBaseRepo(); err != nil { - ctx.Handle(500, "GetBaseRepo", err) + RetrieveBaseRepo(ctx, repo) + if ctx.Written() { return - } else if repo.BaseRepo.GetOwner(); err != nil { - ctx.Handle(500, "BaseRepo.GetOwner", err) - return - } - - bsaeRepo := repo.BaseRepo - baseGitRepo, err := git.OpenRepository(models.RepoPath(bsaeRepo.Owner.Name, bsaeRepo.Name)) - if err != nil { - ctx.Handle(500, "OpenRepository", err) - return - } - if len(bsaeRepo.DefaultBranch) > 0 && baseGitRepo.IsBranchExist(bsaeRepo.DefaultBranch) { - ctx.Data["BaseDefaultBranch"] = bsaeRepo.DefaultBranch - } else { - baseBranches, err := baseGitRepo.GetBranches() - if err != nil { - ctx.Handle(500, "GetBranches", err) - return - } - if len(baseBranches) > 0 { - ctx.Data["BaseDefaultBranch"] = baseBranches[0] - } } } |