MCPcopy Create free account
hub / github.com/github/gh-aw / newFileDiff

Function newFileDiff

actions/setup/js/apply_samples.test.cjs:265–272  ·  view source on GitHub ↗

* Build a unified diff that adds a brand-new file. Synthetic but realistic.

(filePath, contents)

Source from the content-addressed store, hash-verified

263 * Build a unified diff that adds a brand-new file. Synthetic but realistic.
264 */
265 function newFileDiff(filePath, contents) {
266 const lines = contents.split("\n");
267 // Strip trailing empty element produced by a terminating "\n" so the
268 // hunk header line count matches what git apply expects.
269 if (lines[lines.length - 1] === "") lines.pop();
270 const body = lines.map(l => "+" + l).join("\n");
271 return `diff --git a/${filePath} b/${filePath}\n` + `new file mode 100644\n` + `index 0000000..1111111\n` + `--- /dev/null\n` + `+++ b/${filePath}\n` + `@@ -0,0 +1,${lines.length} @@\n` + body + "\n";
272 }
273
274 it("checks out the requested branch and commits the patch on it (create_pull_request)", async () => {
275 const workspace = makeTempDir("gh-aw-prestage-cpr-");

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected