Skip to content

Commit 076eca8

Browse files
authored
Fix incorrect default branch label while switching between branches (#27053)
Fix #27008
1 parent b32998b commit 076eca8

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

templates/repo/branch_dropdown.tmpl

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* ContainerClasses
44
* (TODO: search "branch_dropdown" in the template direcotry)
55
*/}}
6-
{{$defaultBranch := $.root.BranchName}}
6+
{{$defaultSelectedRefName := $.root.BranchName}}
77
{{if and .root.IsViewTag (not .noTag)}}
8-
{{$defaultBranch = .root.TagName}}
8+
{{$defaultSelectedRefName = .root.TagName}}
99
{{end}}
10-
{{if eq $defaultBranch ""}}
11-
{{$defaultBranch = $.root.Repository.DefaultBranch}}
10+
{{if eq $defaultSelectedRefName ""}}
11+
{{$defaultSelectedRefName = $.root.Repository.DefaultBranch}}
1212
{{end}}
1313

1414
{{$type := ""}}
@@ -45,7 +45,8 @@
4545
'tagName': {{.root.TagName}},
4646
'branchName': {{.root.BranchName}},
4747
'noTag': {{.noTag}},
48-
'defaultBranch': {{$defaultBranch}},
48+
'defaultSelectedRefName': {{$defaultSelectedRefName}},
49+
'repoDefaultBranch': {{.root.Repository.DefaultBranch}},
4950
'enableFeed': {{.root.EnableFeed}},
5051
'rssURLPrefix': '{{$.root.RepoLink}}/rss/branch/',
5152
'branchURLPrefix': '{{if .branchURLPrefix}}{{.branchURLPrefix}}{{else}}{{$.root.RepoLink}}/{{if $.root.PageIsCommits}}commits{{else}}src{{end}}/branch/{{end}}',

web_src/js/components/RepoBranchTagSelector.vue

+3-4
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,15 @@ const sfc = {
190190
}
191191
this.isLoading = true;
192192
try {
193-
// the "data.defaultBranch" is ambiguous, it could be "branch name" or "tag name"
194193
const reqUrl = `${this.repoLink}/${this.mode}/list`;
195194
const resp = await fetch(reqUrl);
196195
const {results} = await resp.json();
197196
for (const result of results) {
198197
let selected = false;
199198
if (this.mode === 'branches') {
200-
selected = result === this.defaultBranch;
199+
selected = result === this.defaultSelectedRefName;
201200
} else {
202-
selected = result === (this.release ? this.release.tagName : this.defaultBranch);
201+
selected = result === (this.release ? this.release.tagName : this.defaultSelectedRefName);
203202
}
204203
this.items.push({name: result, url: pathEscapeSegments(result), branch: this.mode === 'branches', tag: this.mode === 'tags', selected});
205204
}
@@ -276,7 +275,7 @@ export default sfc; // activate IDE's Vue plugin
276275
<div class="loading-indicator is-loading" v-if="isLoading"/>
277276
<div v-for="(item, index) in filteredItems" :key="item.name" class="item" :class="{selected: item.selected, active: active === index}" @click="selectItem(item)" :ref="'listItem' + index">
278277
{{ item.name }}
279-
<div class="ui label" v-if="item.name===defaultBranch && mode === 'branches'">
278+
<div class="ui label" v-if="item.name===repoDefaultBranch && mode === 'branches'">
280279
{{ textDefaultBranchLabel }}
281280
</div>
282281
<a v-show="enableFeed && mode === 'branches'" role="button" class="rss-icon gt-float-right" :href="rssURLPrefix + item.url" target="_blank" @click.stop>

0 commit comments

Comments
 (0)