import subprocess import pydantic class CommandResult(pydantic.BaseModel): return_code: int stdout: str stderr: str def _git(args: list[str]) -> CommandResult: result = subprocess.run(["git", *args], capture_output=True) return CommandResult( stdout=result.stdout.decode("utf8").strip(), stderr=result.stderr.decode("utf8").strip(), return_code=result.returncode, ) def get_current_branch() -> CommandResult: """Returns the current checked out branch.""" return _git(["branch", "--show-current"]) def get_current_remote_url() -> CommandResult: """Returns the remote origin url.""" return _git(["config", "--get", "remote.origin.url"]) def push(*, branch: str) -> CommandResult: """Pushes the current local commits to remote.""" return _git(["push", "--set-upstream", "origin", branch])