(
projectId: string,
callback: (context: { env: NodeJS.ProcessEnv; hasHead: boolean }) => Promise<T>,
)
| 66 | } |
| 67 | |
| 68 | export 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 | } |
no test coverage detected