MCPcopy Create free account
hub / github.com/IgorWarzocha/howcode / withTemporaryIndex

Function withTemporaryIndex

desktop/project-git/git-runner.ts:68–89  ·  view source on GitHub ↗
(
  projectId: string,
  callback: (context: { env: NodeJS.ProcessEnv; hasHead: boolean }) => Promise<T>,
)

Source from the content-addressed store, hash-verified

66}
67
68export async function withTemporaryIndex<T>(
69 projectId: string,
70 callback: (context: { env: NodeJS.ProcessEnv; hasHead: boolean }) => Promise<T>,
71) {
72 const tempDir = await mkdtemp(join(tmpdir(), 'howcode-git-index-'))
73 const env = { ...process.env, GIT_INDEX_FILE: join(tempDir, 'index') }
74
75 try {
76 const repositoryHasHead = await hasHeadCommit(projectId)
77 if (repositoryHasHead) {
78 await runGitWithOptions(projectId, ['read-tree', 'HEAD'], {
79 env,
80 timeout: 10_000,
81 maxBuffer: 1024 * 1024,
82 })
83 }
84
85 return await callback({ env, hasHead: repositoryHasHead })
86 } finally {
87 await rm(tempDir, { force: true, recursive: true })
88 }
89}

Callers 3

withStagedWorktreeFunction · 0.90
loadWorktreeStatsFunction · 0.90

Calls 2

hasHeadCommitFunction · 0.85
runGitWithOptionsFunction · 0.85

Tested by

no test coverage detected