π OpenHands: AI-Driven Development
Fixes for git diff viewer (#10026)
Tim O'Farrellb9abdf10ce57
diff --git a/openhands/runtime/utils/git_diff.py b/openhands/runtime/utils/git_diff.pyindex a9b5d263e1..9f71222b19 100644--- a/openhands/runtime/utils/git_diff.py+++ b/openhands/runtime/utils/git_diff.py@@ -10,6 +10,8 @@ import subprocessimport sysfrom 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(diff --git a/openhands/runtime/utils/git_handler.py b/openhands/runtime/utils/git_handler.pyindex d3efa2ed58..5b5ead5f4f 100644--- a/openhands/runtime/utils/git_handler.py+++ b/openhands/runtime/utils/git_handler.py@@ -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 diffif self.git_diff_cmd != GIT_DIFF_CMD: