From c667d76ceeb5fc3e4e70944bf661214a082e8ce0 Mon Sep 17 00:00:00 2001 From: Aadam Ali <57071686+aadam-ali@users.noreply.github.com> Date: Fri, 17 Jul 2026 15:59:51 +0000 Subject: [PATCH] fix: `Signed-off-by` trailer not being added to verbose commits When using an editor to write commit messages with the `commit.verbose` config option set to `true`, the `Signed-off-by` trailer is not added to commits. With the config option set, the following warning is shown: > # ------------------------ >8 ------------------------ > # Do not modify or remove the line above. > # Everything below it will be ignored. The `commit-msg` hook appends the trailer to the end of the commit message file, meaning it's appended after this line therefore it's not actually added to the commit message. This commit filters out the contents of a commit message from the cut-off line ensuring that the `Signed-off-by` trailer is actually added to these commits. Signed-off-by: DBT pre-commit check --- src/hooks/validate_security_scan.py | 10 +++- .../unit/hooks/test_validate_security_scan.py | 53 +++++++++++++++++-- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/hooks/validate_security_scan.py b/src/hooks/validate_security_scan.py index b8b4f301..8afbe2a3 100644 --- a/src/hooks/validate_security_scan.py +++ b/src/hooks/validate_security_scan.py @@ -63,7 +63,15 @@ async def run(self) -> ValidateSecurityScanResult: return ValidateSecurityScanResult(False, "No commit message provided") regex = re.compile(r"Signed-off-by", flags=re.DOTALL) - filtered_contents = [i for i in contents if not regex.match(i)] + + filtered_contents = [] + for i in contents: + if i == "# ------------------------ >8 ------------------------\n": + break + + if not regex.match(i): + filtered_contents.append(i) + filtered_contents.append(f"\n{SIGNED_OFF_BY_TRAILER}") logger.debug("New commit message is %s", "".join(filtered_contents)) diff --git a/tests/unit/hooks/test_validate_security_scan.py b/tests/unit/hooks/test_validate_security_scan.py index f9f22c3c..ee1399a8 100644 --- a/tests/unit/hooks/test_validate_security_scan.py +++ b/tests/unit/hooks/test_validate_security_scan.py @@ -1,8 +1,8 @@ -from anyio import NamedTemporaryFile -import src.hooks.config - from unittest.mock import patch +from anyio import NamedTemporaryFile + +import src.hooks.config from src.hooks.validate_security_scan import ValidateSecurityScan @@ -112,3 +112,50 @@ async def test_run_with_file_with_existing_signed_off_header_is_replaced(self): assert (await tf.read()).decode( "UTF-8" ) == f"A helpful commit message\n\n{src.hooks.config.SIGNED_OFF_BY_TRAILER}" + + async def test_run_with_file_with_commit_verbose_set_to_true(self): + async with NamedTemporaryFile() as tf: + with patch.object(ValidateSecurityScan, "validate_hook_settings", return_value=True): + await tf.writelines( + line + b"\n" + for line in [ + b"A helpful commit message", + b"# ------------------------ >8 ------------------------", + b"# Do not modify or remove the line above.", + b"# Everything below it will be ignored.", + ] + ) + await tf.seek(0) + + result = await ValidateSecurityScan(paths=[tf.name]).run() + + assert result.success is True + + assert (await tf.read()).decode( + "UTF-8" + ) == f"A helpful commit message\n\n{src.hooks.config.SIGNED_OFF_BY_TRAILER}" + + async def test_run_with_file_with_commit_verbose_set_to_true_with_body(self): + async with NamedTemporaryFile() as tf: + with patch.object(ValidateSecurityScan, "validate_hook_settings", return_value=True): + await tf.writelines( + line + b"\n" + for line in [ + b"A", + b"helpful", + b"commit", + b" message", + b"# ------------------------ >8 ------------------------", + b"# Do not modify or remove the line above.", + b"# Everything below it will be ignored.", + ] + ) + await tf.seek(0) + + result = await ValidateSecurityScan(paths=[tf.name]).run() + + assert result.success is True + + assert (await tf.read()).decode( + "UTF-8" + ) == f"A\nhelpful\ncommit\n message\n\n{src.hooks.config.SIGNED_OFF_BY_TRAILER}"