MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / formatDiffAsGitDiff

Function formatDiffAsGitDiff

packages/web/src/features/tools/utils.ts:6–33  ·  view source on GitHub ↗
(result: DiffResult)

Source from the content-addressed store, hash-verified

4type DiffResult = z.infer<typeof getDiffResponseSchema>;
5
6export function formatDiffAsGitDiff(result: DiffResult): string {
7 let output = '';
8
9 for (const file of result.files) {
10 output += file.oldPath ? `--- a/${file.oldPath}\n` : `--- /dev/null\n`;
11 output += file.newPath ? `+++ b/${file.newPath}\n` : `+++ /dev/null\n`;
12
13 for (const hunk of file.hunks) {
14 const oldStart = hunk.oldRange.start;
15 const oldLines = hunk.oldRange.lines;
16 const newStart = hunk.newRange.start;
17 const newLines = hunk.newRange.lines;
18
19 output += `@@ -${oldStart},${oldLines} +${newStart},${newLines} @@`;
20 if (hunk.heading) {
21 output += ` ${hunk.heading}`;
22 }
23 output += '\n';
24
25 output += hunk.body;
26 if (!hunk.body.endsWith('\n')) {
27 output += '\n';
28 }
29 }
30 }
31
32 return output;
33}

Callers 2

getDiff.tsFile · 0.90
utils.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected