Coverage for agentos/marketplace/skills/git/git.py: 24%
21 statements
« prev ^ index » next coverage.py v7.14.3, created at 2026-07-06 19:15 +0800
« prev ^ index » next coverage.py v7.14.3, created at 2026-07-06 19:15 +0800
1"""
2git — Git version control operations.
4Actions: status, log, branch, diff, commit (dry-run)
5"""
7import subprocess
8from typing import Any
11def run(action: str = "status", repo_path: str = ".", message: str = "", **kwargs: Any) -> str:
12 actions = {
13 "status": ["git", "-C", repo_path, "status", "--short"],
14 "log": ["git", "-C", repo_path, "log", "--oneline", "-20"],
15 "branch": ["git", "-C", repo_path, "branch", "--all"],
16 "diff": ["git", "-C", repo_path, "diff", "--stat"],
17 "diff_unstaged": ["git", "-C", repo_path, "diff", "--stat", "HEAD"],
18 "remote": ["git", "-C", repo_path, "remote", "-v"],
19 "stash_list": ["git", "-C", repo_path, "stash", "list"],
20 }
22 if action == "commit_dry_run":
23 stat = _run(["git", "-C", repo_path, "diff", "--cached", "--stat"])
24 if not stat.strip():
25 return "[git] No staged changes to commit."
26 return f"[git] Would commit with message: '{message or '(empty)'}'\nStaged changes:\n{stat}"
27 if action not in actions:
28 return f"[git] Unknown action: {action}. Available: {', '.join(actions.keys())}, commit_dry_run"
30 return _run(actions[action])
33def _run(cmd: list[str]) -> str:
34 try:
35 r = subprocess.run(cmd, capture_output=True, text=True, timeout=15)
36 return r.stdout or r.stderr or "[git] No output."
37 except FileNotFoundError:
38 return "[git] Git not installed."
39 except Exception as e:
40 return f"[git] Error: {e}"
43__all__ = ["run"]