From 076eca81587a286b2392e37beddc6d92a1849bb5 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 14 Sep 2023 12:54:25 +0900 Subject: [PATCH] Fix incorrect default branch label while switching between branches (#27053) Fix #27008 --- templates/repo/branch_dropdown.tmpl | 11 ++++++----- web_src/js/components/RepoBranchTagSelector.vue | 7 +++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/templates/repo/branch_dropdown.tmpl b/templates/repo/branch_dropdown.tmpl index 79eff1c53a..d826eee4f6 100644 --- a/templates/repo/branch_dropdown.tmpl +++ b/templates/repo/branch_dropdown.tmpl @@ -3,12 +3,12 @@ * ContainerClasses * (TODO: search "branch_dropdown" in the template direcotry) */}} -{{$defaultBranch := $.root.BranchName}} +{{$defaultSelectedRefName := $.root.BranchName}} {{if and .root.IsViewTag (not .noTag)}} - {{$defaultBranch = .root.TagName}} + {{$defaultSelectedRefName = .root.TagName}} {{end}} -{{if eq $defaultBranch ""}} - {{$defaultBranch = $.root.Repository.DefaultBranch}} +{{if eq $defaultSelectedRefName ""}} + {{$defaultSelectedRefName = $.root.Repository.DefaultBranch}} {{end}} {{$type := ""}} @@ -45,7 +45,8 @@ 'tagName': {{.root.TagName}}, 'branchName': {{.root.BranchName}}, 'noTag': {{.noTag}}, - 'defaultBranch': {{$defaultBranch}}, + 'defaultSelectedRefName': {{$defaultSelectedRefName}}, + 'repoDefaultBranch': {{.root.Repository.DefaultBranch}}, 'enableFeed': {{.root.EnableFeed}}, 'rssURLPrefix': '{{$.root.RepoLink}}/rss/branch/', 'branchURLPrefix': '{{if .branchURLPrefix}}{{.branchURLPrefix}}{{else}}{{$.root.RepoLink}}/{{if $.root.PageIsCommits}}commits{{else}}src{{end}}/branch/{{end}}', diff --git a/web_src/js/components/RepoBranchTagSelector.vue b/web_src/js/components/RepoBranchTagSelector.vue index b64b66d181..30bff6d23f 100644 --- a/web_src/js/components/RepoBranchTagSelector.vue +++ b/web_src/js/components/RepoBranchTagSelector.vue @@ -190,16 +190,15 @@ const sfc = { } this.isLoading = true; try { - // the "data.defaultBranch" is ambiguous, it could be "branch name" or "tag name" const reqUrl = `${this.repoLink}/${this.mode}/list`; const resp = await fetch(reqUrl); const {results} = await resp.json(); for (const result of results) { let selected = false; if (this.mode === 'branches') { - selected = result === this.defaultBranch; + selected = result === this.defaultSelectedRefName; } else { - selected = result === (this.release ? this.release.tagName : this.defaultBranch); + selected = result === (this.release ? this.release.tagName : this.defaultSelectedRefName); } this.items.push({name: result, url: pathEscapeSegments(result), branch: this.mode === 'branches', tag: this.mode === 'tags', selected}); } @@ -276,7 +275,7 @@ export default sfc; // activate IDE's Vue plugin
{{ item.name }} -
+
{{ textDefaultBranchLabel }}