Clean up nested duplicate: v2/v2/tools/git_tools.py
Browse files- v2/v2/tools/git_tools.py +0 -42
v2/v2/tools/git_tools.py
DELETED
|
@@ -1,42 +0,0 @@
|
|
| 1 |
-
"""Git history tools — log, diff, blame — over the campus repo."""
|
| 2 |
-
|
| 3 |
-
from dataclasses import dataclass
|
| 4 |
-
|
| 5 |
-
from tools.guard import run_checked
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
@dataclass
|
| 9 |
-
class GitTools:
|
| 10 |
-
repo_root: str
|
| 11 |
-
|
| 12 |
-
def log(self, since: str = "7 days ago", limit: int = 20,
|
| 13 |
-
path: str = "") -> str:
|
| 14 |
-
argv = ["git", "log", "--oneline", f"--since={since}", f"-{limit}"]
|
| 15 |
-
if path:
|
| 16 |
-
argv += ["--", path]
|
| 17 |
-
result = run_checked(argv, cwd=self.repo_root, timeout=15)
|
| 18 |
-
return result.stdout if result.ok else f"(git log failed: {result.stderr or result.blocked_reason})"
|
| 19 |
-
|
| 20 |
-
def diff(self, ref: str = "HEAD~5..HEAD", path: str = "",
|
| 21 |
-
stat_only: bool = False) -> str:
|
| 22 |
-
argv = ["git", "diff", ref]
|
| 23 |
-
if stat_only:
|
| 24 |
-
argv.append("--stat")
|
| 25 |
-
if path:
|
| 26 |
-
argv += ["--", path]
|
| 27 |
-
result = run_checked(argv, cwd=self.repo_root, timeout=30)
|
| 28 |
-
out = result.stdout if result.ok else f"(git diff failed: {result.stderr or result.blocked_reason})"
|
| 29 |
-
return out[:20_000]
|
| 30 |
-
|
| 31 |
-
def blame(self, path: str, line_start: int = 1,
|
| 32 |
-
line_end: int = 50) -> str:
|
| 33 |
-
argv = ["git", "blame", "-L", f"{line_start},{line_end}",
|
| 34 |
-
"--date=short", "--", path]
|
| 35 |
-
result = run_checked(argv, cwd=self.repo_root, timeout=20)
|
| 36 |
-
return result.stdout if result.ok else f"(git blame failed: {result.stderr or result.blocked_reason})"
|
| 37 |
-
|
| 38 |
-
def recent_authors(self, path: str, limit: int = 5) -> str:
|
| 39 |
-
argv = ["git", "log", f"-{limit}", "--format=%h %ad %an %s",
|
| 40 |
-
"--date=short", "--", path]
|
| 41 |
-
result = run_checked(argv, cwd=self.repo_root, timeout=15)
|
| 42 |
-
return result.stdout if result.ok else ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|