summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-10-21 16:39:26 +0800
committerGitHub <noreply@github.com>2022-10-21 16:39:26 +0800
commit16cbd5b59ccba3e418ba0c4c345eb2778ef1d15a (patch)
tree91cf3bdd9099e9dcbc7eee05ad5663942c11edfb /modules
parentda3b657c455833f6732d811a410861dc8cfb1bc3 (diff)
downloadgitea-16cbd5b59ccba3e418ba0c4c345eb2778ef1d15a.tar.gz
gitea-16cbd5b59ccba3e418ba0c4c345eb2778ef1d15a.zip
Fix generating compare link (#21519)
Fix #6318 Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules')
-rw-r--r--modules/templates/helper.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index 7bd2bc0a1c..a723291440 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -459,6 +459,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,
+ )
+ },
}}
}