diff --git a/apps/api/src/utils/git_files.py b/apps/api/src/utils/git_files.py index ee6847d..ebe0cd0 100644 --- a/apps/api/src/utils/git_files.py +++ b/apps/api/src/utils/git_files.py @@ -190,18 +190,17 @@ def get_file_content(repo_path: str, branch: str, path: str) -> FileContent: def _is_binary_file(repo_path: str, branch: str, path: str) -> bool: - """Check if a file is binary.""" + """Check if a file is binary using raw bytes to avoid encoding issues.""" try: - _run_git_command( - repo_path, - "diff", - "--numstat", - "--", - path, + result = subprocess.run( + ["git", "show", f"{branch}:{path}"], + cwd=repo_path, + capture_output=True, ) - # Alternative: use git show and check for null bytes - content = _run_git_command(repo_path, "show", f"{branch}:{path}") - return b"\x00" in content.encode("utf-8", errors="replace") + if result.returncode != 0: + raise RuntimeError(f"Git command failed: {result.stderr.decode()}") + # A file is binary if it contains null bytes + return b"\x00" in result.stdout except RuntimeError: return True