Files
OldThink/Tools/check_crlf.py
Cinka f02cc9cb87
Some checks failed
Build & Test Map Renderer / build (ubuntu-latest) (push) Has been cancelled
Build & Test Debug / build (ubuntu-latest) (push) Has been cancelled
Check Merge Conflicts / Label (push) Has been cancelled
Test Packaging / Test Packaging (push) Has been cancelled
RGA schema validator / YAML RGA schema validator (push) Has been cancelled
Map file schema validator / YAML map schema validator (push) Has been cancelled
YAML Linter / YAML Linter (push) Has been cancelled
Build & Test Map Renderer / Build & Test Debug (push) Has been cancelled
Build & Test Debug / Build & Test Debug (push) Has been cancelled
Benchmarks / Run Benchmarks (push) Has been cancelled
Update Contrib and Patreons in credits / get_credits (push) Has been cancelled
Build & Publish Docfx / docfx (push) Has been cancelled
- fix: engine update fix
2026-02-01 14:47:44 +03:00

37 lines
1.1 KiB
Python

#!/usr/bin/env python3
import subprocess
from typing import Iterable
def main() -> int:
any_failed = False
for file_name in get_text_files():
if is_file_crlf(file_name):
print(f"::error file={file_name},title=File contains CRLF line endings::The file '{file_name}' was committed with CRLF new lines. Please make sure your git client is configured correctly and you are not uploading files directly to GitHub via the web interface.")
any_failed = True
return 1 if any_failed else 0
def get_text_files() -> Iterable[str]:
# https://stackoverflow.com/a/24350112/4678631
process = subprocess.run(
["git", "grep", "--cached", "-Il", ""],
check=True,
encoding="utf-8",
stdout=subprocess.PIPE)
for x in process.stdout.splitlines():
yield x.strip()
def is_file_crlf(path: str) -> bool:
# https://stackoverflow.com/a/29697732/4678631
with open(path, "rb") as f:
for line in f:
if line.endswith(b"\r\n"):
return True
return False
exit(main())