Replace bash scripts with Python for git operations (#9914)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Tim O'Farrell
2025-07-29 07:34:52 -06:00
committed by GitHub
parent 8fb3728391
commit d9a595c9b1
6 changed files with 611 additions and 508 deletions

View File

@@ -133,7 +133,8 @@ class Runtime(FileEditRuntimeMixin):
git_provider_tokens: PROVIDER_TOKEN_TYPE | None = None,
):
self.git_handler = GitHandler(
execute_shell_fn=self._execute_shell_fn_git_handler
execute_shell_fn=self._execute_shell_fn_git_handler,
create_file_fn=self._create_file_fn_git_handler,
)
self.sid = sid
self.event_stream = event_stream
@@ -1017,6 +1018,15 @@ fi
return CommandResult(content=content, exit_code=exit_code)
def _create_file_fn_git_handler(self, path: str, content: str) -> int:
"""
This function is used by the GitHandler to execute shell commands.
"""
obs = self.write(FileWriteAction(path=path, content=content))
if isinstance(obs, ErrorObservation):
return -1
return 0
def get_git_changes(self, cwd: str) -> list[dict[str, str]] | None:
self.git_handler.set_cwd(cwd)
changes = self.git_handler.get_git_changes()