@@ -219,6 +219,10 @@ def get_repo(self, repo_path: str) -> git.Repo:
219219 """
220220 if not self .base_path :
221221 raise ValueError ("No base repository path configured" )
222+
223+ # Initialize resolved_path to ensure it's always bound for exception handlers
224+ resolved_path = Path (repo_path )
225+
222226 try :
223227 resolved_path = self .resolve_repo_path (repo_path )
224228 validated_path = self .path_validator .validate_path (resolved_path )
@@ -229,9 +233,9 @@ def get_repo(self, repo_path: str) -> git.Repo:
229233 raise ValueError (f"Repository root { repo_root } not in allowed scope" )
230234 return repo
231235 except git .InvalidGitRepositoryError :
232- raise ValueError (f"{ validated_path } is not a Git repository" )
236+ raise ValueError (f"{ resolved_path } is not a Git repository" )
233237 except git .NoSuchPathError :
234- raise ValueError (f"Path { validated_path } does not exist" )
238+ raise ValueError (f"Path { resolved_path } does not exist" )
235239 except ValueError as e :
236240 # Re-raise ValueError with the original message
237241 raise ValueError (str (e ))
@@ -295,17 +299,20 @@ def git_create_branch(self, repo: git.Repo, branch_name: str, base_branch: str |
295299 try :
296300 # Try to get the ref (branch)
297301 base = repo .refs [base_branch ]
302+ new_branch = repo .create_head (branch_name , base )
303+ return f"Created branch '{ branch_name } ' from '{ base .name } '"
298304 except (IndexError , AttributeError ):
299305 # If it's not a ref, try to get the commit
300306 try :
301- base = repo .commit (base_branch )
307+ commit = repo .commit (base_branch )
308+ new_branch = repo .create_head (branch_name , commit .hexsha )
309+ return f"Created branch '{ branch_name } ' from '{ commit .hexsha } '"
302310 except (git .BadName , ValueError ):
303311 raise ValueError (f"Invalid base branch or commit: { base_branch } " )
304312 else :
305313 base = repo .active_branch
306-
307- new_branch = repo .create_head (branch_name , base )
308- return f"Created branch '{ branch_name } ' from '{ base .name if hasattr (base , 'name' ) else base .hexsha } '"
314+ new_branch = repo .create_head (branch_name , base )
315+ return f"Created branch '{ branch_name } ' from '{ base .name } '"
309316 except git .GitCommandError as e :
310317 raise ValueError (f"Failed to create branch: { str (e )} " )
311318
@@ -437,7 +444,7 @@ async def list_tools() -> list[Tool]:
437444 if repository :
438445 # In single-repo mode with a parent directory,
439446 # we still need repo_path but restrict it to subdirectories
440- if not git . repo . fun . is_git_dir (repository / ".git" ):
447+ if not (repository / ".git" ). exists ( ):
441448 schema ["properties" ]["repo_path" ]["description" ] = "Path to Git repository (must be under the configured base directory)"
442449 else :
443450 # If repository itself is a Git repo, remove repo_path as before
@@ -483,7 +490,7 @@ def by_commandline() -> Sequence[str]:
483490 async def call_tool (name : str , arguments : dict ) -> list [TextContent ]:
484491 try :
485492 # Auto-use configured repository only if it's actually a Git repository
486- if repository and git . repo . fun . is_git_dir (repository / ".git" ):
493+ if repository and (repository / ".git" ). exists ( ):
487494 arguments = arguments .copy ()
488495 arguments ["repo_path" ] = str (repository )
489496 elif repository :
0 commit comments