diff --git a/.gitignore b/.gitignore index 89ad554..fe7bfe5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ anthropic-agent-skills/ __pycache__/ .venv/ test-cache/ - diff --git a/aide-program/aide/flow/branch.py b/aide-program/aide/flow/branch.py index bc1175d..e3e52dd 100644 --- a/aide-program/aide/flow/branch.py +++ b/aide-program/aide/flow/branch.py @@ -92,9 +92,18 @@ class BranchManager: self.aide_dir = root / ".aide" self.branches_json = self.aide_dir / "branches.json" self.branches_md = self.aide_dir / "branches.md" + self.lock_path = self.aide_dir / "flow-status.lock" self._data: BranchesData | None = None self._current_branch_info: BranchInfo | None = None + def _cleanup_lock_file(self) -> None: + """清理 lock 文件,避免分支切换时的冲突""" + try: + if self.lock_path.exists(): + self.lock_path.unlink() + except OSError: + pass + def load_branches(self) -> BranchesData: """加载分支概况""" if self._data is not None: @@ -314,6 +323,9 @@ class BranchManager: source_branch = branch_info.source_branch start_commit = branch_info.start_commit + # 切换分支前清理 lock 文件,避免冲突 + self._cleanup_lock_file() + # 切回源分支 self.git.checkout(source_branch) @@ -343,6 +355,9 @@ class BranchManager: task_branch = branch_info.branch_name temp_branch = f"{task_branch}-merge" + # 切换分支前清理 lock 文件,避免冲突 + self._cleanup_lock_file() + # 从起始提交检出临时分支 self.git.checkout_new_branch(temp_branch, start_commit)