Skip to content

πŸ™Œ OpenHands: AI-Driven Development

chore: improve logging for "not a git repository" (#7944)

Xingyao Wanga792f84a83c8
diff --git a/openhands/runtime/base.py b/openhands/runtime/base.py
index da8aadf31b..7ae5315a41 100644
--- a/openhands/runtime/base.py
+++ b/openhands/runtime/base.py
@@ -610,7 +610,7 @@ class Runtime(FileEditRuntimeMixin):
return CommandResult(content=content, exit_code=exit_code)
- def get_git_changes(self, cwd: str) -> list[dict[str, str]]:
+ def get_git_changes(self, cwd: str) -> list[dict[str, str]] | None:
self.git_handler.set_cwd(cwd)
return self.git_handler.get_git_changes()
diff --git a/openhands/runtime/utils/git_handler.py b/openhands/runtime/utils/git_handler.py
index bfeb884516..2aed4d6ced 100644
--- a/openhands/runtime/utils/git_handler.py
+++ b/openhands/runtime/utils/git_handler.py
@@ -153,18 +153,15 @@ class GitHandler:
else []
)
- def get_git_changes(self) -> list[dict[str, str]]:
+ def get_git_changes(self) -> list[dict[str, str]] | None:
"""
Retrieves the list of changed files in the Git repository.
Returns:
- list[dict[str, str]]: A list of dictionaries containing file paths and statuses.
-
- Raises:
- RuntimeError: If the directory is not a Git repository.
+ list[dict[str, str]] | None: A list of dictionaries containing file paths and statuses. None if not a git repository.
"""
if not self._is_git_repo():
- raise RuntimeError('Not a git repository')
+ return None
changes_list = self._get_changed_files()
result = parse_git_changes(changes_list)
diff --git a/openhands/server/routes/files.py b/openhands/server/routes/files.py
index 7b9d8150a5..5003788c5b 100644
--- a/openhands/server/routes/files.py
+++ b/openhands/server/routes/files.py
@@ -202,6 +202,11 @@ async def git_changes(request: Request, conversation_id: str):
try:
changes = await call_sync_from_async(runtime.get_git_changes, cwd)
+ if changes is None:
+ return JSONResponse(
+ status_code=500,
+ content={'error': 'Not a git repository'},
+ )
return changes
except AgentRuntimeUnavailableError as e:
logger.error(f'Runtime unavailable: {e}')