* 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)
| 20 | * null if the file is the file is newly created. |
| 21 | */ |
| 22 | function 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 |
no outgoing calls
no test coverage detected