处理 runtime 目录已存在但不是 Git 仓库的情况

This commit is contained in:
孙小云 2026-01-09 18:15:47 +08:00
parent dd4ce57388
commit e56fb36ad3
1 changed files with 9 additions and 1 deletions

View File

@ -71,8 +71,16 @@ class Deployer:
# 直接使用 runtime_path 作为仓库路径
repo_path = self.runtime_path
if not repo_path.exists() or not (repo_path / '.git').exists():
# 检查是否是有效的 Git 仓库
if not (repo_path / '.git').exists():
self.logger.info("主仓库不存在,开始克隆...")
# 如果目录存在但不是 Git 仓库,先删除
if repo_path.exists():
self.logger.warning(f"目录 {repo_path} 已存在但不是 Git 仓库,将被删除")
shutil.rmtree(repo_path)
# 确保父目录存在
repo_path.parent.mkdir(parents=True, exist_ok=True)
# 克隆到 runtime 目录