summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-01-17 10:08:07 +0800
committerGitHub <noreply@github.com>2020-01-17 10:08:07 +0800
commited6a2f2e2ecc4dec4f5a38c8356df98b88331d8a (patch)
tree8aa29af3f95c56ddb09e5c2548367244b031b5ee
parenta0435fcd635194868921b45a241bed56b444b5e5 (diff)
downloadgitea-ed6a2f2e2ecc4dec4f5a38c8356df98b88331d8a.tar.gz
gitea-ed6a2f2e2ecc4dec4f5a38c8356df98b88331d8a.zip
Fix compare (#9808) (#9815)
Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: techknowlogick <matti@mdranta.net>
-rw-r--r--routers/repo/compare.go44
1 files changed, 20 insertions, 24 deletions
diff --git a/routers/repo/compare.go b/routers/repo/compare.go
index 9c41a8af3c..a307109ba0 100644
--- a/routers/repo/compare.go
+++ b/routers/repo/compare.go
@@ -152,12 +152,12 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
ctx.ServerError("OpenRepository", err)
return nil, nil, nil, nil, "", ""
}
+ defer headGitRepo.Close()
}
// user should have permission to read baseRepo's codes and pulls, NOT headRepo's
permBase, err := models.GetUserRepoPermission(baseRepo, ctx.User)
if err != nil {
- headGitRepo.Close()
ctx.ServerError("GetUserRepoPermission", err)
return nil, nil, nil, nil, "", ""
}
@@ -168,42 +168,40 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
baseRepo,
permBase)
}
- headGitRepo.Close()
ctx.NotFound("ParseCompareInfo", nil)
return nil, nil, nil, nil, "", ""
}
- // user should have permission to read headrepo's codes
- permHead, err := models.GetUserRepoPermission(headRepo, ctx.User)
- if err != nil {
- headGitRepo.Close()
- ctx.ServerError("GetUserRepoPermission", err)
- return nil, nil, nil, nil, "", ""
- }
- if !permHead.CanRead(models.UnitTypeCode) {
- if log.IsTrace() {
- log.Trace("Permission Denied: User: %-v cannot read code in Repo: %-v\nUser in headRepo has Permissions: %-+v",
- ctx.User,
- headRepo,
- permHead)
+ if !isSameRepo {
+ // user should have permission to read headrepo's codes
+ permHead, err := models.GetUserRepoPermission(headRepo, ctx.User)
+ if err != nil {
+ ctx.ServerError("GetUserRepoPermission", err)
+ return nil, nil, nil, nil, "", ""
+ }
+ if !permHead.CanRead(models.UnitTypeCode) {
+ if log.IsTrace() {
+ log.Trace("Permission Denied: User: %-v cannot read code in Repo: %-v\nUser in headRepo has Permissions: %-+v",
+ ctx.User,
+ headRepo,
+ permHead)
+ }
+ ctx.NotFound("ParseCompareInfo", nil)
+ return nil, nil, nil, nil, "", ""
}
- headGitRepo.Close()
- ctx.NotFound("ParseCompareInfo", nil)
- return nil, nil, nil, nil, "", ""
}
// Check if head branch is valid.
- headIsCommit := ctx.Repo.GitRepo.IsCommitExist(headBranch)
+ headIsCommit := headGitRepo.IsCommitExist(headBranch)
headIsBranch := headGitRepo.IsBranchExist(headBranch)
headIsTag := headGitRepo.IsTagExist(headBranch)
if !headIsCommit && !headIsBranch && !headIsTag {
// Check if headBranch is short sha commit hash
- if headCommit, _ := ctx.Repo.GitRepo.GetCommit(headBranch); headCommit != nil {
+ if headCommit, _ := headGitRepo.GetCommit(headBranch); headCommit != nil {
headBranch = headCommit.ID.String()
ctx.Data["HeadBranch"] = headBranch
headIsCommit = true
} else {
- headGitRepo.Close()
ctx.NotFound("IsRefExist", nil)
return nil, nil, nil, nil, "", ""
}
@@ -224,14 +222,12 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
baseRepo,
permBase)
}
- headGitRepo.Close()
ctx.NotFound("ParseCompareInfo", nil)
return nil, nil, nil, nil, "", ""
}
- compareInfo, err := headGitRepo.GetCompareInfo(models.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseBranch, headBranch)
+ compareInfo, err := headGitRepo.GetCompareInfo(baseRepo.RepoPath(), baseBranch, headBranch)
if err != nil {
- headGitRepo.Close()
ctx.ServerError("GetCompareInfo", err)
return nil, nil, nil, nil, "", ""
}