(cwd?: string, edit?: boolean | string)
| 5 | |
| 6 | // Get recently edited commit message |
| 7 | export async function getEditCommit(cwd?: string, edit?: boolean | string): Promise<string[]> { |
| 8 | const top = await toplevel(cwd); |
| 9 | |
| 10 | if (typeof top !== "string") { |
| 11 | throw new TypeError(`Could not find git root from ${cwd}`); |
| 12 | } |
| 13 | |
| 14 | const editFilePath = await getEditFilePath(top, edit); |
| 15 | |
| 16 | let editFile: Buffer; |
| 17 | try { |
| 18 | editFile = await fs.readFile(editFilePath); |
| 19 | } catch (err) { |
| 20 | if ((err as NodeJS.ErrnoException).code === "ENOENT") { |
| 21 | const hint = |
| 22 | typeof edit === "string" |
| 23 | ? `Check that the path passed to --edit exists and is readable.` |
| 24 | : `--edit reads the message prepared by 'git commit' and is intended to run from a commit-msg hook. If you want to lint existing history, use --from / --to instead; to lint a specific file, pass its path as --edit <file>.`; |
| 25 | throw new Error(`No commit message file found at ${editFilePath}. ${hint}`, { cause: err }); |
| 26 | } |
| 27 | throw err; |
| 28 | } |
| 29 | |
| 30 | return [`${editFile.toString("utf-8")}\n`]; |
| 31 | } |
no test coverage detected