Check the files a commit would commit against rule-hook's file rules, and sort .gitignore's allowlist block
CI / tests (pull_request) Failing after 2m2s

This commit is contained in:
2026-11-11 14:07:34 +01:00
parent 1fa03973a3
commit 3e289c95d9
11 changed files with 154 additions and 29 deletions
+12
View File
@@ -0,0 +1,12 @@
import os
import stat
def read(path: str) -> str:
"""path's text, or "" for anything but a regular file: a FIFO would hang the hook and a device such as /dev/zero would flood it."""
try:
# O_NONBLOCK opens a FIFO without waiting for a writer; fstat then judges the file opened, not one swapped in after a stat.
with open(os.open(path, os.O_RDONLY | os.O_NONBLOCK), encoding="utf-8") as opened:
return opened.read() if stat.S_ISREG(os.fstat(opened.fileno()).st_mode) else ""
except (OSError, UnicodeDecodeError):
return ""