fix: patch-utils unused

This commit is contained in:
Eli Bosley
2025-01-31 15:27:54 -05:00
parent 0163acb7f3
commit 1d5c2c8338

View File

@@ -1,20 +0,0 @@
import { readFile, writeFile } from 'fs/promises';
import { applyPatch, parsePatch, reversePatch } from 'diff';
export async function rollbackPatch(targetFile: string, patch: string): Promise<void> {
const currentContent = await readFile(targetFile, 'utf8');
const parsedPatch = parsePatch(patch)[0];
if (!parsedPatch || !parsedPatch.hunks || parsedPatch.hunks.length === 0) {
throw new Error('Invalid or empty patch content');
}
const reversedPatch = reversePatch(parsedPatch);
const results = applyPatch(currentContent, reversedPatch);
if (results === false) {
throw new Error(`Failed to rollback patch from ${targetFile}`);
}
await writeFile(targetFile, results);
}