Skip to content

Commit c44aa9c

Browse files
committed
Warn about binary files
1 parent c45fdb1 commit c44aa9c

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

codeclash/tournaments/utils/git_utils.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
from codeclash.utils.log import get_logger
2+
3+
14
def filter_git_diff(text: str) -> str:
25
"""Return a git diff with any file sections mentioning binary content removed."""
6+
logger = get_logger(__name__)
37
lines = text.splitlines(keepends=True)
48
out: list[str] = []
59
block: list[str] = []
@@ -15,10 +19,24 @@ def is_binary_block(bl: list[str]) -> bool:
1519
return True
1620
return False
1721

22+
def extract_file_path_from_block(bl: list[str]) -> str:
23+
"""Extract file path from a git diff block."""
24+
for ln in bl:
25+
if ln.startswith("diff --git "):
26+
# Format: "diff --git a/path/to/file b/path/to/file"
27+
parts = ln.strip().split()
28+
if len(parts) >= 4:
29+
# Remove 'a/' prefix from the file path
30+
return parts[2][2:] if parts[2].startswith("a/") else parts[2]
31+
return "unknown file"
32+
1833
for ln in lines:
1934
if ln.startswith("diff --git "):
2035
if in_block:
21-
if not is_binary_block(block):
36+
if is_binary_block(block):
37+
file_path = extract_file_path_from_block(block)
38+
logger.warning(f"Binary file detected in diff: {file_path}")
39+
else:
2240
out.extend(block)
2341
block = []
2442
else:
@@ -31,7 +49,10 @@ def is_binary_block(bl: list[str]) -> bool:
3149
out.append(ln)
3250

3351
if in_block and block:
34-
if not is_binary_block(block):
52+
if is_binary_block(block):
53+
file_path = extract_file_path_from_block(block)
54+
logger.warning(f"Binary file detected in diff: {file_path}")
55+
else:
3556
out.extend(block)
3657

3758
return "".join(out)

0 commit comments

Comments
 (0)