fix(desktop): show diffs against base branch in sidebar#1495
Conversation
The sidebar was only counting staged/unstaged/untracked files for diff stats, ignoring the againstBase comparison entirely. This meant workspaces with committed changes ahead of main but no uncommitted changes showed no diff stats. Extract useGitChangesStatus hook to share the base-branch resolution logic (store override → detected default → "main" fallback) between ChangesContent and WorkspaceListItem. The sidebar now correctly shows the full diff against the base branch.
📝 WalkthroughWalkthroughIntroduces a new useGitChangesStatus hook and replaces direct TRPC branch/status queries in WorkspaceListItem and ChangesContent with this hook; it returns status, isLoading, and effectiveBaseBranch and centralizes branch resolution and status fetching. Changes
Sequence DiagramsequenceDiagram
participant Component as Component (WorkspaceListItem / ChangesContent)
participant Hook as useGitChangesStatus Hook
participant Store as useChangesStore
participant TRPC as tRPC (getBranches / getStatus)
Component->>Hook: call with { worktreePath, refetchInterval, ... }
Hook->>Store: read baseBranch
Hook->>TRPC: query getBranches (if worktreePath)
TRPC-->>Hook: branchData (defaultBranch)
Hook->>Hook: compute effectiveBaseBranch (store or branchData or "main")
Hook->>TRPC: query getStatus (with effectiveBaseBranch, if worktreePath)
TRPC-->>Hook: status
Hook-->>Component: return { status, isLoading, effectiveBaseBranch }
Component->>Component: render using status & effectiveBaseBranch
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Summary
againstBasediff comparisonuseGitChangesStatushook to deduplicate the base-branch resolution logic between the sidebar and the changes viewChanges
useGitChangesStatus— resolves the effective base branch (store override → detected default →"main"fallback) and fetcheschanges.getStatuswith itchanges.getStatus(which was missingdefaultBranch), and now prefersagainstBasefor diff stats over just staged/unstaged/untrackedTest Plan
Summary by CodeRabbit
New Features
Bug Fixes
Refactor