From cccc4a9d5aee1cc1336d584b207c274fde4e0e17 Mon Sep 17 00:00:00 2001 From: Fusion Date: Tue, 19 May 2026 18:55:58 +0200 Subject: [PATCH] fix: correct binary file detection in git file viewer - Remove useless git diff --numstat call that failed in bare repos - Use raw bytes instead of text decoding to avoid encoding issues - Properly check subprocess return codes Fixes false positive binary detection for text files like .env.sample --- apps/api/src/utils/git_files.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) 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