fix git checkout
This commit is contained in:
parent
f9c84b211b
commit
33db841592
@ -53,11 +53,19 @@ class GitManager:
|
||||
logger.error(f"配置 remote 失败: {e}")
|
||||
|
||||
def pull(self) -> bool:
|
||||
"""拉取最新代码"""
|
||||
"""拉取最新代码(自动切回 main/master 分支)"""
|
||||
if not self.repo:
|
||||
return False
|
||||
|
||||
try:
|
||||
# 先切回 main/master,避免在无 upstream 的 fix 分支上 pull 失败
|
||||
current = self.repo.active_branch.name
|
||||
if current.startswith("fix/"):
|
||||
main_name = "main" if "main" in self.repo.heads else "master"
|
||||
if main_name in [h.name for h in self.repo.heads]:
|
||||
self.repo.heads[main_name].checkout()
|
||||
logger.info(f"从 {current} 切回 {main_name}")
|
||||
|
||||
origin = self.repo.remotes.origin
|
||||
origin.pull()
|
||||
logger.info("代码拉取成功")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user