Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow default branch to be inferred on compare page #17908

Merged
merged 4 commits into from
Dec 6, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions routers/web/repo/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down