MCPcopy Create free account
hub / github.com/arctic-cli/interface / ensureChildWorktree

Function ensureChildWorktree

packages/arctic/src/session/benchmark.ts:365–393  ·  view source on GitHub ↗
(
    parent: Session.Info & { benchmark: BenchmarkSchema.Parent },
    child: Session.Info & { benchmark: BenchmarkSchema.ChildSession },
  )

Source from the content-addressed store, hash-verified

363 }
364
365 export async function ensureChildWorktree(
366 parent: Session.Info & { benchmark: BenchmarkSchema.Parent },
367 child: Session.Info & { benchmark: BenchmarkSchema.ChildSession },
368 ) {
369 const worktree =
370 child.benchmark.worktree ?? path.join(Global.Path.data, "benchmark", parent.id, child.id)
371 const exists = await fs
372 .stat(worktree)
373 .then(() => true)
374 .catch(() => false)
375 if (!exists) {
376 await fs.mkdir(worktree, { recursive: true })
377 if (parent.benchmark.baseSnapshot) {
378 await Snapshot.restoreTo(parent.benchmark.baseSnapshot, worktree, { cleanUntracked: true })
379 }
380 await Session.update(child.id, (draft) => {
381 if (draft.benchmark?.type === "child") {
382 draft.benchmark.worktree = worktree
383 }
384 })
385 await Session.update(parent.id, (draft) => {
386 if (draft.benchmark?.type === "parent") {
387 const entry = draft.benchmark.children.find((item) => item.sessionID === child.id)
388 if (entry) entry.worktree = worktree
389 }
390 })
391 }
392 return worktree
393 }
394}

Callers 2

applyFunction · 0.85
undoFunction · 0.85

Calls 1

updateMethod · 0.45

Tested by

no test coverage detected