From e481377317b634cfe10cb391c309f986ce72bf4b Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Mon, 1 Jan 2024 12:46:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20update=20=E7=9A=84?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/command/command.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/model/command/command.py b/model/command/command.py index b0f6c7c94..3a1abd1a6 100644 --- a/model/command/command.py +++ b/model/command/command.py @@ -364,14 +364,16 @@ class Command: else: commits_log += f"[{index}] {commit.message}\n-----------\n" index+=1 - remote_commit_hash = origin.refs.master.commit.hexsha[:6] + # remote_commit_hash = origin.refs.master.commit.hexsha[:6] + remote_commit_hash = origin.refs[curr_branch].commit.hexsha[:6] return True, f"当前分支: {curr_branch}\n当前版本: {now_commit.hexsha[:6]}\n最新版本: {remote_commit_hash}\n\n3条commit(非最新):\n{str(commits_log)}\nTips:\n1. 使用 update latest 更新至最新版本;\n2. 使用 update checkout <分支名> 切换代码分支。", "update" else: if l[1] == "latest": try: + curr_branch = repo.active_branch.name origin = repo.remotes.origin - origin.fetch() - commits = list(repo.iter_commits('master', max_count=1)) + repo.git.pull("origin", curr_branch, "-f") + commits = list(repo.iter_commits(curr_branch, max_count=1)) commit_log = commits[0].message tag = "update" if len(l) == 3 and l[2] == "r": @@ -390,6 +392,9 @@ class Command: origin = repo.remotes.origin origin.fetch() repo.git.checkout(l[2]) + + # 更新分支(强制) + repo.git.pull("origin", l[2], "-f") # 获得最新的 commit commits = list(repo.iter_commits(max_count=1))