mirror of
https://github.com/stablyai/orca.git
synced 2026-11-18 11:54:46 +00:00
Worktree ids built as `${repo.id}::${path}` by hand are how one worktree got two
spellings (#30150). New code composes them through src/shared/worktree/id.ts; the
ratchet counts the remaining hand-built ids per file (18) and may only go down. Six
byte-identical `${repo.id}::${repo.path}` sites move to getRepoMainWorktreeId.
81 lines
3.5 KiB
TypeScript
81 lines
3.5 KiB
TypeScript
import { DEFAULT_WORKSPACE_STATUS_ID } from '../../shared/workspace-statuses'
|
|
import type { Repo } from '../../shared/repo-types'
|
|
import type { WorktreeMeta } from '../../shared/worktree/meta-types'
|
|
import type { Worktree } from '../../shared/worktree/types'
|
|
import {
|
|
FOLDER_WORKSPACE_INSTANCE_SEPARATOR,
|
|
getRepoMainWorktreeId
|
|
} from '../../shared/worktree/id'
|
|
import { normalizeWorkspaceCreatorProvenance } from '../../shared/workspace-creator-provenance'
|
|
|
|
export function getRuntimeFolderWorkspaceRootId(repo: Repo): string {
|
|
return getRepoMainWorktreeId(repo)
|
|
}
|
|
|
|
export function getRuntimeFolderWorkspaceInstanceId(repo: Repo, instanceId: string): string {
|
|
return `${getRuntimeFolderWorkspaceRootId(repo)}${FOLDER_WORKSPACE_INSTANCE_SEPARATOR}${instanceId}`
|
|
}
|
|
|
|
export function isRuntimeFolderWorkspaceIdForRepo(repo: Repo, worktreeId: string): boolean {
|
|
const rootId = getRuntimeFolderWorkspaceRootId(repo)
|
|
return (
|
|
worktreeId === rootId ||
|
|
worktreeId.startsWith(`${rootId}${FOLDER_WORKSPACE_INSTANCE_SEPARATOR}`)
|
|
)
|
|
}
|
|
|
|
export function mergeRuntimeFolderWorkspace(
|
|
repo: Repo,
|
|
worktreeId: string,
|
|
meta: Partial<WorktreeMeta>
|
|
): Worktree {
|
|
const creatorProvenance = normalizeWorkspaceCreatorProvenance(meta.creatorProvenance)
|
|
return {
|
|
id: worktreeId,
|
|
...(meta.instanceId !== undefined ? { instanceId: meta.instanceId } : {}),
|
|
repoId: repo.id,
|
|
...(meta.projectId !== undefined ? { projectId: meta.projectId } : {}),
|
|
...(meta.hostId !== undefined ? { hostId: meta.hostId } : {}),
|
|
...(meta.projectHostSetupId !== undefined
|
|
? { projectHostSetupId: meta.projectHostSetupId }
|
|
: {}),
|
|
...(creatorProvenance ? { creatorProvenance } : {}),
|
|
path: repo.path,
|
|
head: '',
|
|
branch: '',
|
|
isBare: false,
|
|
isMainWorktree: worktreeId === getRuntimeFolderWorkspaceRootId(repo),
|
|
displayName: meta.displayName || repo.displayName,
|
|
comment: meta.comment || '',
|
|
linkedIssue: meta.linkedIssue ?? null,
|
|
linkedPR: meta.linkedPR ?? null,
|
|
linkedLinearIssue: meta.linkedLinearIssue ?? null,
|
|
linkedLinearIssueWorkspaceId: meta.linkedLinearIssueWorkspaceId ?? null,
|
|
linkedLinearIssueOrganizationUrlKey: meta.linkedLinearIssueOrganizationUrlKey ?? null,
|
|
linkedGitLabMR: meta.linkedGitLabMR ?? null,
|
|
linkedGitLabIssue: meta.linkedGitLabIssue ?? null,
|
|
linkedBitbucketPR: meta.linkedBitbucketPR ?? null,
|
|
linkedAzureDevOpsPR: meta.linkedAzureDevOpsPR ?? null,
|
|
linkedGiteaPR: meta.linkedGiteaPR ?? null,
|
|
linkedWorkItem: meta.linkedWorkItem ?? null,
|
|
...(meta.linkedItems !== undefined ? { linkedItems: meta.linkedItems } : {}),
|
|
linkedTaskSourceContext: meta.linkedTaskSourceContext ?? null,
|
|
isArchived: meta.isArchived ?? false,
|
|
isUnread: meta.isUnread ?? false,
|
|
isPinned: meta.isPinned ?? false,
|
|
sortOrder: meta.sortOrder ?? 0,
|
|
...(meta.manualOrder !== undefined ? { manualOrder: meta.manualOrder } : {}),
|
|
lastActivityAt: meta.lastActivityAt ?? 0,
|
|
...(meta.createdAt !== undefined ? { createdAt: meta.createdAt } : {}),
|
|
...(meta.createdWithAgent !== undefined ? { createdWithAgent: meta.createdWithAgent } : {}),
|
|
...(meta.automationProvenance !== undefined
|
|
? { automationProvenance: meta.automationProvenance }
|
|
: {}),
|
|
...(meta.cliProvenance !== undefined ? { cliProvenance: meta.cliProvenance } : {}),
|
|
...(meta.priorWorktreeIds !== undefined ? { priorWorktreeIds: meta.priorWorktreeIds } : {}),
|
|
workspaceStatus: meta.workspaceStatus ?? DEFAULT_WORKSPACE_STATUS_ID,
|
|
diffComments: meta.diffComments,
|
|
mobileDiffReview: meta.mobileDiffReview
|
|
}
|
|
}
|