]> source.dussan.org Git - gitea.git/commitdiff
Fix generating compare link (#21519) (#21530)
authorLunny Xiao <xiaolunwen@gmail.com>
Fri, 21 Oct 2022 12:59:27 +0000 (20:59 +0800)
committerGitHub <noreply@github.com>
Fri, 21 Oct 2022 12:59:27 +0000 (20:59 +0800)
Fix #6318, backport #21519

Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: zeripath <art27@cantab.net>
modules/templates/helper.go
templates/repo/home.tmpl

index 2ea7bdacc69553b01cc155e0567b6feb044c14d8..61f1f6adad0ca19ef5d81505bcabc55a62909c48 100644 (file)
@@ -458,6 +458,19 @@ func NewFuncMap() []template.FuncMap {
                        return items
                },
                "HasPrefix": strings.HasPrefix,
+               "CompareLink": func(baseRepo, repo *repo_model.Repository, branchName string) string {
+                       var curBranch string
+                       if repo.ID != baseRepo.ID {
+                               curBranch += fmt.Sprintf("%s/%s:", url.PathEscape(repo.OwnerName), url.PathEscape(repo.Name))
+                       }
+                       curBranch += util.PathEscapeSegments(branchName)
+
+                       return fmt.Sprintf("%s/compare/%s...%s",
+                               baseRepo.Link(),
+                               util.PathEscapeSegments(baseRepo.DefaultBranch),
+                               curBranch,
+                       )
+               },
        }}
 }
 
index 18c02aa9ecac58cce364482b8a62b8243a928d23..a24aa52247e5ceb2439fb41c2fd213fa05b0bbba 100644 (file)
@@ -68,7 +68,7 @@
                                <!-- If home page, show new PR. If not, show breadcrumb -->
                                {{if eq $n 0}}
                                        {{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}}
-                                               <a href="{{.BaseRepo.Link}}/compare/{{PathEscapeSegments .BaseRepo.DefaultBranch}}...{{if ne .Repository.Owner.Name .BaseRepo.Owner.Name}}{{PathEscape .Repository.Owner.Name}}{{if .BaseRepo.IsFork}}/{{PathEscape .Repository.Name}}{{end}}:{{end}}{{PathEscapeSegments .BranchName}}">
+                                               <a href="{{CompareLink .BaseRepo .Repository .BranchName}}">
                                                        <button id="new-pull-request" class="ui compact basic button tooltip" data-content="{{if .PullRequestCtx.Allowed}}{{.i18n.Tr "repo.pulls.compare_changes"}}{{else}}{{.i18n.Tr "action.compare_branch"}}{{end}}"><span class="text">{{svg "octicon-git-pull-request"}}</span></button>
                                                </a>
                                        {{end}}