aboutsummaryrefslogtreecommitdiff
path: root/hooks/git-commit-confirm.py
diff options
context:
space:
mode:
Diffstat (limited to 'hooks/git-commit-confirm.py')
-rwxr-xr-xhooks/git-commit-confirm.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/hooks/git-commit-confirm.py b/hooks/git-commit-confirm.py
index 2441d23..618ac20 100755
--- a/hooks/git-commit-confirm.py
+++ b/hooks/git-commit-confirm.py
@@ -42,7 +42,12 @@ import re
import subprocess
import sys
-from _common import read_payload, respond_ask, scan_attribution
+from _common import (
+ read_payload,
+ read_referenced_file,
+ respond_ask,
+ scan_attribution,
+)
MAX_FILES_SHOWN = 25
@@ -140,6 +145,18 @@ def extract_commit_message(cmd: str) -> str:
if long_form:
return "\n\n".join(msg for _, msg in long_form).strip()
+ # File-backed message: -F <file> / --file <file> / --file=<file>.
+ # Read the file so its text is attribution-scanned. If it can't be read
+ # safely, fall through to UNPARSEABLE_MESSAGE so the hook asks (fail-safe).
+ file_flag = re.search(
+ r"(?:^|\s)(?:-F|--file)[=\s]+(\"[^\"]+\"|'[^']+'|\S+)", cmd
+ )
+ if file_flag:
+ path = file_flag.group(1).strip("\"'")
+ text = read_referenced_file(path)
+ if text is not None:
+ return text.strip()
+
return UNPARSEABLE_MESSAGE