MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeWiki / GitManager

Class GitManager

codewiki/cli/git_manager.py:14–226  ·  view source on GitHub ↗

Manages git operations for documentation generation. Handles: - Status checking - Branch creation - Committing documentation - Remote detection

Source from the content-addressed store, hash-verified

12
13
14class GitManager:
15 """
16 Manages git operations for documentation generation.
17
18 Handles:
19 - Status checking
20 - Branch creation
21 - Committing documentation
22 - Remote detection
23 """
24
25 def __init__(self, repo_path: Path):
26 """
27 Initialize git manager.
28
29 Args:
30 repo_path: Path to git repository
31
32 Raises:
33 RepositoryError: If not a valid git repository
34 """
35 self.repo_path = Path(repo_path).expanduser().resolve()
36
37 try:
38 self.repo = git.Repo(repo_path, search_parent_directories=True)
39 except git.InvalidGitRepositoryError:
40 raise RepositoryError(
41 f"Not a git repository: {repo_path}\n\n"
42 "To initialize a git repository: git init"
43 )
44
45 def check_clean_working_directory(self) -> Tuple[bool, str]:
46 """
47 Check if working directory is clean (no uncommitted changes).
48
49 Returns:
50 Tuple of (is_clean, status_message)
51 """
52 if self.repo.is_dirty(untracked_files=True):
53 status_lines = []
54
55 # Changed files
56 changed = [item.a_path for item in self.repo.index.diff(None)]
57 if changed:
58 status_lines.append(f"Modified: {', '.join(changed[:3])}")
59 if len(changed) > 3:
60 status_lines.append(f"... and {len(changed) - 3} more")
61
62 # Untracked files
63 untracked = self.repo.untracked_files
64 if untracked:
65 status_lines.append(f"Untracked: {', '.join(untracked[:3])}")
66 if len(untracked) > 3:
67 status_lines.append(f"... and {len(untracked) - 3} more")
68
69 return False, "\n".join(status_lines)
70
71 return True, "Working directory is clean"

Callers 1

generate_commandFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected