mirror of
https://github.com/stablyai/orca.git
synced 2026-10-13 00:02:54 +00:00
Preserve complete branch selectors when Git truncates or disambiguates short names, and keep slash-named local branches separate from remote-tracking refs through worktree creation and reuse. Keep native/SSH namespace boundaries and mixed-version client capability gates intact. Accept Git-valid dotted components and cover collisions with configured and orphan tracking refs. Adapted from @nishino-tsukasa's #19540. Independently reviewed in seven adversarial rounds; 235 focused tests and 77 affected-Apple-Git tests pass, along with typecheck, quality checks, and the desktop build. Correct the inherited file-explorer cache-scan expectation while retaining its exact constant-work bound. Correct the inherited release-parser compatibility assertion to match the pinned test dependency; all 121 cross-version tests pass locally. Fixes #19515 Co-authored-by: kino <nishinotsukasavirgo@gmail.com>
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
const REF_PREFIX = 'refs/'
|
|
const LOCAL_BRANCH_REF_PREFIX = 'refs/heads/'
|
|
const WORKTREE_REF_PREFIXES = ['refs/bisect/', 'refs/rewritten/', 'refs/worktree/']
|
|
const FORBIDDEN_REF_CHARS = '~^:?*[\\'
|
|
|
|
function hasForbiddenRefChar(ref: string): boolean {
|
|
for (const char of ref) {
|
|
const code = char.charCodeAt(0)
|
|
if (code <= 0x20 || code === 0x7f || FORBIDDEN_REF_CHARS.includes(char)) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
export function isSafeGitRefName(ref: string): boolean {
|
|
if (!ref.startsWith(REF_PREFIX) || ref.endsWith('/') || ref.endsWith('.')) {
|
|
return false
|
|
}
|
|
if (ref.includes('..') || ref.includes('@{') || hasForbiddenRefChar(ref)) {
|
|
return false
|
|
}
|
|
const parts = ref.split('/')
|
|
return (
|
|
parts.length >= 2 &&
|
|
parts.every(
|
|
(part) =>
|
|
part.length > 0 &&
|
|
part !== '.' &&
|
|
part !== '..' &&
|
|
!part.startsWith('.') &&
|
|
!part.endsWith('.lock')
|
|
)
|
|
)
|
|
}
|
|
|
|
export function isSafeGitStatusUpstreamRef(ref: string): boolean {
|
|
return (
|
|
isSafeGitRefName(ref) &&
|
|
ref !== 'refs/heads' &&
|
|
!ref.startsWith(LOCAL_BRANCH_REF_PREFIX) &&
|
|
!WORKTREE_REF_PREFIXES.some((prefix) => ref === prefix.slice(0, -1) || ref.startsWith(prefix))
|
|
)
|
|
}
|