MCPcopy Index your code
hub / github.com/forloopcodes/contextplus / createRestorePoint

Function createRestorePoint

src/git/shadow.ts:47–71  ·  view source on GitHub ↗
(rootDir: string, files: string[], message: string)

Source from the content-addressed store, hash-verified

45}
46
47export async function createRestorePoint(rootDir: string, files: string[], message: string): Promise<RestorePoint> {
48 const normalizedRoot = resolve(rootDir);
49 const dataPath = await ensureDataDir(normalizedRoot);
50 const id = `rp-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
51 const backupDir = join(dataPath, "backups", id);
52 await mkdir(backupDir, { recursive: true });
53
54 for (const file of files) {
55 const fullPath = assertWithinRoot(normalizedRoot, file);
56 try {
57 const content = await readFile(fullPath, "utf-8");
58 const backupPath = join(backupDir, file.replace(/[\\/]/g, "__"));
59 await writeFile(backupPath, content);
60 } catch {
61 }
62 }
63
64 const point: RestorePoint = { id, timestamp: Date.now(), files, message };
65 const manifest = await loadManifest(normalizedRoot);
66 manifest.push(point);
67 if (manifest.length > 100) manifest.splice(0, manifest.length - 100);
68 await saveManifest(normalizedRoot, manifest);
69
70 return point;
71}
72
73export async function restorePoint(rootDir: string, pointId: string): Promise<string[]> {
74 const normalizedRoot = resolve(rootDir);

Callers 4

shadow.test.mjsFile · 0.85
shadow.demo.mjsFile · 0.85
proposeCommitFunction · 0.85

Calls 4

ensureDataDirFunction · 0.85
assertWithinRootFunction · 0.85
loadManifestFunction · 0.85
saveManifestFunction · 0.85

Tested by

no test coverage detected