Commit 07dbcb6d authored by Simon Knox's avatar Simon Knox

Merge branch '322792-switch-branch-of-shorter-name' into 'master'

Fix broken branch switch with similar names

See merge request gitlab-org/gitlab!57197
parents e2f53abf ef4d3542
......@@ -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;
}
......
---
title: Fix branch switch to be exact instead of partial match
merge_request: 57197
author:
type: fixed
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment