From 7dd8bc582aeb47c1f00f494f75f3d70bac29786a Mon Sep 17 00:00:00 2001 From: KimigaiiWuyi <444835641@qq.com> Date: Sun, 22 Sep 2024 23:18:33 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E4=BC=98=E5=8C=96=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=8F=92=E4=BB=B6=E7=9B=B8=E5=85=B3=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E7=9A=84=E8=BF=94=E5=9B=9E=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gsuid_core/utils/plugins_update/_plugins.py | 47 ++++++++++++++------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/gsuid_core/utils/plugins_update/_plugins.py b/gsuid_core/utils/plugins_update/_plugins.py index 83b4f17..29c40f6 100644 --- a/gsuid_core/utils/plugins_update/_plugins.py +++ b/gsuid_core/utils/plugins_update/_plugins.py @@ -380,6 +380,15 @@ def update_from_git( logger.info(f'[更新] 准备更新 [{plugin_name}], 更新等级为{level}') + # 先执行git fetch + logger.info(f'[更新][{plugin_name}] 正在执行 git fetch') + o.fetch() + + default_branch_ref = repo.git.symbolic_ref('refs/remotes/origin/HEAD') + default_branch = default_branch_ref.split('/')[-1] # 提取主分支名称 + + commits_diff = list(repo.iter_commits(f'HEAD..origin/{default_branch}')) + if level >= 2: logger.warning(f'[更新][{plugin_name}] 正在执行 git clean --xdf') logger.warning('[更新] 你有 2 秒钟的时间中断该操作...') @@ -398,22 +407,30 @@ def update_from_git( logger.info(f'[更新][{repo.head.commit.hexsha[:7]}] 获取远程最新版本') except GitCommandError as e: logger.warning(f'[更新] 更新失败...{e}!') - return ['更新失败, 请检查控制台...'] + return [f'更新插件 {plugin_name} 中...', '更新失败, 请检查控制台...'] - commits = list(repo.iter_commits(max_count=40)) - log_list = [f'更新插件 {plugin_name} 中...'] - for commit in commits: - if isinstance(commit.message, str): - if log_key: - for key in log_key: - if key in commit.message: - log_list.append(commit.message.replace('\n', '')) - if len(log_list) >= log_limit: - break - else: - log_list.append(commit.message.replace('\n', '')) - if len(log_list) >= log_limit: - break + # commits = list(repo.iter_commits(max_count=40)) + if commits_diff: + commits = commits_diff + else: + commits = [] + log_list = [] + if commits: + log_list.append(f'✅本次插件 {plugin_name} , 更新内容如下:') + for commit in commits: + if isinstance(commit.message, str): + if log_key: + for key in log_key: + if key in commit.message: + log_list.append(commit.message.replace('\n', '')) + if len(log_list) >= log_limit: + break + else: + log_list.append(commit.message.replace('\n', '')) + if len(log_list) >= log_limit: + break + else: + log_list.append(f'✅插件 {plugin_name} 本次无更新内容!') return log_list