fix(toolbar): refresh the branch list after a commit so the Push badge follows - #546
Merged
Merged
Conversation
β¦e follows The Push and Pull badges count the commits ahead of / behind the upstream, and those two numbers ride on the branch query (`GitBranch.aheadCount`/`behindCount`), not on the log. Every flow that wrote a commit invalidated `git-log` and `git-status` only, so the graph redrew correctly while the toolbar went on claiming there was nothing to push β `useBranches` has a 15s `staleTime`, and react-query only refetches a stale query on a trigger the toolbar never gets (it is never remounted). Replace the copied-by-hand pair with one shared `refreshAfterHistoryChange` in `lib/repoRefresh.ts`, holding the invariant in its doc comment, and route every action that writes, removes or rewrites a commit through it: the commit / amend / staging panel, cherry-pick (graph menu and palette), reset, revert, fixup, autosquash, rebase (controls and the dedicated window's events), bisect, and the board auto-sync, which committed and pushed in the background without refreshing anything at all. `features/graph/lib/graphQueryRefresh.ts` was the function that froze the incomplete pair, so it goes away. Also drops the legacy key-returning i18n mock from `CommitDetailsPanel.test.tsx` and asserts the real English copy instead, per CLAUDE.md.
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 changed
Committing now updates the toolbar's Push badge. Before this, you committed and the Push button went
on showing nothing β or the previous count β while the graph beneath it already showed the new
commit. Same for every other action that moves the branch tip: amend, cherry-pick, reset, revert,
fixup, autosquash, rebase, bisect, and the board's background auto-sync (which committed and
pushed without refreshing anything at all).
The badge markup itself was already there and correct; nothing about it changed.
Why
aheadCount/behindCountcome from the['branches', repoPath]query β they live onGitBranch,not on the log. Every flow that wrote a commit invalidated
git-logandgit-statusonly, so thegraph redrew correctly while the toolbar kept claiming there was nothing to push.
useBrancheshasa 15s
staleTime, and react-query only refetches a stale query on a trigger the toolbar never gets:it is never remounted, so in practice the badge stayed wrong until the window lost and regained
focus.
It was not an isolated omission β the
git-log+git-statuspair was copied by hand into about adozen call sites and
brancheswas missing from nearly all of them, so the fix is one sharedrefreshAfterHistoryChange(queryClient, repoPath)inlib/repoRefresh.tswith the invariant writteninto its doc comment, and every history-changing flow routed through it.
refreshAfterHeadMovenowdelegates to it.
Notes for the reviewer
features/graph/lib/graphQueryRefresh.tsis deleted. ItsrefreshLogAndStatuswas preciselythe function that froze the incomplete pair and handed it to six graph hooks, so keeping it as a
wrapper would keep the trap. Its six callers now import the shared helper.
useStashMenuand the branchmenu's
run()now also invalidatebranches(a stash pop changes no commit). It is one cheaplocal query, and a refresh helper that is almost right per caller is how this bug happened β I
preferred one rule over six judgements.
useBranchMenuActionshad a duplicatebranchesinvalidation right after; that line is gone.
useBoardConfigAutoSyncimports thequeryClientsingleton directly, likeuseAutoFetchdoes β there is no component around
syncIfDirtyto hold auseQueryClient.ahead = 0, so the badgeis empty even though everything is unpushed. That is a separate design decision (should it count
from the base?), not a regression this introduces.
CommitDetailsPanel.test.tsxloses its legacy key-returning i18n mock and asserts the realEnglish copy instead, per CLAUDE.md's rule for touching such a file. That is why its diff is bigger
than the one assertion I added.
Verification
pnpm typecheckpnpm lint(warnings only, all pre-existing)pnpm --filter @git-manager/desktop testβ 762 files / 8317 tests green. One earlier run hadmain.test.tsxhit its 5s timeout under CPU load; green on its own and on a full re-run.cargo testβ n/ais pinned by unit tests instead:
refreshAfterHistoryChangeinvalidates all three keys(asserted per key β
branchesis the one that went missing), and the commit panel's refreshreaches the branch query. No e2e scenario covers the Push badge after a commit either: the
remote-aheadfixture has an upstream but a clean working tree, and dirtying it would changethe doc screenshots that fixture feeds. Happy to build that scenario if you want it.
If this PR touchesβ¦
repoRefresh.test.ts,CommitDetailsPanel.test.tsx)refresh that skips it is silently wrong" is recorded in
refreshAfterHistoryChange's doccomment, beside the code that enforces it