MCPcopy Create free account
hub / github.com/conventional-changelog/commitlint / getEditCommit

Function getEditCommit

@commitlint/read/src/get-edit-commit.ts:7–31  ·  view source on GitHub ↗
(cwd?: string, edit?: boolean | string)

Source from the content-addressed store, hash-verified

5
6// Get recently edited commit message
7export 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}

Callers 1

getCommitMessagesFunction · 0.85

Calls 2

toplevelFunction · 0.85
getEditFilePathFunction · 0.85

Tested by

no test coverage detected