Skip to content

Commit a7ceb12

Browse files
committed
Merge branch 'lunny/refactor_reftype' of github.com:lunny/gitea into lunny/refactor_reftype
2 parents 98d7e04 + 2de6bbe commit a7ceb12

File tree

6 files changed

+94
-73
lines changed

6 files changed

+94
-73
lines changed

modules/git/ref.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package git
55

66
import (
77
"regexp"
8+
"slices"
89
"strings"
910

1011
"code.gitea.io/gitea/modules/util"
@@ -220,3 +221,11 @@ func (ref RefName) RefWebLinkPath() string {
220221
}
221222
return string(refType) + "/" + util.PathEscapeSegments(ref.ShortName())
222223
}
224+
225+
func RefNameFromUserInput(ref string, allowedTypes ...RefType) RefName {
226+
refName := RefName(ref)
227+
if !slices.Contains(allowedTypes, refName.RefType()) {
228+
return ""
229+
}
230+
return refName
231+
}

routers/web/repo/find.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ package repo
55

66
import (
77
"net/http"
8+
"net/url"
89

10+
"code.gitea.io/gitea/modules/git"
911
"code.gitea.io/gitea/modules/templates"
1012
"code.gitea.io/gitea/modules/util"
1113
"code.gitea.io/gitea/services/context"
@@ -18,7 +20,8 @@ const (
1820
// FindFiles render the page to find repository files
1921
func FindFiles(ctx *context.Context) {
2022
path := ctx.PathParam("*")
21-
ctx.Data["TreeLink"] = ctx.Repo.RepoLink + "/src/" + util.PathEscapeSegments(path)
22-
ctx.Data["DataLink"] = ctx.Repo.RepoLink + "/tree-list/" + util.PathEscapeSegments(path)
23+
ref := git.RefNameFromUserInput(ctx.FormTrim("ref"), git.RefTypeBranch, git.RefTypeTag, git.RefTypeCommit)
24+
ctx.Data["TreeLink"] = ctx.Repo.RepoLink + "/src/" + ref.RefWebLinkPath() + "/" + util.PathEscapeSegments(path)
25+
ctx.Data["DataLink"] = ctx.Repo.RepoLink + "/tree-list/" + util.PathEscapeSegments(path) + "?ref=" + url.QueryEscape(ctx.FormTrim("ref"))
2326
ctx.HTML(http.StatusOK, tplFindFiles)
2427
}

routers/web/repo/treelist.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ import (
1515

1616
// TreeList get all files' entries of a repository
1717
func TreeList(ctx *context.Context) {
18-
tree, err := ctx.Repo.Commit.SubTree("/")
18+
_, commit, err := ctx.Repo.GetRefCommit(ctx.FormString("ref"), git.RefTypeBranch, git.RefTypeTag, git.RefTypeCommit)
19+
if err != nil {
20+
ctx.ServerError("GetRefCommit", err)
21+
return
22+
}
23+
tree, err := commit.SubTree("/")
1924
if err != nil {
2025
ctx.ServerError("Repo.Commit.SubTree", err)
2126
return

routers/web/web.go

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"code.gitea.io/gitea/models/db"
1212
"code.gitea.io/gitea/models/perm"
1313
"code.gitea.io/gitea/models/unit"
14+
"code.gitea.io/gitea/modules/git"
1415
"code.gitea.io/gitea/modules/log"
1516
"code.gitea.io/gitea/modules/metrics"
1617
"code.gitea.io/gitea/modules/public"
@@ -1156,11 +1157,8 @@ func registerRoutes(m *web.Router) {
11561157

11571158
m.Group("/{username}/{reponame}", func() {
11581159
m.Get("/find/*", repo.FindFiles)
1159-
m.Group("/tree-list", func() {
1160-
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.TreeList)
1161-
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.TreeList)
1162-
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.TreeList)
1163-
})
1160+
m.Get("/find", repo.FindFiles)
1161+
m.Get("/tree-list", repo.TreeList)
11641162
m.Get("/compare", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff)
11651163
m.Combo("/compare/*", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists).
11661164
Get(repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff).
@@ -1313,9 +1311,9 @@ func registerRoutes(m *web.Router) {
13131311

13141312
m.Group("/branches", func() {
13151313
m.Group("/_new", func() {
1316-
m.Post("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.CreateBranch)
1317-
m.Post("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.CreateBranch)
1318-
m.Post("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.CreateBranch)
1314+
m.Post("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.CreateBranch)
1315+
m.Post("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.CreateBranch)
1316+
m.Post("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.CreateBranch)
13191317
}, web.Bind(forms.NewBranchForm{}))
13201318
m.Post("/delete", repo.DeleteBranchPost)
13211319
m.Post("/restore", repo.RestoreBranchPost)
@@ -1334,7 +1332,7 @@ func registerRoutes(m *web.Router) {
13341332
m.Get(".rss", feedEnabled, repo.TagsListFeedRSS)
13351333
m.Get(".atom", feedEnabled, repo.TagsListFeedAtom)
13361334
}, ctxDataSet("EnableFeed", setting.Other.EnableFeed),
1337-
repo.MustBeNotEmpty, context.RepoRefByType(context.RepoRefTag, context.RepoRefByTypeOptions{IgnoreNotExistErr: true}))
1335+
repo.MustBeNotEmpty, context.RepoRefByType(git.RefTypeTag, context.RepoRefByTypeOptions{IgnoreNotExistErr: true}))
13381336
m.Post("/tags/delete", repo.DeleteTag, reqSignIn,
13391337
repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoCodeWriter, context.RepoRef())
13401338
}, optSignIn, context.RepoAssignment, reqRepoCodeReader)
@@ -1348,7 +1346,7 @@ func registerRoutes(m *web.Router) {
13481346
m.Get(".rss", feedEnabled, repo.ReleasesFeedRSS)
13491347
m.Get(".atom", feedEnabled, repo.ReleasesFeedAtom)
13501348
}, ctxDataSet("EnableFeed", setting.Other.EnableFeed),
1351-
repo.MustBeNotEmpty, context.RepoRefByType(context.RepoRefTag, context.RepoRefByTypeOptions{IgnoreNotExistErr: true}))
1349+
repo.MustBeNotEmpty, context.RepoRefByType(git.RefTypeTag, context.RepoRefByTypeOptions{IgnoreNotExistErr: true}))
13521350
m.Get("/releases/attachments/{uuid}", repo.MustBeNotEmpty, repo.GetAttachment)
13531351
m.Get("/releases/download/{vTag}/{fileName}", repo.MustBeNotEmpty, repo.RedirectDownload)
13541352
m.Group("/releases", func() {
@@ -1521,42 +1519,42 @@ func registerRoutes(m *web.Router) {
15211519
}, repo.MustBeNotEmpty, context.RepoRef())
15221520

15231521
m.Group("/media", func() {
1524-
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.SingleDownloadOrLFS)
1525-
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.SingleDownloadOrLFS)
1526-
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.SingleDownloadOrLFS)
1522+
m.Get("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.SingleDownloadOrLFS)
1523+
m.Get("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.SingleDownloadOrLFS)
1524+
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.SingleDownloadOrLFS)
15271525
m.Get("/blob/{sha}", repo.DownloadByIDOrLFS)
15281526
// "/*" route is deprecated, and kept for backward compatibility
1529-
m.Get("/*", context.RepoRefByType(context.RepoRefUnknown), repo.SingleDownloadOrLFS)
1527+
m.Get("/*", context.RepoRefByType(""), repo.SingleDownloadOrLFS)
15301528
}, repo.MustBeNotEmpty)
15311529

15321530
m.Group("/raw", func() {
1533-
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.SingleDownload)
1534-
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.SingleDownload)
1535-
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.SingleDownload)
1531+
m.Get("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.SingleDownload)
1532+
m.Get("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.SingleDownload)
1533+
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.SingleDownload)
15361534
m.Get("/blob/{sha}", repo.DownloadByID)
15371535
// "/*" route is deprecated, and kept for backward compatibility
1538-
m.Get("/*", context.RepoRefByType(context.RepoRefUnknown), repo.SingleDownload)
1536+
m.Get("/*", context.RepoRefByType(""), repo.SingleDownload)
15391537
}, repo.MustBeNotEmpty)
15401538

15411539
m.Group("/render", func() {
1542-
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.RenderFile)
1543-
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.RenderFile)
1544-
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.RenderFile)
1540+
m.Get("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.RenderFile)
1541+
m.Get("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.RenderFile)
1542+
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.RenderFile)
15451543
m.Get("/blob/{sha}", repo.RenderFile)
15461544
}, repo.MustBeNotEmpty)
15471545

15481546
m.Group("/commits", func() {
1549-
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.RefCommits)
1550-
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.RefCommits)
1551-
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.RefCommits)
1547+
m.Get("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.RefCommits)
1548+
m.Get("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.RefCommits)
1549+
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.RefCommits)
15521550
// "/*" route is deprecated, and kept for backward compatibility
1553-
m.Get("/*", context.RepoRefByType(context.RepoRefUnknown), repo.RefCommits)
1551+
m.Get("/*", context.RepoRefByType(""), repo.RefCommits)
15541552
}, repo.MustBeNotEmpty)
15551553

15561554
m.Group("/blame", func() {
1557-
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.RefBlame)
1558-
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.RefBlame)
1559-
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.RefBlame)
1555+
m.Get("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.RefBlame)
1556+
m.Get("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.RefBlame)
1557+
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.RefBlame)
15601558
}, repo.MustBeNotEmpty)
15611559

15621560
m.Get("/blob_excerpt/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob)
@@ -1568,20 +1566,20 @@ func registerRoutes(m *web.Router) {
15681566
m.Get("/cherry-pick/{sha:([a-f0-9]{7,64})$}", repo.SetEditorconfigIfExists, repo.CherryPick)
15691567
}, repo.MustBeNotEmpty, context.RepoRef())
15701568

1571-
m.Get("/rss/branch/*", context.RepoRefByType(context.RepoRefBranch), feedEnabled, feed.RenderBranchFeed)
1572-
m.Get("/atom/branch/*", context.RepoRefByType(context.RepoRefBranch), feedEnabled, feed.RenderBranchFeed)
1569+
m.Get("/rss/branch/*", context.RepoRefByType(git.RefTypeBranch), feedEnabled, feed.RenderBranchFeed)
1570+
m.Get("/atom/branch/*", context.RepoRefByType(git.RefTypeBranch), feedEnabled, feed.RenderBranchFeed)
15731571

15741572
m.Group("/src", func() {
15751573
m.Get("", func(ctx *context.Context) { ctx.Redirect(ctx.Repo.RepoLink) }) // there is no "{owner}/{repo}/src" page, so redirect to "{owner}/{repo}" to avoid 404
1576-
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.Home)
1577-
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.Home)
1578-
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.Home)
1579-
m.Get("/*", context.RepoRefByType(context.RepoRefUnknown), repo.Home) // "/*" route is deprecated, and kept for backward compatibility
1574+
m.Get("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.Home)
1575+
m.Get("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.Home)
1576+
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.Home)
1577+
m.Get("/*", context.RepoRefByType(""), repo.Home) // "/*" route is deprecated, and kept for backward compatibility
15801578
}, repo.SetEditorconfigIfExists)
15811579

