aboutsummaryrefslogtreecommitdiff
path: root/routers/repo/pull.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-02-08 18:43:46 -0500
committerUnknwon <u@gogs.io>2017-02-08 18:43:46 -0500
commitafab38b0d74c65e1deb4348a411cd3a13a641b74 (patch)
tree02f9083504b354c41812f30cd6d52677b12c6c60 /routers/repo/pull.go
parentede58ade4c5f5729ae225e3330802aa645973d54 (diff)
routers/repo/pull: fix 404 on PR compare (#4074)
Due to recent code refactor, ctx.PullRequest is not initialized for route repo.CompareAndPullRequest, which leads the UI thinks the compare is not happening inside the same repository. The current fix is to allow compare URL to include redundant head user name so everything works fine again, but code logic isn't as clean as before. Made comments about possible future fix.
Diffstat (limited to 'routers/repo/pull.go')
-rw-r--r--routers/repo/pull.go31
1 files changed, 19 insertions, 12 deletions
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index d649e3d7..d99d5c83 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -453,6 +453,7 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
return nil, nil, nil, nil, "", ""
}
headBranch = headInfos[1]
+ isSameRepo = headUser.ID == baseRepo.OwnerID
} else {
ctx.Handle(404, "CompareAndPullRequest", nil)
@@ -468,24 +469,30 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
return nil, nil, nil, nil, "", ""
}
- // Check if current user has fork of repository or in the same repository.
- headRepo, has := models.HasForkedRepo(headUser.ID, baseRepo.ID)
- if !has && !isSameRepo {
- log.Trace("ParseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID)
- ctx.Handle(404, "ParseCompareInfo", nil)
- return nil, nil, nil, nil, "", ""
- }
+ var (
+ headRepo *models.Repository
+ headGitRepo *git.Repository
+ )
+
+ // In case user included redundant head user name for comparison in same repository,
+ // no need to check the fork relation.
+ if !isSameRepo {
+ var has bool
+ headRepo, has = models.HasForkedRepo(headUser.ID, baseRepo.ID)
+ if !has {
+ log.Trace("ParseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID)
+ ctx.Handle(404, "ParseCompareInfo", nil)
+ return nil, nil, nil, nil, "", ""
+ }
- var headGitRepo *git.Repository
- if isSameRepo {
- headRepo = ctx.Repo.Repository
- headGitRepo = ctx.Repo.GitRepo
- } else {
headGitRepo, err = git.OpenRepository(models.RepoPath(headUser.Name, headRepo.Name))
if err != nil {
ctx.Handle(500, "OpenRepository", err)
return nil, nil, nil, nil, "", ""
}
+ } else {
+ headRepo = ctx.Repo.Repository
+ headGitRepo = ctx.Repo.GitRepo
}
if !ctx.User.IsWriterOfRepo(headRepo) && !ctx.User.IsAdmin {