Polish customer update flow and prepare ZIP installation
This commit is contained in:
+25
-10
@@ -49,8 +49,8 @@ def _git(*args, timeout=60, check=True):
|
||||
return result
|
||||
|
||||
|
||||
def update_package():
|
||||
"""Fetch the release main branch and fast-forward only a clean local main."""
|
||||
def _check_release():
|
||||
"""Inspect the release before considering any local file changes."""
|
||||
if not (PLUGIN_DIR / ".git").exists():
|
||||
raise UpdateError(
|
||||
"not_git", "当前插件不是 Git 安装。",
|
||||
@@ -64,14 +64,7 @@ def update_package():
|
||||
"请先检查并切换分支;本地分支上的修改不会自动合并。",
|
||||
)
|
||||
|
||||
if _git("status", "--porcelain", "--untracked-files=no").stdout.strip():
|
||||
raise UpdateError(
|
||||
"local_changes", "插件目录有未提交的代码修改。",
|
||||
"请先保存、提交或暂存修改;更新不会覆盖这些文件。",
|
||||
)
|
||||
|
||||
old_commit = _git("rev-parse", "HEAD").stdout.strip()
|
||||
old_requirements = _git("show", "HEAD:requirements.txt", check=False).stdout
|
||||
fetched = _git("fetch", "--no-tags", RELEASE_REPOSITORY_URL, "main", timeout=90, check=False)
|
||||
if fetched.returncode:
|
||||
raise UpdateError(
|
||||
@@ -80,7 +73,7 @@ def update_package():
|
||||
)
|
||||
new_commit = _git("rev-parse", "FETCH_HEAD").stdout.strip()
|
||||
if old_commit == new_commit:
|
||||
return {"updated": False, "version": old_commit[:7], "requirements_changed": False}
|
||||
return old_commit, new_commit
|
||||
|
||||
if _git("merge-base", "--is-ancestor", "HEAD", "FETCH_HEAD", check=False).returncode:
|
||||
raise UpdateError(
|
||||
@@ -88,6 +81,28 @@ def update_package():
|
||||
"请手动比较两个分支并合并,不要强制重置本地文件。",
|
||||
)
|
||||
|
||||
if _git("status", "--porcelain", "--untracked-files=no").stdout.strip():
|
||||
raise UpdateError(
|
||||
"local_changes", "插件目录有未提交的代码修改。",
|
||||
"请先保存、提交或暂存修改;更新不会覆盖这些文件。",
|
||||
)
|
||||
|
||||
return old_commit, new_commit
|
||||
|
||||
|
||||
def check_for_update():
|
||||
"""Check whether the installed version can be updated without changing files."""
|
||||
old_commit, new_commit = _check_release()
|
||||
return {"update_available": old_commit != new_commit}
|
||||
|
||||
|
||||
def update_package():
|
||||
"""Fetch the release main branch and fast-forward only a clean local main."""
|
||||
old_commit, new_commit = _check_release()
|
||||
if old_commit == new_commit:
|
||||
return {"updated": False, "version": old_commit[:7], "requirements_changed": False}
|
||||
|
||||
old_requirements = _git("show", "HEAD:requirements.txt", check=False).stdout
|
||||
new_requirements = _git("show", "FETCH_HEAD:requirements.txt", check=False).stdout
|
||||
merged = _git("merge", "--ff-only", "FETCH_HEAD", check=False)
|
||||
if merged.returncode:
|
||||
|
||||
Reference in New Issue
Block a user