Fixes for git diff viewer (#10026)

This commit is contained in:
Tim O'Farrell
2025-07-31 13:19:56 -06:00
committed by GitHub
parent 5b5a9718c2
commit b9abdf10ce
2 changed files with 6 additions and 2 deletions

View File

@@ -10,6 +10,8 @@ import subprocess
import sys
from pathlib import Path
MAX_FILE_SIZE_FOR_GIT_DIFF = 1024 * 1024 # 1 Mb
def get_closest_git_repo(path: Path) -> Path | None:
while True:
@@ -75,9 +77,11 @@ def get_valid_ref(repo_dir: str) -> str | None:
def get_git_diff(relative_file_path: str) -> dict[str, str]:
path = Path(os.getcwd(), relative_file_path).resolve()
if os.path.getsize(path) > MAX_FILE_SIZE_FOR_GIT_DIFF:
raise ValueError('file_to_large')
closest_git_repo = get_closest_git_repo(path)
if not closest_git_repo:
raise ValueError('no_repo')
raise ValueError('no_repository')
current_rev = get_valid_ref(str(closest_git_repo))
try:
original = run(

View File

@@ -115,7 +115,7 @@ class GitHandler:
result = self.execute(self.git_diff_cmd.format(file_path=file_path), self.cwd)
if result.exit_code == 0:
diff = json.loads(result.content)
diff = json.loads(result.content, strict=False)
return diff
if self.git_diff_cmd != GIT_DIFF_CMD: