Skip to content
Source
Sign inSign up
pingdotgg/t3code

Refresh upstream state after branch checkout and invalidate git queries #46

Mergedjuliusmarmingemerged 3 commits intomain fromgit-inmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Summary

  • refresh tracked upstream metadata after git checkout by fetching the checked-out branch's remote (quiet, no-tags)
  • ensure checkout-derived status reflects current ahead/behind counts when the remote branch has advanced
  • add an integration test covering the stale-behind-count scenario after checkout
  • invalidate git-related React Query caches on turn/completed events so UI git state refreshes promptly

Testing

  • Added integration test in apps/server/src/git.test.ts that:
  • creates a remote + source + clone setup
  • advances the remote tracked branch from another clone
  • checks out the branch locally and asserts aheadCount === 0 and behindCount === 1
  • Verified implementation path in apps/server/src/git.ts calls upstream refresh after successful checkout
  • Not run: project lint scripts
  • Not run: full test suite

Open with Devin

Summary by CodeRabbit

  • New Features

    • Checkout now attempts to refresh upstream tracking after switching branches.
    • UI invalidates git queries when background events complete to keep git state up to date.
  • Bug Fixes / Resiliency

    • Checkout proceeds even if the upstream refresh/fetch fails; a single fetch retry is attempted and failures are best-effort only.
  • Tests

    • Added tests covering upstream behind-count, scoped fetch behavior, and checkout behavior during refresh/fetch failures.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Walkthrough

      Adds best-effort upstream refresh after branch checkout in the server Git service, two tests validating upstream behind-count and checkout resilience to fetch failures, and client-side invalidation of Git queries on "turn/completed" events.

      Changes

      Cohort / File(s)Summary
      Git Tests
      apps/server/src/git.test.ts
      Adds multiple tests that create a bare remote, a local source repo, and a clone to verify upstream behind-count after remote branch advancement, that checkout proceeds when an upstream fetch/refresh fails, and that fetches are scoped to the checked-out branch.
      Git Operations (server)
      apps/server/src/git.ts
      Adds a private refreshCheckedOutBranchUpstream(cwd: string) to resolve the current branch upstream and run a branch-scoped git fetch; checkoutBranch now calls this method after checkout (best-effort, failures ignored). Note: the new method appears duplicated in the class locations.
      Client: event-driven invalidation
      apps/web/src/App.tsx
      Imports useQueryClient and invalidateGitQueries, and invokes invalidateGitQueries(queryClient) when event.method === "turn/completed" in EventRouter; adds queryClient to effect dependencies.

      Sequence Diagram(s)

      mermaid sequenceDiagram participant Client as Web Client participant Server as GitService participant Remote as Remote Git (bare repo) Client->>Server: request checkoutBranch(repo, branch) Server->>Server: git checkout Server->>Server: resolve upstream (remote + ref) Server->>Remote: git fetch Remote-->>Server: fetch result Server-->>Client: checkout result (fetch errors ignored)

      mermaid sequenceDiagram participant EventRouter as Web EventRouter participant QueryClient as React QueryClient participant ServerAPI as Server Git API EventRouter->>QueryClient: invalidateGitQueries(queryClient) QueryClient->>ServerAPI: refetch Git-related queries ServerAPI-->>QueryClient: latest Git data QueryClient-->>EventRouter: updated data (subscribers)

      Estimated code review effort

      🎯 3 (Moderate) | ⏱️ ~25 minutes

      🚥 Pre-merge checks | ✅ 3 | ❌ 1
      ❌ Failed checks (1 warning)
      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring 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 nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title check✅ PassedThe title accurately and concisely summarizes the main changes: refreshing upstream state after branch checkout and invalidating git queries in the UI.
      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 `git-in`

      No actionable comments were generated in the recent review. 🎉


      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. greptile-apps[bot](GitHub profile, opens in a new tab)commented

      Greptile Summary

      Added upstream branch refresh after checkout to ensure accurate ahead/behind counts when remote branches advance, plus UI query invalidation on agent turn completion.

      Key changes:

      • refreshCheckedOutBranchUpstream() fetches the checked-out branch's upstream refspec after successful checkout (scoped fetch, not all remote refs)
      • Fetch failures are silently caught since checkout already succeeded (best-effort refresh)
      • Integration tests verify behind-count accuracy, failure tolerance, and refspec scoping
      • UI now invalidates git-related React Query caches on turn/completed events to reflect post-agent git state

      Confidence Score: 4/5

      • Safe to merge with minor considerations around error handling patterns
      • Implementation follows CLAUDE.md priorities (reliability, predictable failure behavior) by wrapping fetch in try-catch and scoping to specific refspec. Comprehensive test coverage validates the happy path, failure tolerance, and refspec scoping. The UI integration properly invalidates queries. Previous review comments addressed fetch scoping and error masking concerns.
      • No files require special attention

      Important Files Changed

      FilenameOverview
      apps/server/src/git.tsAdded refreshCheckedOutBranchUpstream method to fetch upstream state after checkout, properly scoped to the checked-out branch's refspec, with error tolerance
      apps/server/src/git.test.tsAdded three comprehensive integration tests covering behind-count refresh, fetch failure tolerance, and refspec scoping
      apps/web/src/App.tsxInvalidates git queries on turn/completed events to ensure UI reflects current git state after agent operations

      Sequence Diagram

      sequenceDiagram
          participant User
          participant UI as App.tsx
          participant API as Git API
          participant Git as GitCoreService
          participant Remote as Git Remote
      
          User->>API: checkout branch
          API->>Git: checkoutBranch()
          Git->>Git: executeGit(["checkout", branch])
          Note over Git: Checkout succeeds
          
          Git->>Git: refreshCheckedOutBranchUpstream()
          Git->>Git: gitStdout(["rev-parse", "@{upstream}"])
          Git-->>Git: "origin/feature-branch"
          Git->>Git: Parse remote name and branch
          Git->>Remote: git fetch --quiet --no-tags origin +refs/heads/feature:refs/remotes/origin/feature
          
          alt Fetch succeeds
              Remote-->>Git: Updated refs
              Git-->>API: Checkout complete
          else Fetch fails
              Note over Git: Silently catch error
              Git-->>API: Checkout complete (best effort)
          end
          
          API-->>UI: Checkout result
          
          Note over UI: On turn/completed event
          UI->>UI: invalidateGitQueries(queryClient)
          UI->>API: Re-fetch git status
          API->>Git: statusDetails()
          Git-->>API: Current ahead/behind counts
          API-->>UI: Updated git state
          Note over UI: UI shows fresh git status
      Last reviewed commit: 147f433
    3. 3 files reviewed, 1 comment [Edit Code Review Agent Settings](https://app.greptile.com/review/github) | [Greptile](https://greptile.com?utm_source=greptile_expert&utm_medium=github&utm_campaign=code_reviews)
      apps/server/src/git.ts lines 585 to 595Resolvedby juliusmarminge
    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Refresh the checked-out branch’s upstream after GitCoreService.checkoutBranch and invalidate Git React Query caches on turn/completed events

      Add GitCoreService.refreshCheckedOutBranchUpstream to run a scoped fetch after checkout and call it best-effort from GitCoreService.checkoutBranch; invalidate Git-related queries in App.EventRouter on turn/completed; add tests covering behind count refresh, fetch scoping, and failure tolerance in apps/server/src/git.test.ts and logic in apps/server/src/git.ts and apps/web/src/App.tsx.

      📍Where to Start

      Start with GitCoreService.refreshCheckedOutBranchUpstream and its invocation inside GitCoreService.checkoutBranch in apps/server/src/git.ts.


      Macroscope summarized 147f433.
    5. @greptileai review

    6. 3 files reviewed, 1 comment [Edit Code Review Agent Settings](https://app.greptile.com/review/github) | [Greptile](https://greptile.com?utm_source=greptile_expert&utm_medium=github&utm_campaign=code_reviews)
      apps/server/src/git.ts line 577OutdatedResolvedby juliusmarminge
    7. @greptileai review

    8. juliusmarminge merged this6708fe9

    9. juliusmarminge closed this

Sign in to join this conversation.