mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-09 14:57:59 -05:00
Fixes for git diff viewer (#10026)
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user