Skip to content

Commit b01ef22

Browse files
committed
chore: cover every merge subject git writes, and report an unreadable message file
1 parent 72b98f6 commit b01ef22

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎.pre-commit-config.yaml‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ repos:
2626
- |
2727
import re, sys
2828
P = re.compile(r"\b(?i:LAB)-[0-9]+|op://|\.ts\.net|(?i:\bk3s[\s-]+(?:cluster|node|host)s?\b)|dev\.cachekit\.io|\bStage [0-9]|\bAC-[0-9]|github\.com/cachekit(?![\w-])")
29-
GIT_SUBJECT = re.compile(r"Merge (?:branch|branches|remote-tracking branch|tag|commit) '[^']*'(?: and '[^']*')*(?: of \S+)?(?: into \S+)?|Revert \".*\"")
30-
text = open(sys.argv[1], encoding="utf-8", errors="replace").read()
29+
KIND = r"(?:branch|branches|remote-tracking branch|remote-tracking branches|tag|tags|commit|commits)"
30+
GIT_SUBJECT = re.compile(rf"Merge {KIND} '[^']*'(?:(?:, | and ){KIND}? ?'[^']*')*(?: of \S+)?(?: into \S+)?|(?:Revert|Reapply) \".*\"")
31+
try:
32+
with open(sys.argv[1], encoding="utf-8", errors="replace") as f:
33+
text = f.read()
34+
except OSError as e:
35+
sys.exit(f"{sys.argv[1]}: cannot read the commit message: {e}")
3136
text = text.split("# ------------------------ >8 ------------------------")[0]
3237
lines = [line for line in text.splitlines() if line.strip() and not re.match(r"#(?:[ \t]|$)", line)]
3338
if lines and GIT_SUBJECT.fullmatch(lines[0]):

0 commit comments

Comments
 (0)