diff --git a/modules/context/repo.go b/modules/context/repo.go index 1836373918..ddb63150b1 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -1086,6 +1086,9 @@ func (ctx *Context) IssueTemplatesFromDefaultBranch() []api.IssueTemplate { } it.Content = content it.FileName = entry.Name() + if !strings.HasPrefix(it.Ref, "refs/") { // Assume that the ref intended is always a branch - for tags users should use refs/tags/ + it.Ref = "refs/heads/" + it.Ref + } if it.Valid() { issueTemplates = append(issueTemplates, it) } diff --git a/modules/git/utils.go b/modules/git/utils.go index d6bf9f4413..1a7041433d 100644 --- a/modules/git/utils.go +++ b/modules/git/utils.go @@ -100,6 +100,9 @@ func RefURL(repoURL, ref string) string { return repoURL + "/src/branch/" + refName case strings.HasPrefix(ref, TagPrefix): return repoURL + "/src/tag/" + refName + case !SHAPattern.MatchString(ref): + // assume they mean a branch + return repoURL + "/src/branch/" + refName default: return repoURL + "/src/commit/" + refName } diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index e6f9529e31..6856c1e0be 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -782,6 +782,10 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleDirs, } } } + if !strings.HasPrefix(meta.Ref, "refs/") { // Assume that the ref intended is always a branch - for tags users should use refs/tags/ + meta.Ref = "refs/heads/" + meta.Ref + } + ctx.Data["HasSelectedLabel"] = len(labelIDs) > 0 ctx.Data["label_ids"] = strings.Join(labelIDs, ",") ctx.Data["Reference"] = meta.Ref diff --git a/services/issue/issue.go b/services/issue/issue.go index 7131829b03..2ea7f06b15 100644 --- a/services/issue/issue.go +++ b/services/issue/issue.go @@ -18,7 +18,6 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/storage" - "code.gitea.io/gitea/modules/util" ) // NewIssue creates new issue with labels for repository. @@ -201,7 +200,7 @@ func GetRefEndNamesAndURLs(issues []*issues_model.Issue, repoLink string) (map[i for _, issue := range issues { if issue.Ref != "" { issueRefEndNames[issue.ID] = git.RefEndName(issue.Ref) - issueRefURLs[issue.ID] = git.RefURL(repoLink, util.PathEscapeSegments(issue.Ref)) + issueRefURLs[issue.ID] = git.RefURL(repoLink, issue.Ref) } } return issueRefEndNames, issueRefURLs