fix(updated): fall back to current branch when target_branch not found on remote

Prevents false 'update available' notifications when the stored
target_branch doesn't match any branch on the remote. Instead, compare
against the currently running branch for accurate update detection.
This commit is contained in:
mawei
2026-06-04 14:08:45 +08:00
parent 0cc5666b64
commit 30239bfbd2
+24 -7
View File
@@ -235,21 +235,38 @@ class Updater:
b = SP_BRANCH_MIGRATIONS.get((HARDWARE.get_device_type(), b), b)
return b
@property
def _resolve_target_branch(self) -> tuple[str, str | None]:
"""Resolve the effective target branch and its remote commit hash.
Falls back to current branch if target_branch doesn't exist on remote."""
branch = self.target_branch
remote_commit = self.branches[branch]
if remote_commit is None:
branch = self.get_branch(BASEDIR)
remote_commit = self.branches[branch]
return branch, remote_commit
@property
def update_ready(self) -> bool:
consistent_file = Path(os.path.join(FINALIZED, ".overlay_consistent"))
if consistent_file.is_file():
hash_mismatch = self.get_commit_hash(BASEDIR) != self.branches[self.target_branch]
branch_mismatch = self.get_branch(BASEDIR) != self.target_branch
on_target_branch = self.get_branch(FINALIZED) == self.target_branch
target_branch, target_commit = self._resolve_target_branch()
if target_commit is None:
return False
hash_mismatch = self.get_commit_hash(BASEDIR) != target_commit
branch_mismatch = self.get_branch(BASEDIR) != target_branch
on_target_branch = self.get_branch(FINALIZED) == target_branch
return ((hash_mismatch or branch_mismatch) and on_target_branch)
return False
@property
def update_available(self) -> bool:
if os.path.isdir(OVERLAY_MERGED) and len(self.branches) > 0:
hash_mismatch = self.get_commit_hash(OVERLAY_MERGED) != self.branches[self.target_branch]
branch_mismatch = self.get_branch(OVERLAY_MERGED) != self.target_branch
target_branch, target_commit = self._resolve_target_branch()
if target_commit is None:
return False
hash_mismatch = self.get_commit_hash(OVERLAY_MERGED) != target_commit
branch_mismatch = self.get_branch(OVERLAY_MERGED) != target_branch
return hash_mismatch or branch_mismatch
return False
@@ -352,8 +369,8 @@ class Updater:
cur_branch = self.get_branch(OVERLAY_MERGED)
cur_commit = self.get_commit_hash(OVERLAY_MERGED)
new_branch = self.target_branch
new_commit = self.branches[new_branch]
new_branch, new_commit = self._resolve_target_branch()
if (cur_branch, cur_commit) != (new_branch, new_commit):
cloudlog.info(f"update available, {cur_branch} ({str(cur_commit)[:7]}) -> {new_branch} ({str(new_commit)[:7]})")
else: