Refresh upstream state after branch checkout and invalidate git queries #46
- @@ -556,6 +569,21 @@569+ if (separatorIndex <= 0) {570+ return;571+ }572+ const remoteName = upstreamRef.slice(0, separatorIndex);573+ if (remoteName.length === 0) {574+ return;575+ }576+577+ await executeGit(cwd, ["fetch", "--quiet", "--no-tags", remoteName], {578+ timeoutMs: 20_000,579+ allowNonZeroExit: true,580+ });581+ }582+556583 async checkoutBranch(input: GitCheckoutInput): Promise<void> {557584 await executeGit(input.cwd, ["checkout", input.branch], {558585 timeoutMs: 10_000,559586 fallbackErrorMessage: "git checkout failed",560587 });588+ await this.refreshCheckedOutBranchUpstream(input.cwd);561589 }
- @@ -555,0 +557,21 @@557+ const upstreamRef = trimStdout(558+ await this.gitStdout(559+ cwd,560+ ["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"],561+ true,562+ ),563+ );564+ if (upstreamRef.length === 0 || upstreamRef === "@{upstream}") {565+ return;566+ }567+568+ const separatorIndex = upstreamRef.indexOf("/");569+ if (separatorIndex <= 0) {570+ return;571+ }572+ const remoteName = upstreamRef.slice(0, separatorIndex);573+ if (remoteName.length === 0) {574+ return;575+ }576+577+ await this.git(cwd, ["fetch", "--quiet", "--no-tags", remoteName], true);
juliusmarminge merged this6708fe9
juliusmarminge closed this
Sign in to join this conversation.
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#
apps/server/src/git.test.tsapps/server/src/git.tsrefreshCheckedOutBranchUpstream(cwd: string)to resolve the current branch upstream and run a branch-scopedgit fetch;checkoutBranchnow calls this method after checkout (best-effort, failures ignored). Note: the new method appears duplicated in the class locations.apps/web/src/App.tsxuseQueryClientandinvalidateGitQueries, and invokesinvalidateGitQueries(queryClient)whenevent.method === "turn/completed"in EventRouter; addsqueryClientto 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)
✅ Passed checks (3 passed)
main✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉
Comment `@coderabbitai help` to get the list of available commands and usage tips.