Skip to content

fix(git): refresh branch labels after branch changes - #439

Merged
chriswritescode-dev merged 1 commit into
mainfrom
fix/branch-label-invalidation
Oct 17, 2026
Merged

chriswritescode-dev merged 1 commit into
mainfrom
fix/branch-label-invalidation

Conversation

@chriswritescode-dev

@chriswritescode-dev chriswritescode-dev commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

Switching branches in the Source Control panel did not update the branch shown in the session header. The header resolves its branch from GET /api/repos/:id/siblings, which includes the repo itself, and no git mutation invalidated that cache. Branch changes made outside the panel had related gaps.

Shared invalidation (lib/queryInvalidation.ts)

  • invalidateRepoGitCaches invalidates ['repo', 'siblings'] whenever it invalidates repo metadata, so switch, create, rename, fetch and pull refresh header and worktree branch labels.
  • invalidateRepoGitCachesDebounced (used for vcs.branch.updated) also invalidates the batched repo list git status, which repo cards prefer for their branch label.

External branch changes (contexts/EventContext.tsx)

  • A vcs.branch.updated event for a directory that matches no repo row, such as a worktree, now invalidates the sibling caches instead of being ignored.

Operations (hooks/useGit.ts)

  • Continue and abort now refresh repo metadata, so a label that read HEAD during a rebase returns to the branch name.

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation

Checklist

  • Code follows project style (no comments, named imports)
  • TypeScript types are properly defined
  • Tests added/updated (80% coverage target)
  • pnpm lint:frontend passes locally
  • Frontend typecheck passes locally

Tests

  • queryInvalidation.test.ts: sibling caches invalidated with repo metadata and kept when skipped; debounced flush invalidates the matching repo list status only.
  • EventContext.test.tsx: unmatched vcs.branch.updated invalidates siblings; matched event updates the repo cache and invalidates siblings.
  • useGit.test.tsx: continue and abort invalidate the repo and sibling caches.

Validation

  • vitest run src/lib src/contexts src/hooks src/components/source-control src/components/repo src/pages: 126 files, 1511 tests passed.
  • tsc -b and pnpm lint:frontend: clean.

Summary by CodeRabbit

  • Bug Fixes
    • Updated branch-change events now refresh sibling-repository data, including when the event comes from an unlisted worktree.
    • Continuing or aborting Git operations now refreshes repository and sibling-repository data.
    • Debounced Git updates now refresh the relevant repository-list status.

Invalidate the repo siblings cache with repo metadata so the session header branch updates after a switch, refresh the repo list git status and worktree siblings on vcs.branch.updated, and refresh repo metadata after continuing or aborting an operation.
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 9eb07dba-10f2-4a6c-9812-67a809f0dc5f
📥 Commits

Reviewing files that changed from the base of the PR and between 9075ab1 and f519993.

📒 Files selected for processing: 6
  • frontend/src/contexts/EventContext.test.tsx
  • frontend/src/contexts/EventContext.tsx
  • frontend/src/hooks/useGit.test.tsx
  • frontend/src/hooks/useGit.ts
  • frontend/src/lib/queryInvalidation.test.ts
  • frontend/src/lib/queryInvalidation.ts

Included review availability: This review used your included allowance. Your plan provides up to 5 included reviews per hour; 3 remain after this review.

📝 Walkthrough

Repository Git-cache invalidation now includes sibling-repository caches when repository metadata invalidation is enabled. Debounced invalidation also refreshes the relevant repository-list status. Branch-update events and Git continue and abort operations use these invalidation rules.

Changes: Repository cache invalidation

Layer / File(s) Summary
Cache invalidation rules
frontend/src/lib/queryInvalidation.ts, frontend/src/lib/queryInvalidation.test.ts
Git-cache invalidation now invalidates sibling caches when repository metadata invalidation is enabled. Debounced invalidation requests repository-list status invalidation. Tests cover sibling-cache behavior and the batched status entry refreshed after 200 ms.
Event and Git-operation invalidation
frontend/src/contexts/EventContext.tsx, frontend/src/contexts/EventContext.test.tsx, frontend/src/hooks/useGit.ts, frontend/src/hooks/useGit.test.tsx
An unmatched branch-update event now invalidates sibling caches. Tests cover unmatched and matched branch updates. Continue and abort operations no longer disable repository-metadata invalidation; their tests expect repository and sibling-cache invalidation.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to f5199

The changed invalidations reach the relevant branch-label and repo-card queries. No identified issue needs resolution before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: refreshing branch labels after Git branch changes.
Description check Passed The description is complete and directly matches the pull request changes. It includes the summary, change type, checklist, tests, and validation results. The listed validation commands are more speci…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is complete and directly matches the pull request changes. It includes the summary, change type, checklist, tests, and validation results. The listed validation commands are more specific than the template commands but provide equivalent frontend coverage.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@chriswritescode-dev
chriswritescode-dev merged commit 851a63f into main Oct 17, 2026
2 checks passed
@chriswritescode-dev
chriswritescode-dev deleted the fix/branch-label-invalidation branch October 17, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant