mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: handle commit file path
This commit is contained in:
parent
7fd7abb070
commit
ac44c8f76f
1 changed files with 20 additions and 9 deletions
|
|
@ -42,21 +42,32 @@ function isInCodePage(metaData = {}) {
|
|||
)
|
||||
}
|
||||
|
||||
function isCommitPath(path) {
|
||||
return /^[a-z0-9]{40}$/.test(path[0])
|
||||
}
|
||||
|
||||
function getCurrentPath(branchName = '') {
|
||||
const { path, type } = parse()
|
||||
const slicedBranchName = branchName.split('/')
|
||||
if (type === 'blob' || type === 'tree') {
|
||||
while (slicedBranchName.length) {
|
||||
if (slicedBranchName[0] === path[0]) {
|
||||
slicedBranchName.shift()
|
||||
path.shift()
|
||||
} else {
|
||||
raiseError(new Error(`branch name and path prefix not match`))
|
||||
return []
|
||||
if (isCommitPath(path)) {
|
||||
// path = commit-SHA/path/to/item
|
||||
path.shift()
|
||||
} else {
|
||||
// path = branch/name/path/to/item
|
||||
const slicedBranchName = branchName.split('/')
|
||||
while (slicedBranchName.length) {
|
||||
if (slicedBranchName[0] === path[0]) {
|
||||
slicedBranchName.shift()
|
||||
path.shift()
|
||||
} else {
|
||||
raiseError(new Error(`branch name and path prefix not match`))
|
||||
return []
|
||||
}
|
||||
}
|
||||
}
|
||||
return path.map(decodeURIComponent)
|
||||
}
|
||||
return path.map(decodeURIComponent)
|
||||
return []
|
||||
}
|
||||
|
||||
export default {
|
||||
|
|
|
|||
Loading…
Reference in a new issue