MCPcopy Index your code
hub / github.com/desktop/desktop / formatPatchHeader

Function formatPatchHeader

app/src/lib/patch-formatter.ts:22–36  ·  view source on GitHub ↗

* Generates a string matching the format of a GNU unified diff header excluding * the (optional) timestamp fields * * Note that this multi-line string includes a trailing newline. * * @param from The relative path to the original version of the file or * null if the file is newly

(from: string | null, to: string | null)

Source from the content-addressed store, hash-verified

20 * null if the file is the file is newly created.
21 */
22function formatPatchHeader(from: string | null, to: string | null): string {
23 // https://en.wikipedia.org/wiki/Diff_utility
24 //
25 // > At the beginning of the patch is the file information, including the full
26 // > path and a time stamp delimited by a tab character.
27 // >
28 // > [...] the original file is preceded by "---" and the new file is preceded
29 // > by "+++".
30 //
31 // We skip the time stamp to match git
32 const fromPath = from ? `a/${from}` : '/dev/null'
33 const toPath = to ? `b/${to}` : '/dev/null'
34
35 return `--- ${fromPath}\n+++ ${toPath}\n`
36}
37
38/**
39 * Generates a string matching the format of a GNU unified diff header excluding

Callers 2

formatPatchHeaderForFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected