mirror of
https://github.com/stablyai/orca.git
synced 2026-10-08 16:02:37 +00:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { WORKTREE_ID_SEPARATOR } from './pty-session-id-format'
|
|
|
|
export { WORKTREE_ID_SEPARATOR } from './pty-session-id-format'
|
|
|
|
export type ParsedWorktreeId = {
|
|
repoId: string
|
|
worktreePath: string
|
|
}
|
|
|
|
export function getRepoIdFromWorktreeId(worktreeId: string): string {
|
|
const separatorIdx = worktreeId.indexOf(WORKTREE_ID_SEPARATOR)
|
|
return separatorIdx === -1 ? worktreeId : worktreeId.slice(0, separatorIdx)
|
|
}
|
|
|
|
export function splitWorktreeId(worktreeId: string): ParsedWorktreeId | null {
|
|
const separatorIdx = worktreeId.indexOf(WORKTREE_ID_SEPARATOR)
|
|
if (separatorIdx === -1) {
|
|
return null
|
|
}
|
|
return {
|
|
repoId: worktreeId.slice(0, separatorIdx),
|
|
worktreePath: worktreeId.slice(separatorIdx + WORKTREE_ID_SEPARATOR.length)
|
|
}
|
|
}
|
|
|
|
export function getWorktreePathBasenameFromId(worktreeId: string): string | null {
|
|
const parsed = splitWorktreeId(worktreeId)
|
|
const normalizedPath = parsed?.worktreePath.trim().replace(/[\\/]+$/g, '') ?? ''
|
|
if (!normalizedPath) {
|
|
return null
|
|
}
|
|
const basename = normalizedPath.split(/[\\/]/).filter(Boolean).at(-1)?.trim()
|
|
return basename || null
|
|
}
|