Skip to content

fix(desktop): show diffs against base branch in sidebar#1495

Merged
Kitenite merged 2 commits into
mainfrom
kitenite/diffs-arent-showing
Feb 14, 2026
Merged

fix(desktop): show diffs against base branch in sidebar#1495
Kitenite merged 2 commits into
mainfrom
kitenite/diffs-arent-showing

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Feb 14, 2026

Summary

  • The sidebar workspace list was only counting staged/unstaged/untracked files for diff stats, completely ignoring the againstBase diff comparison
  • Workspaces with committed changes ahead of main but no uncommitted local changes showed no diff stats in the sidebar
  • Extracted a shared useGitChangesStatus hook to deduplicate the base-branch resolution logic between the sidebar and the changes view

Changes

  • New hook: useGitChangesStatus — resolves the effective base branch (store override → detected default → "main" fallback) and fetches changes.getStatus with it
  • WorkspaceListItem: Uses the new hook instead of raw changes.getStatus (which was missing defaultBranch), and now prefers againstBase for diff stats over just staged/unstaged/untracked
  • ChangesContent: Refactored to use the same shared hook, removing duplicated base-branch resolution logic

Test Plan

  • Open a workspace with commits ahead of main but no uncommitted changes — sidebar should now show +/- diff stats
  • Open a workspace with only uncommitted changes (no commits ahead) — sidebar should still show +/- stats from staged/unstaged/untracked
  • Open the changes view — verify it still shows the correct base branch and file list
  • Hover over a sidebar item and verify diff stats appear on first hover

Summary by CodeRabbit

  • New Features

    • Unified Git status handling for workspace views, with a single source driving loading state and base-branch selection.
  • Bug Fixes

    • More accurate diff/stat reporting and base-branch detection for workspace changes.
    • Improved loading behavior to avoid stale or missing status displays.
  • Refactor

    • Consolidated change-fetching logic and simplified lazy/hover-driven loading for workspace change lists.

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.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 14, 2026

📝 Walkthrough

Walkthrough

Introduces 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

Cohort / File(s) Summary
New Hook Implementation
apps/desktop/src/renderer/screens/main/hooks/useGitChangesStatus/useGitChangesStatus.ts, apps/desktop/src/renderer/screens/main/hooks/useGitChangesStatus/index.ts
Adds useGitChangesStatus hook and UseGitChangesStatusOptions; performs conditional getBranches and getStatus queries, computes effectiveBaseBranch, and returns { status, isLoading, effectiveBaseBranch }.
Hook Export
apps/desktop/src/renderer/screens/main/hooks/index.ts
Adds public export for useGitChangesStatus.
Workspace Sidebar Update
apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/WorkspaceListItem.tsx
Replaces local getStatus query with useGitChangesStatus; adapts to new status shape (branch, againstBase, staged, unstaged, untracked); changes lazy-loading enabled condition to depend on hover/type rather than explicit worktreePath check; adjusts diff-stat computation to prefer againstBase.
Changes View Update
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ChangesContent/ChangesContent.tsx
Replaces manual base-branch and status fetching with useGitChangesStatus; removes separate branch query and base-branch fallback logic and passes effectiveBaseBranch downstream.
Manifest
package.json
Minor change (lines changed +6/-18) related to package metadata (contextual).

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hopped through branches, sniffed the diff,
One hook to gather every gitly whiff.
Status in paw, base branch in sight,
I rabbit-hop code into tidy light. ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: showing diffs against base branch in sidebar, which directly addresses the core issue resolved in this changeset.
Description check ✅ Passed The PR description comprehensively covers the problem, solution, affected components, and includes a detailed test plan matching the template structure.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kitenite/diffs-arent-showing

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
apps/desktop/src/renderer/screens/main/hooks/useGitChangesStatus/useGitChangesStatus.ts (1)

27-40: getStatus may fire with stale effectiveBaseBranch before getBranches resolves.

When baseBranch is null (no store override) and getBranches hasn't resolved yet, effectiveBaseBranch falls back to "main". Once branchData arrives with a different defaultBranch, the query re-fires. This causes a wasted initial fetch against the wrong base.

You could gate the status query on branchData being available (when there's no store override), or accept the double-fetch as a trade-off for faster first paint:

Optional: gate on branch data availability
+	const hasBranchInfo = baseBranch !== null || branchData !== undefined;
+
 	const { data: status, isLoading } = electronTrpc.changes.getStatus.useQuery(
 		{
 			worktreePath: worktreePath || "",
 			defaultBranch: effectiveBaseBranch,
 		},
 		{
-			enabled: enabled && !!worktreePath,
+			enabled: enabled && !!worktreePath && hasBranchInfo,
 			refetchInterval,
 			refetchOnWindowFocus,
 			staleTime,
 		},
 	);
apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/WorkspaceListItem.tsx (1)

146-161: Edge case: workspaces with both committed and uncommitted changes show only againstBase stats.

If a workspace has commits ahead of the base branch and additional uncommitted changes, the sidebar will display only the againstBase diff stats — the uncommitted changes won't be reflected. This seems intentional per the PR objectives, but worth confirming it matches the desired UX. Users might expect to see the combined picture.


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.

❤️ Share

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

@Kitenite Kitenite merged commit 902a11f into main Feb 14, 2026
6 checks passed
@Kitenite Kitenite deleted the kitenite/diffs-arent-showing branch February 14, 2026 10:01
@github-actions
Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch
  • ⚠️ Electric Fly.io app
  • ⚠️ Streams Fly.io app

Thank you for your contribution! 🎉

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