| 81 | } |
| 82 | |
| 83 | function 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 | |
| 101 | async function createTrackedFilePatch( |
| 102 | repositoryRoot: string, |