Skip to content

Commit 7794a97

Browse files
committed
Fix redirects to new URL scheme, and update template
1 parent 6780594 commit 7794a97

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

modules/context/repo.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,16 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
521521
return ""
522522
}
523523

524+
// URL to redirect to for deprecated URL scheme
525+
func repoRefRedirect(ctx *Context) string {
526+
urlPath := ctx.Req.URL.String()
527+
idx := strings.LastIndex(urlPath, ctx.Params("*"))
528+
if idx < 0 {
529+
idx = len(urlPath)
530+
}
531+
return path.Join(urlPath[:idx], ctx.Repo.BranchNameSubURL())
532+
}
533+
524534
// RepoRefByType handles repository reference name for a specific type
525535
// of repository reference
526536
func RepoRefByType(refType RepoRefType) macaron.Handler {
@@ -548,6 +558,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
548558
// Get default branch.
549559
if len(ctx.Params("*")) == 0 {
550560
refName = ctx.Repo.Repository.DefaultBranch
561+
ctx.Repo.BranchName = refName
551562
if !ctx.Repo.GitRepo.IsBranchExist(refName) {
552563
brs, err := ctx.Repo.GitRepo.GetBranches()
553564
if err != nil {
@@ -571,6 +582,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
571582

572583
} else {
573584
refName = getRefName(ctx, refType)
585+
ctx.Repo.BranchName = refName
574586
if ctx.Repo.GitRepo.IsBranchExist(refName) {
575587
ctx.Repo.IsViewBranch = true
576588

@@ -605,15 +617,11 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
605617

606618
if refType == RepoRefUnknown {
607619
// redirect from old URL scheme to new URL scheme
608-
ctx.Redirect(path.Join(
609-
ctx.Repo.BranchNameSubURL(),
610-
ctx.Repo.TreePath,
611-
))
620+
ctx.Redirect(repoRefRedirect(ctx))
612621
return
613622
}
614623
}
615624

616-
ctx.Repo.BranchName = refName
617625
ctx.Data["BranchName"] = ctx.Repo.BranchName
618626
ctx.Data["BranchNameSubURL"] = ctx.Repo.BranchNameSubURL()
619627
ctx.Data["CommitID"] = ctx.Repo.CommitID

templates/repo/branch_dropdown.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
</div>
1111
<div class="data" style="display: none" data-mode="{{if .IsViewTag}}tags{{else}}branches{{end}}">
1212
{{range .Branches}}
13-
<div class="item branch {{if eq $.BranchName .}}selected{{end}}" data-url="{{$.RepoLink}}/{{if $.PageIsCommits}}commits{{else}}src{{end}}/{{EscapePound .}}{{if $.TreePath}}/{{EscapePound $.TreePath}}{{end}}">{{.}}</div>
13+
<div class="item branch {{if eq $.BranchName .}}selected{{end}}" data-url="{{$.RepoLink}}/{{if $.PageIsCommits}}commits{{else}}src{{end}}/branch/{{EscapePound .}}{{if $.TreePath}}/{{EscapePound $.TreePath}}{{end}}">{{.}}</div>
1414
{{end}}
1515
{{range .Tags}}
16-
<div class="item tag {{if eq $.BranchName .}}selected{{end}}" data-url="{{$.RepoLink}}/{{if $.PageIsCommits}}commits{{else}}src{{end}}/{{EscapePound .}}{{if $.TreePath}}/{{EscapePound $.TreePath}}{{end}}">{{.}}</div>
16+
<div class="item tag {{if eq $.BranchName .}}selected{{end}}" data-url="{{$.RepoLink}}/{{if $.PageIsCommits}}commits{{else}}src{{end}}/tag/{{EscapePound .}}{{if $.TreePath}}/{{EscapePound $.TreePath}}{{end}}">{{.}}</div>
1717
{{end}}
1818
</div>
1919
<div class="menu transition" :class="{visible: menuVisible}" v-if="menuVisible" v-cloak>

0 commit comments

Comments
 (0)