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\nTo initialize a git repository: git init"
42 )
43
44 def check_clean_working_directory(self) -> Tuple[bool, str]:
45 """
46 Check if working directory is clean (no uncommitted changes).
47
48 Returns:
49 Tuple of (is_clean, status_message)
50 """
51 if self.repo.is_dirty(untracked_files=True):
52 status_lines = []
53
54 # Changed files
55 changed = [item.a_path for item in self.repo.index.diff(None)]
56 if changed:
57 status_lines.append(f"Modified: {', '.join(changed[:3])}")
58 if len(changed) > 3:
59 status_lines.append(f"... and {len(changed) - 3} more")
60
61 # Untracked files
62 untracked = self.repo.untracked_files
63 if untracked:
64 status_lines.append(f"Untracked: {', '.join(untracked[:3])}")
65 if len(untracked) > 3:
66 status_lines.append(f"... and {len(untracked) - 3} more")
67
68 return False, "\n".join(status_lines)
69
70 return True, "Working directory is clean"
71

Callers 1

generate_commandFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected