Lines 283-323javascript
284 const oldFile = join(dir, "old");
285 const newFile = join(dir, "new");
286 await writeFile(oldFile, before, "utf8");
287 await writeFile(newFile, after, "utf8");
288 const { stdout } = await runGitDiffNoIndex(projectPath, oldFile, newFile);
289 return relabelNoIndexDiff(stdout, oldFile, newFile, rel);
295 await rm(dir, { recursive: true, force: true });
299 * Run `git diff --no-index <old> <new>` to generate a diff between two
300 * arbitrary files. Returns stdout on success (exit code 1 = differences
301 * found, which is expected). Throws on other errors.
303async function runGitDiffNoIndex(cwd, oldFile, newFile) {
304 const { spawn } = await import("node:child_process");
305 return new Promise((resolveFn, rejectFn) => {
HighChild Process
Package source references child process execution.
dist/server/turn-diff-builder.jsView on unpkg · L303 306 const child = spawn("git", ["diff", "--no-color", "--no-ext-diff", "--no-index", oldFile, newFile], {
308 stdio: ["ignore", "pipe", "pipe"],
312 child.stdout.setEncoding("utf8");
313 child.stdout.on("data", (chunk) => { stdout += chunk; });
314 child.stderr.setEncoding("utf8");
315 child.stderr.on("data", (chunk) => { stderr += chunk; });
316 child.on("error", (err) => rejectFn(err));
317 child.on("close", (code) => {
318 // git diff --no-index exits 1 when differences found, 0 when identical
319 if (code === 0 || code === 1)
320 resolveFn({ stdout });
322 rejectFn(new Error(`git diff --no-index exited ${code}: ${stderr}`));