Skip to content

Commit b971752

Browse files
committed
Replace git clone with read-tree and checkout-index for git checkpoint restoration
- In `apps/editor/src/commands/history-command/actions/restore-checkpoint.ts`, replace the `git clone`, `git checkout`, and `.git` deletion block with a zero-clone index approach: create a temporary index file path, run `git read-tree "${git_info.commit_hash}"` and `git checkout-index -a -f` inside `folder.uri.fsPath` using `env: { ...process.env, GIT_INDEX_FILE: temp_index_path, GIT_WORK_TREE: temp_git_clone_path }`, and ensure you clean up the temporary index file in a finally block. └── apps └── editor └── src ├── commands │ └── history-command │ ├── actions │ │ ├── clear-all-checkpoints.ts │ │ ├── create-temporary-checkpoint.ts │ │ ├── delete-checkpoint-with-undo.ts │ │ ├── restore-checkpoint.ts │ │ ├── sync-workspace-from-dir.ts │ │ ├── toggle-checkpoint-pin.ts │ │ └── update-checkpoint-description.ts │ ├── history-command.ts │ ├── index.ts │ └── utils │ └── sync-directory.ts └── features └── checkpoints ├── actions │ ├── create-checkpoint.ts │ ├── delete-checkpoint.ts │ ├── get-checkpoints.ts │ └── index.ts ├── types │ ├── checkpoint.ts │ └── index.ts └── utils ├── copy-optimised-recursively.ts ├── get-checkpoint-path.ts ├── get-incremented-description.ts ├── git-utils.ts └── index.ts
1 parent 73a2da4 commit b971752

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

‎apps/editor/src/commands/history-command/actions/restore-checkpoint.ts‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,24 +291,32 @@ export const restore_checkpoint = async (params: {
291291
`cwc-git-clone-${Date.now()}-${Math.random().toString().slice(2)}`
292292
)
293293
const temp_git_dir_uri = vscode.Uri.file(temp_git_clone_path)
294+
const temp_index_path = path.join(
295+
os.tmpdir(),
296+
`cwc-index-${Date.now()}-${Math.random().toString().slice(2)}.index`
297+
)
294298

295299
try {
296300
await vscode.workspace.fs.createDirectory(temp_git_dir_uri)
297-
execSync(`git clone "${folder.uri.fsPath}" .`, {
298-
cwd: temp_git_clone_path,
301+
302+
const git_env = {
303+
...process.env,
304+
GIT_INDEX_FILE: temp_index_path,
305+
GIT_WORK_TREE: temp_git_clone_path
306+
}
307+
308+
execSync(`git read-tree "${git_info.commit_hash}"`, {
309+
cwd: folder.uri.fsPath,
310+
env: git_env,
299311
stdio: 'pipe'
300312
})
301313

302-
execSync(`git checkout ${git_info.commit_hash}`, {
303-
cwd: temp_git_clone_path,
314+
execSync(`git checkout-index -a -f`, {
315+
cwd: folder.uri.fsPath,
316+
env: git_env,
304317
stdio: 'pipe'
305318
})
306319

307-
await vscode.workspace.fs.delete(
308-
vscode.Uri.file(path.join(temp_git_clone_path, '.git')),
309-
{ recursive: true }
310-
)
311-
312320
const diff_file_path = path.join(
313321
checkpoint_dir_path,
314322
`${folder_name}.diff`
@@ -396,6 +404,13 @@ export const restore_checkpoint = async (params: {
396404
})
397405
} catch {}
398406
}
407+
if (temp_index_path) {
408+
try {
409+
await vscode.workspace.fs.delete(
410+
vscode.Uri.file(temp_index_path)
411+
)
412+
} catch {}
413+
}
399414
}
400415
} else {
401416
const source_folder_uri =

0 commit comments

Comments
 (0)