fix(update): only flag an update when the install is behind - #87
Open
cn0303 wants to merge 1 commit into
Open
Conversation
The update notifier flagged "update available" whenever the repo HEAD differed from the installed commit, in either direction. If the installed commit was ahead of the default branch (a dev build) or the branch had diverged (a force-push / rewritten history), it still nagged, and the in-place --force reinstall it offers would have discarded those local commits. GitHub's compare(base=installed, head=latest) already classifies the relationship. Gate on status == "ahead", the one case where the repo has strictly newer commits the install can fast-forward to. "behind" and "diverged" now stay silent, and so does an unavailable compare (e.g. the installed commit is no longer in the repo), rather than guessing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
The update notifier flagged "update available" whenever the repo HEAD differed
from the installed commit, in either direction. So an install that was ahead
of the default branch (a dev build) or on a branch that had diverged (a
force-push or rewritten history) still got nagged to update, and the in-place
--forcereinstall the button offers would have discarded those local commits.The cause
_compute_status()compared the installed commit to the repo HEAD and setupdate_available = Truefor any difference:GitHub's
compare(base=installed, head=latest)already classifies therelationship in its
statusfield (ahead,behind,diverged,identical),but the code ignored it.
The fix
Gate on
status == "ahead", the one case where the repo has strictly newercommits the install can fast-forward to:
behind(the install is ahead of the default branch) anddivergednow staysilent, as does an unavailable compare (for instance when the installed commit is
no longer in the repo), rather than guessing.
Before / after
aheadidenticalbehinddivergedTesting
Reproduced with unit tests that feed
_github_jsona canned compare response.Three new tests (
diverged, install-ahead, compare-unavailable) fail against thecurrent code and pass with the fix; the existing "update available" and
"up to date" cases still pass.
pytest tests/test_update.py: 20 passed. ruffcheck and ruff format green; pre-commit (mypy, bandit, typos) green.