diff --git a/routers/repo/compare.go b/routers/repo/compare.go index f8534f68b77..b9e14abfb87 100644 --- a/routers/repo/compare.go +++ b/routers/repo/compare.go @@ -339,12 +339,40 @@ func PrepareCompareDiff( return false } +// parseBaseRepoInfo parse base repository if current repo is forked. +// The "base" here means the repository where current repo forks from, +// not the repository fetch from current URL. +func parseBaseRepoInfo(ctx *context.Context, repo *models.Repository) error { + if !repo.IsFork { + return nil + } + if err := repo.GetBaseRepo(); err != nil { + return err + } + if err := repo.BaseRepo.GetOwnerName(); err != nil { + return err + } + baseGitRepo, err := git.OpenRepository(models.RepoPath(repo.BaseRepo.OwnerName, repo.BaseRepo.Name)) + if err != nil { + return err + } + ctx.Data["BaseRepoBranches"], err = baseGitRepo.GetBranches() + if err != nil { + return err + } + return nil +} + // CompareDiff show different from one commit to another commit func CompareDiff(ctx *context.Context) { headUser, headRepo, headGitRepo, compareInfo, baseBranch, headBranch := ParseCompareInfo(ctx) if ctx.Written() { return } + if err := parseBaseRepoInfo(ctx, headRepo); err != nil { + ctx.ServerError("parseBaseRepoInfo", err) + return + } nothingToCompare := PrepareCompareDiff(ctx, headUser, headRepo, headGitRepo, compareInfo, baseBranch, headBranch) if ctx.Written() { diff --git a/templates/repo/diff/compare.tmpl b/templates/repo/diff/compare.tmpl index 1c8942d42fe..50a51c44acc 100644 --- a/templates/repo/diff/compare.tmpl +++ b/templates/repo/diff/compare.tmpl @@ -28,6 +28,11 @@ {{range .Branches}}
{{$.BaseName}}:{{.}}
{{end}} + {{if .Repository.IsFork}} + {{range .BaseRepoBranches}} +
{{$.PullRequestCtx.BaseRepo.OwnerName}}:{{.}}
+ {{end}} + {{end}} @@ -54,7 +59,7 @@ {{if .IsNothingToCompare}}
{{.i18n.Tr "repo.pulls.nothing_to_compare"}}
- {{else if .PageIsComparePull}} + {{else if .PageIsComparePull}} {{if .HasPullRequest}}
{{.i18n.Tr "repo.pulls.has_pull_request" $.RepoLink $.RepoRelPath .PullRequest.Index | Safe}} diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index 9b354a6800b..d68e6dac26b 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -14,7 +14,7 @@ {{if .PageIsIssueList}} {{.i18n.Tr "repo.issues.new"}} {{else}} - {{.i18n.Tr "repo.pulls.new"}} + {{.i18n.Tr "repo.pulls.new"}} {{end}}
{{else}}