2024-11-04 01:59:35 +00:00
|
|
|
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"])
|
2024-11-04 02:11:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
def push(*, branch: str) -> CommandResult:
|
|
|
|
"""Pushes the current local commits to remote."""
|
|
|
|
return _git(["push", "--set-upstream", "origin", branch])
|