From e7d78f249d62486fb957af09d761a68e164cae8d Mon Sep 17 00:00:00 2001 From: luojian Date: Tue, 8 Jul 2025 11:09:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/project_init.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/project_init.py b/scripts/project_init.py index b621e62..19e993a 100644 --- a/scripts/project_init.py +++ b/scripts/project_init.py @@ -33,11 +33,12 @@ class ProjectInit(Task): repo.git.fetch(remote_name) - # 2. 创建本地分支并跟踪远程分支 - remote_branch_ref = f"{remote_name}/{branch_name}" - local_branch = repo.create_head(branch_name, remote_branch_ref) # 创建本地分支指向远程 - local_branch.set_tracking_branch(repo.remotes[remote_name].refs[branch_name]) # 设置跟踪 - local_branch.checkout() # 切换到该分支 + if repo.active_branch.name != branch_name: + # 2. 创建本地分支并跟踪远程分支 + remote_branch_ref = f"{remote_name}/{branch_name}" + local_branch = repo.create_head(branch_name, remote_branch_ref) # 创建本地分支指向远程 + local_branch.set_tracking_branch(repo.remotes[remote_name].refs[branch_name]) # 设置跟踪 + local_branch.checkout() # 切换到该分支 self.context.local_repo_branch = repo.active_branch.name self.context.local_repo_commit = repo.head.commit.hexsha[:10]