Skip to content

Paginate git branch listing and search results#1691

Merged
juliusmarminge merged 9 commits intomainfrom
t3code/git-branch-pagination
Apr 2, 2026
Merged

Paginate git branch listing and search results#1691
juliusmarminge merged 9 commits intomainfrom
t3code/git-branch-pagination

Conversation

@juliusmarminge
Copy link
Copy Markdown
Member

@juliusmarminge juliusmarminge commented Apr 2, 2026

Summary

  • Added cursor-based pagination to git listBranches, including nextCursor and totalCount metadata.
  • Moved branch deduping/query helpers into shared git utilities and applied query filtering before pagination on the server.
  • Updated the branch picker to use an infinite query, load additional pages on scroll, and show branch count/loading status.
  • Extended contracts, tests, and the branch-list benchmark to cover the new paging behavior.

Testing

  • Not run in this context.
  • New coverage was added for server-side branch pagination/filtering and client-side branch query invalidation/infinite search behavior.

Note

Medium Risk
Medium risk because it changes the git listBranches RPC contract and server-side git status/branch listing behavior, plus updates multiple UI consumers to rely on the new pagination and status flags.

Overview
Adds cursor-based pagination and server-side search to GitCore.listBranches, returning nextCursor/totalCount, applying query filtering before pagination, and deduping origin/* remote refs when a matching local branch exists (logic moved to @t3tools/shared/git).

Extends GitStatusResult/statusDetails to include isRepo, hasOriginRemote, and isDefaultBranch (derived from refs/remotes/origin/HEAD when available) and updates GitManager to gracefully return an explicit non-repo status on “not a git repository” errors.

Updates the branch picker to use an infinite query (gitBranchSearchInfiniteQueryOptions) with prefetch + scroll-to-load pagination and status text, and refactors other UI surfaces to use git.status for repo detection/default-branch checks instead of branch-list queries; tests/fixtures are updated accordingly.

Written by Cursor Bugbot for commit 34102bc. This will update automatically on new commits. Configure here.

Note

Paginate git branch listing and add query filtering with deduplication

  • Adds query, cursor, and limit params to GitListBranchesInput and returns nextCursor and totalCount in the response, enabling server-side filtered, paginated branch listing.
  • Introduces filterBranchesForListQuery and paginateBranches helpers in GitCore.ts; dedupes origin remote refs when a matching local branch exists via a new shared dedupeRemoteBranchesWithLocalMatches util.
  • Replaces useQuery(gitBranchesQueryOptions) with useInfiniteQuery(gitBranchSearchInfiniteQueryOptions) in BranchToolbarBranchSelector.tsx, adding scroll-to-load-more and a count/loading footer.
  • Extends GitStatusResult with isRepo, hasOriginRemote, and isDefaultBranch flags; GitActionsControl, ChatView, and DiffPanel now derive repo/default-branch state from status instead of the branches query.
  • GitManager.status now returns an explicit non-repo status object instead of erroring when the working directory is not a git repository.

Macroscope summarized 34102bc.

- add cursors, limits, and totals to branch RPCs
- switch branch picker to infinite search with remote/local dedupe
- update tests and fixtures for paginated branch results
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 01384974-ccc5-4754-87f9-34a063b98033

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch t3code/git-branch-pagination

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

@github-actions github-actions bot added size:XXL 1,000+ changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Apr 2, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 2, 2026

Approvability

Verdict: Needs human review

This PR adds pagination and search capabilities to git branch listing, modifies API contracts (GitListBranchesResult, GitStatusResult, GitListBranchesInput), and changes frontend data fetching patterns from regular queries to infinite queries. The scope of changes across contracts, server, and client layers with runtime behavior modifications warrants human review.

You can customize Macroscope's approvability policy. Learn more.

Replace the useEffect that manually seeded the infinite query cache from
branchesOverviewQuery data (via setQueryData + createGitBranchSearchInfiniteData)
with a prefetchInfiniteQuery call that directly fetches the first page.

This is more idiomatic TanStack Query usage and avoids the indirection of
copying data between separate query caches.

- Remove createGitBranchSearchInfiniteData helper (no longer needed)
- Remove InfiniteData/GitListBranchesResult imports from gitReactQuery.ts
- Update tests to inline the infinite data construction
- Remove the createGitBranchSearchInfiniteData test

Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
…anchSelector

The overview query (useQuery(gitBranchesQueryOptions)) is no longer needed
in this component now that the infinite search query is prefetched on mount.

- Use prefetched infinite search data for the current-branch fallback
- Use branchesSearchQuery.isPending for the trigger disabled state
- Remove gitBranchesQueryOptions import (still used by other components)

Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
@github-actions github-actions bot added size:XL 500-999 changed lines (additions + deletions). and removed size:XXL 1,000+ changed lines (additions + deletions). labels Apr 2, 2026
@github-actions github-actions bot added size:L 100-499 changed lines (additions + deletions). and removed size:XL 500-999 changed lines (additions + deletions). labels Apr 2, 2026
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 3 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Unused production re-export of deduplication function
    • Removed the dead re-export of dedupeRemoteBranchesWithLocalMatches from BranchToolbar.logic.ts and updated the test file to import directly from @t3tools/shared/git.

Create PR

Or push these changes by commenting:

@cursor push e50df67294
Preview (e50df67294)
diff --git a/apps/web/src/components/BranchToolbar.logic.test.ts b/apps/web/src/components/BranchToolbar.logic.test.ts
--- a/apps/web/src/components/BranchToolbar.logic.test.ts
+++ b/apps/web/src/components/BranchToolbar.logic.test.ts
@@ -1,7 +1,7 @@
 import type { GitBranch } from "@t3tools/contracts";
 import { describe, expect, it } from "vitest";
+import { dedupeRemoteBranchesWithLocalMatches } from "@t3tools/shared/git";
 import {
-  dedupeRemoteBranchesWithLocalMatches,
   deriveLocalBranchNameFromRemoteRef,
   resolveBranchSelectionTarget,
   resolveDraftEnvModeAfterBranchChange,

diff --git a/apps/web/src/components/BranchToolbar.logic.ts b/apps/web/src/components/BranchToolbar.logic.ts
--- a/apps/web/src/components/BranchToolbar.logic.ts
+++ b/apps/web/src/components/BranchToolbar.logic.ts
@@ -1,9 +1,6 @@
 import type { GitBranch } from "@t3tools/contracts";
 import { Schema } from "effect";
-export {
-  dedupeRemoteBranchesWithLocalMatches,
-  deriveLocalBranchNameFromRemoteRef,
-} from "@t3tools/shared/git";
+export { deriveLocalBranchNameFromRemoteRef } from "@t3tools/shared/git";
 
 export const EnvMode = Schema.Literals(["local", "worktree"]);
 export type EnvMode = typeof EnvMode.Type;

You can send follow-ups to this agent here.

- detect non-repos cleanly
- derive default branch from status
- drop branch overview polling
- Stub `GitCore.statusDetails.defaultRef` in git integration layers
- Load additional branch pages as the list scrolls
- Resolve remote branch status from the checkout cwd
@juliusmarminge juliusmarminge merged commit 915a054 into main Apr 2, 2026
12 checks passed
@juliusmarminge juliusmarminge deleted the t3code/git-branch-pagination branch April 2, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants