Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion @commitlint/read/src/get-edit-commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,22 @@ export async function getEditCommit(cwd?: string, edit?: boolean | string): Prom
throw err;
}

return [`${editFile.toString("utf-8")}\n`];
const raw = editFile.toString("utf-8");

// Strip the verbose diff added by `git commit --verbose`.
// Git appends the diff after a scissors line and/or a `diff --git`
// marker. The diff is never part of the final commit message so
// neither should commitlint see it (see #437).
const diffIndex = raw.indexOf("\ndiff --git ");
const scissorsIndex = raw.indexOf("\n# ------------------------ >8 ------------------------");
const cutIndex =
diffIndex !== -1 && scissorsIndex !== -1
? Math.min(diffIndex, scissorsIndex)
: diffIndex !== -1
? diffIndex
: scissorsIndex;
Comment on lines +36 to +43

const cleaned = cutIndex !== -1 ? raw.slice(0, cutIndex) : raw;

return [`${cleaned}\n`];
Comment on lines +30 to +47
}
Loading