forge-tools/frg/git.py
Marc Cataford fd11d84466
All checks were successful
/ tests (pull_request) Successful in 1m16s
/ static-analysis (pull_request) Successful in 1m27s
/ export-trace (pull_request) Successful in 28s
/ tests (push) Successful in 1m16s
/ static-analysis (push) Successful in 1m35s
/ export-trace (push) Successful in 26s
feat: ensure push on pr create
2024-11-03 21:11:12 -05:00

34 lines
870 B
Python

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])