MCPcopy Create free account
hub / github.com/backnotprop/plannotator / parseDiffGitHeader

Function parseDiffGitHeader

packages/shared/diff-paths.ts:66–87  ·  view source on GitHub ↗
(header: string)

Source from the content-addressed store, hash-verified

64}
65
66export function parseDiffGitHeader(header: string): DiffPathPair {
67 const prefix = "diff --git ";
68 if (!header.startsWith(prefix)) return {};
69
70 const rest = header.slice(prefix.length);
71 if (rest.trimStart().startsWith('"')) {
72 const first = scanHeaderToken(rest);
73 const second = first ? scanHeaderToken(first.rest) : null;
74 if (first && second) {
75 const oldPath = parsePatchPathToken(first.token, "a");
76 const newPath = parsePatchPathToken(second.token, "b");
77 return {
78 oldPath: oldPath && oldPath !== "/dev/null" ? oldPath : undefined,
79 newPath: newPath && newPath !== "/dev/null" ? newPath : undefined,
80 };
81 }
82 }
83
84 const match = header.match(/^diff --git a\/(.+) b\/(.+)$/);
85 if (!match) return {};
86 return { oldPath: match[1], newPath: match[2] };
87}
88
89export function formatPatchPathToken(side: "a" | "b", filePath: string): string {
90 if (filePath === "/dev/null") return filePath;

Callers 3

pr-github.test.tsFile · 0.90
rewritePatchChunkFunction · 0.90
parseDiffToFilesFunction · 0.90

Calls 2

scanHeaderTokenFunction · 0.85
parsePatchPathTokenFunction · 0.85

Tested by

no test coverage detected