fixbug: plan

This commit is contained in:
莘权 马 2024-04-09 14:16:22 +08:00
parent 516c9462ce
commit d7b9325bc8
2 changed files with 17 additions and 1 deletions

View file

@ -10,6 +10,7 @@ from metagpt.logs import ToolLogItem, log_tool_output
from metagpt.schema import BugFixContext, Message
from metagpt.tools.tool_registry import register_tool
from metagpt.utils.common import any_to_str
from metagpt.utils.project_repo import ProjectRepo
@register_tool(tags=["software development", "ProductManager"])
@ -365,7 +366,10 @@ async def git_archive(project_path: str | Path) -> str:
)
ctx = Context()
ctx.set_repo_dir(project_path)
project_dir = ProjectRepo.search_project_path(project_path)
if not project_dir:
ValueError(f"{project_path} is not a valid git repository.")
ctx.set_repo_dir(project_dir)
files = " ".join(ctx.git_repo.changed_files.keys())
outputs = [ToolLogItem(name="cmd", value=f"git add {files}")]
log_tool_output(output=outputs, tool_name=git_archive.__name__)

View file

@ -10,6 +10,7 @@
from __future__ import annotations
from pathlib import Path
from typing import Optional
from metagpt.const import (
CLASS_VIEW_FILE_REPO,
@ -148,3 +149,14 @@ class ProjectRepo(FileRepository):
@property
def src_relative_path(self) -> Path | None:
return self._srcs_path
@staticmethod
def search_project_path(filename: str | Path) -> Optional[Path]:
root = Path(filename).parent if Path(filename).is_file() else Path(filename)
root = root.resolve()
while str(root) != "/":
git_repo = root / ".git"
if git_repo.exists():
return root
root = root.parent
return None