Files
jarvis/capabilities/git_manager.py
2026-03-24 00:11:34 -05:00

40 lines
1.1 KiB
Python

"""
Git operations via subprocess.
Wraps common git commands for use by JARVIS.
"""
import subprocess
from pathlib import Path
def _git(path: str, *args) -> dict:
result = subprocess.run(
["git", *args], cwd=path, capture_output=True, text=True
)
return {
"stdout": result.stdout.strip(),
"stderr": result.stderr.strip(),
"returncode": result.returncode
}
def get_git_status(path: str) -> str:
return _git(path, "status")["stdout"]
def get_git_log(path: str, count: int = 5) -> str:
return _git(path, "log", f"--oneline", f"-{count}")["stdout"]
def git_diff(path: str) -> str:
return _git(path, "diff")["stdout"]
def git_pull(path: str) -> dict:
return _git(path, "pull")
def git_add_commit(path: str, message: str) -> dict:
_git(path, "add", "-A")
return _git(path, "commit", "-m", message)
def git_push(path: str) -> dict:
return _git(path, "push")
def list_branches(path: str) -> list[str]:
result = _git(path, "branch", "-a")
return [b.strip().lstrip("* ") for b in result["stdout"].splitlines() if b.strip()]