From a0937311076593dc8258c8f573ef916f73601b85 Mon Sep 17 00:00:00 2001 From: Hermes PR Agent Date: Fri, 15 May 2026 10:08:03 +0700 Subject: [PATCH] fix(read): strip verbose diff from commit message When `git commit --verbose` is used, git appends the diff to the commit message file (COMMIT_EDITMSG). Commitlint's --edit mode reads this file directly, causing body/footer-max-line-length rules to incorrectly fail on diff lines. Strip everything after the scissors line or the first `diff --git` marker, mirroring git's own stripping behavior. Fixes #437 --- @commitlint/read/src/get-edit-commit.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/@commitlint/read/src/get-edit-commit.ts b/@commitlint/read/src/get-edit-commit.ts index 491864136f..d1ea686f15 100644 --- a/@commitlint/read/src/get-edit-commit.ts +++ b/@commitlint/read/src/get-edit-commit.ts @@ -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; + + const cleaned = cutIndex !== -1 ? raw.slice(0, cutIndex) : raw; + + return [`${cleaned}\n`]; }