(node: NodeNameParts)
| 30 | export interface BranchNode { project?: string; name: string; state: 'detached' | 'working-tree' | 'branch' } |
| 31 | |
| 32 | export function branchNodeOf(node: NodeNameParts): BranchNode | undefined { |
| 33 | const label = node.label || node.kind; |
| 34 | const at = node.qualifiedName?.indexOf(BRANCH_MARK) ?? -1; |
| 35 | if (label ? label !== 'Branch' : at <= 0) return undefined; |
| 36 | const slug = at > 0 ? node.qualifiedName!.slice(at + BRANCH_MARK.length) : undefined; |
| 37 | const project = at > 0 ? node.qualifiedName!.slice(0, at) : node.project || undefined; |
| 38 | /* |
| 39 | * The engine names a detached HEAD "DETACHED" with the slug "detached". |
| 40 | * A search hit carries no name, only the qualified name, so its name is |
| 41 | * the slug ("detached"); a branch that is really called "detached" looks |
| 42 | * the same and is taken for the far more common detached HEAD. The slug |
| 43 | * keeps the case of the branch, so "Detached" stays a branch. |
| 44 | */ |
| 45 | const detached = slug === undefined ? node.name === 'DETACHED' : slug === 'detached'; |
| 46 | const state = detached ? 'detached' : node.name === 'working-tree' && (slug === undefined || slug === 'working-tree') ? 'working-tree' : 'branch'; |
| 47 | return { ...project ? { project } : {}, name: node.name, state }; |
| 48 | } |
| 49 | |
| 50 | /** The shown name: "django-demo · detached HEAD" for a Branch node, the node's own name for every other. */ |
| 51 | export function nodeDisplayName(node: NodeNameParts, words: BranchNameWords = galaxyNodeNameText): string { |
no outgoing calls
no test coverage detected