fix lefthook (#17023)

This commit is contained in:
Zhichang Yu
2026-07-17 11:18:10 +08:00
committed by GitHub
parent 7c698f8e4b
commit f69ed74670
5 changed files with 91 additions and 43 deletions

View File

@@ -3,6 +3,7 @@ from __future__ import annotations
import ast
import json
import os
import re
import subprocess
import sys
@@ -23,14 +24,17 @@ def _read_bytes(path: Path) -> bytes:
return path.read_bytes()
def _staged_paths() -> list[Path]:
def _git_paths(*args: str) -> list[Path]:
proc = subprocess.run(
["git", "diff", "--cached", "--name-only", "--diff-filter=ACMR"],
["git", *args, "-z"],
check=True,
capture_output=True,
text=True,
)
return [Path(line) for line in proc.stdout.splitlines() if line]
return [Path(os.fsdecode(raw_path)) for raw_path in proc.stdout.split(b"\0") if raw_path]
def _staged_paths() -> list[Path]:
return _git_paths("diff", "--cached", "--name-only", "--diff-filter=ACMR")
def _report(errors: list[str]) -> int:
@@ -147,15 +151,10 @@ def check_symlinks(paths: list[Path], fix: bool = False) -> int:
def check_case_conflicts(_: list[Path], fix: bool = False) -> int:
proc = subprocess.run(
["git", "ls-files"],
check=True,
capture_output=True,
text=True,
)
seen: dict[str, str] = {}
errors: list[str] = []
for path in proc.stdout.splitlines():
for raw_path in _git_paths("ls-files"):
path = str(raw_path)
lowered = path.lower()
other = seen.get(lowered)
if other and other != path: