From b464fdc333f1156b4204ab790d17c06e83e0db8c Mon Sep 17 00:00:00 2001 From: Will Miao Date: Wed, 29 Jul 2026 21:23:39 +0800 Subject: [PATCH] fix(update): preserve .git on release channel switch, use git checkout tag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, switching to the release channel would delete .git/ and fall back to a ZIP download. This broke update.bat, manual git commands, and CM git-based update detection. Now the release path uses git checkout when .git exists, and only falls back to ZIP when .git is absent (CM CNR installs). .git is never deleted - the ZIP→nightly path remains a one-way upgrade via _init_git_repo. Also updates locale strings (en, zh-CN, zh-TW, ja) to remove the now-inaccurate "remove the Git repository" wording. --- locales/en.json | 2 +- locales/ja.json | 2 +- locales/zh-CN.json | 2 +- locales/zh-TW.json | 2 +- py/routes/update_routes.py | 22 ++++++++++------------ 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/locales/en.json b/locales/en.json index ec191bd5..1af60162 100644 --- a/locales/en.json +++ b/locales/en.json @@ -1782,7 +1782,7 @@ "nightlyTitle": "Switch to Nightly Channel", "nightlyMessage": "Switching to Nightly will initialize a Git repository and track the latest main branch commits. Updates will be more frequent but may be unstable. You can switch back to Release at any time.", "releaseTitle": "Switch to Release Channel", - "releaseMessage": "Switching to Release will remove the Git repository and install the latest stable release. Future updates will use stable releases only.", + "releaseMessage": "Switching to Release will checkout the latest stable release tag. Your Git repository and settings are preserved. You can switch back to Nightly at any time.", "switching": "Switching to {channel} channel...", "completed": "Successfully switched to {channel} channel", "failed": "Failed to switch channel" diff --git a/locales/ja.json b/locales/ja.json index 9c7f9424..3b699f2c 100644 --- a/locales/ja.json +++ b/locales/ja.json @@ -1782,7 +1782,7 @@ "nightlyTitle": "ナイトリーチャンネルに切り替え", "nightlyMessage": "ナイトリーに切り替えると、Gitリポジトリが初期化され、mainブランチの最新コミットを追跡します。更新頻度は高くなりますが、不安定な場合があります。いつでもリリース版に戻せます。", "releaseTitle": "リリースチャンネルに切り替え", - "releaseMessage": "リリースに切り替えると、Gitリポジトリが削除され、最新の安定版がインストールされます。以降の更新は安定版のみが使用されます。", + "releaseMessage": "リリースに切り替えると、最新の安定版タグにチェックアウトされます。Gitリポジトリと設定は保持されます。いつでもNightlyに戻せます。", "switching": "{channel} チャンネルに切り替え中...", "completed": "{channel} チャンネルに切り替えました", "failed": "チャンネルの切り替えに失敗しました" diff --git a/locales/zh-CN.json b/locales/zh-CN.json index 9c4e0848..3b3f3a87 100644 --- a/locales/zh-CN.json +++ b/locales/zh-CN.json @@ -1782,7 +1782,7 @@ "nightlyTitle": "切换到 Nightly", "nightlyMessage": "切换到 Nightly 将初始化 Git 仓库并跟踪 main 分支的最新提交。更新更频繁但可能不稳定,可随时切回稳定版。", "releaseTitle": "切换到稳定版", - "releaseMessage": "切换到稳定版将移除 Git 仓库并安装最新的稳定发布版本,后续仅使用稳定版更新。", + "releaseMessage": "切换到稳定版将检出最新的发布标签。Git 仓库和您的设置均会保留。可随时切换回每日构建版。", "switching": "正在切换到 {channel} 频道...", "completed": "已切换到 {channel} 频道", "failed": "切换频道失败" diff --git a/locales/zh-TW.json b/locales/zh-TW.json index d130963c..dccce3ec 100644 --- a/locales/zh-TW.json +++ b/locales/zh-TW.json @@ -1782,7 +1782,7 @@ "nightlyTitle": "切换到 Nightly", "nightlyMessage": "切换到 Nightly 将初始化 Git 仓库并跟踪 main 分支的最新提交。更新更频繁但可能不稳定,可随时切回稳定版。", "releaseTitle": "切换到稳定版", - "releaseMessage": "切换到稳定版将移除 Git 仓库并安装最新的稳定发布版本,后续仅使用稳定版更新。", + "releaseMessage": "切換到穩定版將檢出最新的發布標籤。Git 倉庫和您的設定均會保留。可隨時切換回每日構建版。", "switching": "正在切換到 {channel} 頻道...", "completed": "已切換到 {channel} 頻道", "failed": "切換頻道失敗" diff --git a/py/routes/update_routes.py b/py/routes/update_routes.py index 5c3b5582..bcf6d094 100644 --- a/py/routes/update_routes.py +++ b/py/routes/update_routes.py @@ -291,9 +291,11 @@ class UpdateRoutes: async def switch_channel(request): """ Switch between release and nightly update channels. - - Release → Nightly: Initialize a Git repository (from ZIP/CM stable mode) - Nightly → Release: Remove .git, download latest release ZIP, write .tracking + + ZIP/CNR install → Nightly: git init + checkout main (one-way upgrade) + Git install → Release: git checkout latest tag (.git preserved) + ZIP/CNR install → Release: ZIP download (no .git, stays in ZIP mode) + Git install → Nightly: git checkout main + pull """ try: body = await request.json() if request.has_body else {} @@ -336,21 +338,17 @@ class UpdateRoutes: finally: UpdateRoutes._restore_git(git_backup, git_folder, success, 'nightly') else: - git_backup = None - if os.path.exists(git_folder): - git_backup = UpdateRoutes._backup_git(git_folder, 'release') - success = False new_version = '' - try: - if os.path.exists(git_folder): - shutil.rmtree(git_folder) + if os.path.exists(git_folder): + success, new_version = await UpdateRoutes._perform_git_update( + plugin_root, nightly=False + ) + else: tracking_file = os.path.join(plugin_root, '.tracking') if os.path.exists(tracking_file): os.remove(tracking_file) success, new_version = await UpdateRoutes._download_and_replace_zip(plugin_root) - finally: - UpdateRoutes._restore_git(git_backup, git_folder, success, 'release') finally: _restore_preserved_items(plugin_root, staged_backup_dir, staged_items)