revert: getBasePath() logic to original

This commit is contained in:
Martin Fillafer 2023-03-20 15:28:36 +01:00
parent cdfbf90a4e
commit 3606ee2f36
2 changed files with 30 additions and 13 deletions

View file

@ -23,21 +23,17 @@ export function getBasePath(path: string, trackedFiles: string[]): string | unde
return ''
}
let max = ''
for (const file of trackedFiles) {
const pathParts = path.split('/')
const originalLength = pathParts.length
const fileParts = file.split('/')
while (pathParts.length && pathParts.slice(-1)[0] === fileParts.slice(-1)[0]) {
pathParts.pop()
fileParts.pop()
}
// we found some matching path parts
if (pathParts.length !== originalLength) {
return pathParts.join('/')
if (path.endsWith(file) && file.length > max.length) {
max = file
}
}
return undefined
if (max === '') {
return undefined
}
const base = path.substr(0, path.length - max.length)
return base
}