Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions codemcp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,27 @@ def truncate_output_content(content: str, prefer_end: bool = True) -> str:
truncated_content += f"\n... (output truncated, showing {MAX_LINES_TO_READ} of {total_lines} lines)"

return truncated_content


def find_git_root(start_path: str) -> Optional[str]:
"""Find the root of the Git repository starting from the given path.

Args:
start_path: The path to start searching from

Returns:
The absolute path to the Git repository root, or None if not found
"""
path = os.path.abspath(start_path)

while path:
if os.path.isdir(os.path.join(path, ".git")):
return path

parent = os.path.dirname(path)
if parent == path: # Reached filesystem root
return None

path = parent

return None
Loading