Initial commit from agent
This commit is contained in:
39
capabilities/git_manager.py
Normal file
39
capabilities/git_manager.py
Normal file
@@ -0,0 +1,39 @@
|
||||
"""
|
||||
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()]
|
||||
Reference in New Issue
Block a user