15821580
m.Get("/forks", context.RepoRef(), repo.Forks)
15831581
m.Get("/commit/{sha:([a-f0-9]{7,64})}.{ext:patch|diff}", repo.MustBeNotEmpty, repo.RawDiff)
1584-
m.Post("/lastcommit/*", context.RepoRefByType(context.RepoRefCommit), repo.LastCommit)
1582+
m.Post("/lastcommit/*", context.RepoRefByType(git.RefTypeCommit), repo.LastCommit)
15851583
}, optSignIn, context.RepoAssignment, reqRepoCodeReader)
15861584
// end "/{username}/{reponame}": repo code
15871585

services/context/repo.go

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ func (r *Repository) GetObjectFormat() git.ObjectFormat {
9191
return git.ObjectFormatFromName(r.Repository.ObjectFormatName)
9292
}
9393

94+
func (r *Repository) GetRefCommit(ref string, allowedTypes ...git.RefType) (git.RefName, *git.Commit, error) {
95+
refName := git.RefNameFromUserInput(ref, allowedTypes...)
96+
if refName == "" {
97+
return "", nil, errors.New("invalid ref")
98+
}
99+
commitID, err := r.GitRepo.GetRefCommitID(refName.String())
100+
if err != nil {
101+
return "", nil, err
102+
}
103+
commit, err := r.GitRepo.GetCommit(commitID)
104+
if err != nil {
105+
return "", nil, err
106+
}
107+
return refName, commit, nil
108+
}
109+
94110
// RepoMustNotBeArchived checks if a repo is archived
95111
func RepoMustNotBeArchived() func(ctx *Context) {
96112
return func(ctx *Context) {
@@ -677,24 +693,13 @@ func RepoAssignment(ctx *Context) {
677693
}
678694
}
679695

680-
// RepoRefType type of repo reference
681-
type RepoRefType int
682-
683-
const (
684-
// RepoRefUnknown is for legacy support, makes the code to "guess" the ref type
685-
RepoRefUnknown RepoRefType = iota
686-
RepoRefBranch
687-
RepoRefTag
688-
RepoRefCommit
689-
)
690-
691696
const headRefName = "HEAD"
692697

693698
// RepoRef handles repository reference names when the ref name is not
694699
// explicitly given
695700
func RepoRef() func(*Context) {
696701
// since no ref name is explicitly specified, ok to just use branch
697-
return RepoRefByType(RepoRefBranch)
702+
return RepoRefByType(git.RefTypeBranch)
698703
}
699704

700705
func getRefNameFromPath(repo *Repository, path string, isExist func(string) bool) string {
@@ -710,29 +715,29 @@ func getRefNameFromPath(repo *Repository, path string, isExist func(string) bool
710715
return ""
711716
}
712717

713-
func getRefNameLegacy(ctx *Base, repo *Repository, reqPath, extraRef string) (string, RepoRefType) {
718+
func getRefNameLegacy(ctx *Base, repo *Repository, reqPath, extraRef string) (string, git.RefType) {
714719
reqRefPath := path.Join(extraRef, reqPath)
715720
reqRefPathParts := strings.Split(reqRefPath, "/")
716-
if refName := getRefName(ctx, repo, reqRefPath, RepoRefBranch); refName != "" {
717-
return refName, RepoRefBranch
721+
if refName := getRefName(ctx, repo, reqRefPath, git.RefTypeBranch); refName != "" {
722+
return refName, git.RefTypeBranch
718723
}
719-
if refName := getRefName(ctx, repo, reqRefPath, RepoRefTag); refName != "" {
720-
return refName, RepoRefTag
724+
if refName := getRefName(ctx, repo, reqRefPath, git.RefTypeTag); refName != "" {
725+
return refName, git.RefTypeTag
721726
}
722727
if git.IsStringLikelyCommitID(git.ObjectFormatFromName(repo.Repository.ObjectFormatName), reqRefPathParts[0]) {
723728
// FIXME: this logic is different from other types. Ideally, it should also try to GetCommit to check if it exists
724729
repo.TreePath = strings.Join(reqRefPathParts[1:], "/")
725-
return reqRefPathParts[0], RepoRefCommit
730+
return reqRefPathParts[0], git.RefTypeCommit
726731
}
727732
// FIXME: the old code falls back to default branch if "ref" doesn't exist, there could be an edge case:
728733
// "README?ref=no-such" would read the README file from the default branch, but the user might expect a 404
729734
repo.TreePath = reqPath
730-
return repo.Repository.DefaultBranch, RepoRefBranch
735+
return repo.Repository.DefaultBranch, git.RefTypeBranch
731736
}
732737

733-
func getRefName(ctx *Base, repo *Repository, path string, pathType RepoRefType) string {
734-
switch pathType {
735-
case RepoRefBranch:
738+
func getRefName(ctx *Base, repo *Repository, path string, refType git.RefType) string {
739+
switch refType {
740+
case git.RefTypeBranch:
736741
ref := getRefNameFromPath(repo, path, repo.GitRepo.IsBranchExist)
737742
if len(ref) == 0 {
738743
// check if ref is HEAD
@@ -762,9 +767,9 @@ func getRefName(ctx *Base, repo *Repository, path string, pathType RepoRefType)
762767
}
763768

764769
return ref
765-
case RepoRefTag:
770+
case git.RefTypeTag:
766771
return getRefNameFromPath(repo, path, repo.GitRepo.IsTagExist)
767-
case RepoRefCommit:
772+
case git.RefTypeCommit:
768773
parts := strings.Split(path, "/")
769774
if git.IsStringLikelyCommitID(repo.GetObjectFormat(), parts[0], 7) {
770775
// FIXME: this logic is different from other types. Ideally, it should also try to GetCommit to check if it exists
@@ -782,7 +787,7 @@ func getRefName(ctx *Base, repo *Repository, path string, pathType RepoRefType)
782787
return commit.ID.String()
783788
}
784789
default:
785-
panic(fmt.Sprintf("Unrecognized path type: %v", pathType))
790+
panic(fmt.Sprintf("Unrecognized ref type: %v", refType))
786791
}
787792
return ""
788793
}
@@ -791,13 +796,13 @@ type RepoRefByTypeOptions struct {
791796
IgnoreNotExistErr bool
792797
}
793798

794-
func repoRefFullName(shortName string, typ RepoRefType) git.RefName {
799+
func repoRefFullName(typ git.RefType, shortName string) git.RefName {
795800
switch typ {
796-
case RepoRefBranch:
801+
case git.RefTypeBranch:
797802
return git.RefNameFromBranch(shortName)
798-
case RepoRefTag:
803+
case git.RefTypeTag:
799804
return git.RefNameFromTag(shortName)
800-
case RepoRefCommit:
805+
case git.RefTypeCommit:
801806
return git.RefNameFromCommit(shortName)
802807
default:
803808
setting.PanicInDevOrTesting("Unknown RepoRefType: %v", typ)
@@ -807,7 +812,7 @@ func repoRefFullName(shortName string, typ RepoRefType) git.RefName {
807812

808813
// RepoRefByType handles repository reference name for a specific type
809814
// of repository reference
810-
func RepoRefByType(detectRefType RepoRefType, opts ...RepoRefByTypeOptions) func(*Context) {
815+
func RepoRefByType(detectRefType git.RefType, opts ...RepoRefByTypeOptions) func(*Context) {
811816
opt := util.OptionalArg(opts)
812817
return func(ctx *Context) {
813818
var err error
@@ -861,13 +866,13 @@ func RepoRefByType(detectRefType RepoRefType, opts ...RepoRefByTypeOptions) func
861866
}
862867
ctx.Repo.IsViewBranch = true
863868
} else { // there is a path in request
864-
guessLegacyPath := refType == RepoRefUnknown
869+
guessLegacyPath := refType == ""
865870
if guessLegacyPath {
866871
refShortName, refType = getRefNameLegacy(ctx.Base, ctx.Repo, reqPath, "")
867872
} else {
868873
refShortName = getRefName(ctx.Base, ctx.Repo, reqPath, refType)
869874
}
870-
ctx.Repo.RefFullName = repoRefFullName(refShortName, refType)
875+
ctx.Repo.RefFullName = repoRefFullName(refType, refShortName)
871876
isRenamedBranch, has := ctx.Data["IsRenamedBranch"].(bool)
872877
if isRenamedBranch && has {
873878
renamedBranchName := ctx.Data["RenamedBranchName"].(string)
@@ -877,7 +882,7 @@ func RepoRefByType(detectRefType RepoRefType, opts ...RepoRefByTypeOptions) func
877882
return
878883
}
879884

880-
if refType == RepoRefBranch && ctx.Repo.GitRepo.IsBranchExist(refShortName) {
885+
if refType == git.RefTypeBranch && ctx.Repo.GitRepo.IsBranchExist(refShortName) {
881886
ctx.Repo.IsViewBranch = true
882887
ctx.Repo.BranchName = refShortName
883888
ctx.Repo.RefFullName = git.RefNameFromBranch(refShortName)
@@ -888,7 +893,7 @@ func RepoRefByType(detectRefType RepoRefType, opts ...RepoRefByTypeOptions) func
888893
return
889894
}
890895
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
891-
} else if refType == RepoRefTag && ctx.Repo.GitRepo.IsTagExist(refShortName) {
896+
} else if refType == git.RefTypeTag && ctx.Repo.GitRepo.IsTagExist(refShortName) {
892897
ctx.Repo.IsViewTag = true
893898
ctx.Repo.RefFullName = git.RefNameFromTag(refShortName)
894899
ctx.Repo.TagName = refShortName

templates/repo/home.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262

6363
<!-- Show go to file if on home page -->
6464
{{if $isTreePathRoot}}
65-
<a href="{{.Repository.Link}}/find/{{.RefTypeNameSubURL}}" class="ui compact basic button">{{ctx.Locale.Tr "repo.find_file.go_to_file"}}</a>
65+
{{/* FIXME: it should still use RefTypeNameSubURL, otherwise the link is ugly */}}
66+
<a href="{{.Repository.Link}}/find/{{.TreePath}}?ref={{.RefFullName}}" class="ui compact basic button">{{ctx.Locale.Tr "repo.find_file.go_to_file"}}</a>
6667
{{end}}
6768

6869
{{if and .CanWriteCode .IsViewBranch (not .Repository.IsMirror) (not .Repository.IsArchived) (not .IsViewFile)}}

0 commit comments

Comments
 (0)