diff options
author | John Olheiser <john.olheiser@gmail.com> | 2021-12-06 11:04:07 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-06 11:04:07 -0600 |
commit | eb69c7ec8c1f732c67978355f6efff1f7dfe2fac (patch) | |
tree | b5316bde870689751c3167b75f1d6463c3fb13a7 /routers/web/repo/compare.go | |
parent | 12a42baa5ed5f5b5224f7c775b8be04b3eb4980c (diff) | |
download | gitea-eb69c7ec8c1f732c67978355f6efff1f7dfe2fac.tar.gz gitea-eb69c7ec8c1f732c67978355f6efff1f7dfe2fac.zip |
Allow default branch to be inferred on compare page (#17908)
* Allow default branch to be inferred
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Add test for inferred default branch
Signed-off-by: jolheiser <john.olheiser@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'routers/web/repo/compare.go')
-rw-r--r-- | routers/web/repo/compare.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 865a734caf..54d7e77f2d 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -186,6 +186,9 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { // 1. /{:baseOwner}/{:baseRepoName}/compare/{:baseBranch}...{:headBranch} // 2. /{:baseOwner}/{:baseRepoName}/compare/{:baseBranch}...{:headOwner}:{:headBranch} // 3. /{:baseOwner}/{:baseRepoName}/compare/{:baseBranch}...{:headOwner}/{:headRepoName}:{:headBranch} + // 4. /{:baseOwner}/{:baseRepoName}/compare/{:headBranch} + // 5. /{:baseOwner}/{:baseRepoName}/compare/{:headOwner}:{:headBranch} + // 6. /{:baseOwner}/{:baseRepoName}/compare/{:headOwner}/{:headRepoName}:{:headBranch} // // Here we obtain the infoPath "{:baseBranch}...[{:headOwner}/{:headRepoName}:]{:headBranch}" as ctx.Params("*") // with the :baseRepo in ctx.Repo. @@ -213,9 +216,12 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { infos := strings.SplitN(infoPath, "...", 2) if len(infos) != 2 { - infos = strings.SplitN(infoPath, "..", 2) - ci.DirectComparison = true - ctx.Data["PageIsComparePull"] = false + infos = []string{baseRepo.DefaultBranch, infoPath} + if strings.Contains(infoPath, "..") { + infos = strings.SplitN(infoPath, "..", 2) + ci.DirectComparison = true + ctx.Data["PageIsComparePull"] = false + } } if len(infos) != 2 { |