diff --git a/app/assets/javascripts/pages/projects/project.js b/app/assets/javascripts/pages/projects/project.js index da8dc527d79f72827b593dac268b08bbf65c389c..91f376060f882d763f7f51d50a34cb6dbef23a58 100644 --- a/app/assets/javascripts/pages/projects/project.js +++ b/app/assets/javascripts/pages/projects/project.js @@ -123,10 +123,19 @@ export default class Project { const loc = window.location.href; if (loc.includes('/-/')) { - const refs = this.fullData.Branches.concat(this.fullData.Tags); - const currentRef = refs.find((ref) => loc.indexOf(ref) > -1); - if (currentRef) { - const targetPath = loc.split(currentRef)[1].slice(1).split('#')[0]; + // Since the current ref in renderRow is outdated on page changes + // (To be addressed in: https://gitlab.com/gitlab-org/gitlab/-/issues/327085) + // We are deciphering the current ref from the dropdown data instead + const currentRef = $dropdown.data('ref'); + // The split and startWith is to ensure an exact word match + // and avoid partial match ie. currentRef is "dev" and loc is "development" + const splitPathAfterRefPortion = loc.split(currentRef)[1]; + const doesPathContainRef = splitPathAfterRefPortion?.startsWith('/'); + + if (doesPathContainRef) { + // We are ignoring the url containing the ref portion + // and plucking the thereafter portion to reconstructure the url that is correct + const targetPath = splitPathAfterRefPortion?.slice(1).split('#')[0]; selectedUrl.searchParams.set('path', targetPath); selectedUrl.hash = window.location.hash; } diff --git a/changelogs/unreleased/322792-switch-branch-of-shorter-name.yml b/changelogs/unreleased/322792-switch-branch-of-shorter-name.yml new file mode 100644 index 0000000000000000000000000000000000000000..f9eddc86b8c83688782ecbec0bdd7d1d561dccb1 --- /dev/null +++ b/changelogs/unreleased/322792-switch-branch-of-shorter-name.yml @@ -0,0 +1,5 @@ +--- +title: Fix branch switch to be exact instead of partial match +merge_request: 57197 +author: +type: fixed