MCPcopy Create free account
hub / github.com/agegr/pi-web / createAddedFilePatch

Function createAddedFilePatch

lib/git-changes.ts:83–99  ·  view source on GitHub ↗
(gitPath: string, content: string)

Source from the content-addressed store, hash-verified

81}
82
83function createAddedFilePatch(gitPath: string, content: string): string {
84 const hasTrailingNewline = content.endsWith("\n");
85 const lines = content.split("\n");
86 if (hasTrailingNewline) lines.pop();
87 const body = lines.map((line) => `+${line}`).join("\n");
88 const noNewlineMarker = !hasTrailingNewline && lines.length > 0
89 ? "\n\\ No newline at end of file"
90 : "";
91 return [
92 `diff --git a/${gitPath} b/${gitPath}`,
93 "new file mode 100644",
94 "--- /dev/null",
95 `+++ b/${gitPath}`,
96 `@@ -0,0 +1,${lines.length} @@`,
97 `${body}${noNewlineMarker}`,
98 ].join("\n");
99}
100
101async function createTrackedFilePatch(
102 repositoryRoot: string,

Callers 1

getGitFileDiffFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected