The best way to control Claude Code, Codex and more from any computer or phone
Skip local-branch PR checks and dedupe sidebar git status
- server: only query open PRs when the current branch has an upstream; still fall back to merged PR lookup - tests: cover status behavior for branches without upstream tracking - web: fetch git status once per cwd, validate query data with schema parsing, and map merged PR badges by thread branch match
Julius Marminge committed
Feb 15, 2026 at 14:28 UTC
dcdb9ac92320d62028fd2d12be26167406666920
3 files changed
+58
-13
apps/server/src/gitManager.test.ts
+22
@@ -242,6 +242,28 @@ describe("GitManager", () => {
242
expect(ghCalls.some((call) => call.includes("--state merged"))).toBe(true);
243
});
244
245
+ it("status skips open PR lookup for branches without upstream", async () => {
246
+ const repoDir = makeTempDir("t3code-git-manager-");
247
+ await initRepo(repoDir);
248
+ await runGit(repoDir, ["checkout", "-b", "feature/local-only"]);
249
+
250
+ const { runner, ghCalls } = createRunnerWithFakeGh({
251
+ prListSequence: ["[]"],
252
+ });
253
+
254
+ const manager = new GitManager({
255
+ runProcess: runner,
256
+ textGenerator: createTextGenerator(),
257
+ });
258
+
259
+ const status = await manager.status({ cwd: repoDir });
260
+ expect(status.branch).toBe("feature/local-only");
261
+ expect(status.openPr).toBeNull();
262
+ expect(status.mergedPr).toBeNull();
263
+ expect(ghCalls.some((call) => call.includes("--state open"))).toBe(false);
264
+ expect(ghCalls.some((call) => call.includes("--state merged"))).toBe(true);
265
+ });
266
+
267
it("status is resilient to gh lookup failures and returns openPr/mergedPr null", async () => {
268
const repoDir = makeTempDir("t3code-git-manager-");
269
await initRepo(repoDir);
apps/server/src/gitManager.ts
+7
-4
@@ -195,10 +195,13 @@ export class GitManager {
195
let mergedPr: ReturnType<typeof toStatusOpenPr> | null = null;
196
if (details.branch) {
197
try {
198
- const existing = await this.findOpenPr(input.cwd, details.branch);
199
- if (existing) {
200
- openPr = toStatusOpenPr(existing);
201
- } else {
198
+ if (details.hasUpstream) {
199
+ const existing = await this.findOpenPr(input.cwd, details.branch);
200
+ if (existing) {
201
+ openPr = toStatusOpenPr(existing);
202
+ }
203
+ }
204
+ if (!openPr) {
205
const merged = await this.findMergedPr(input.cwd, details.branch);
206
if (merged) {
207
mergedPr = toStatusOpenPr(merged);
apps/web/src/components/Sidebar.tsx
+29
-9
@@ -1,7 +1,7 @@
1
import { MonitorIcon, MoonIcon, SunIcon, TerminalIcon } from "lucide-react";
2
import { useCallback, useEffect, useMemo, useState } from "react";
3
import { useMutation, useQueries, useQueryClient } from "@tanstack/react-query";
4
-import type { GitStatusResult } from "@t3tools/contracts";
4
+import { gitStatusResultSchema, type GitStatusResult } from "@t3tools/contracts";
5
import { isElectron } from "../env";
6
import { useTheme } from "../hooks/useTheme";
7
import { DEFAULT_MODEL } from "../model-logic";
@@ -153,29 +153,49 @@ export default function Sidebar() {
153
})),
154
[projectCwdById, state.threads],
155
);
156
+ const threadGitStatusCwds = useMemo(
157
+ () =>
158
+ [
159
+ ...new Set(
160
+ threadGitTargets
161
+ .filter((target) => target.branch !== null)
162
+ .map((target) => target.cwd)
163
+ .filter((cwd): cwd is string => cwd !== null),
164
+ ),
165
+ ],
166
+ [threadGitTargets],
167
+ );
168
const threadGitStatusQueries = useQueries({
157
- queries: threadGitTargets.map((target) => {
158
- const base = gitStatusQueryOptions(api, target.cwd);
169
+ queries: threadGitStatusCwds.map((cwd) => {
170
+ const base = gitStatusQueryOptions(api, cwd);
171
return {
172
...base,
161
- enabled: Boolean(base.enabled && target.branch !== null),
173
+ enabled: Boolean(base.enabled),
174
staleTime: 30_000,
175
refetchInterval: 60_000,
176
};
177
}),
178
});
179
const mergedPrByThreadId = useMemo(() => {
180
+ const statusByCwd = new Map<string, GitStatusResult>();
181
+ for (let index = 0; index < threadGitStatusCwds.length; index += 1) {
182
+ const cwd = threadGitStatusCwds[index];
183
+ if (!cwd) continue;
184
+ const parsed = gitStatusResultSchema.safeParse(threadGitStatusQueries[index]?.data);
185
+ if (parsed.success) {
186
+ statusByCwd.set(cwd, parsed.data);
187
+ }
188
+ }
189
+
190
const map = new Map<string, boolean>();
169
- for (let index = 0; index < threadGitTargets.length; index += 1) {
170
- const target = threadGitTargets[index];
171
- if (!target) continue;
172
- const status = threadGitStatusQueries[index]?.data as GitStatusResult | undefined;
191
+ for (const target of threadGitTargets) {
192
+ const status = target.cwd ? statusByCwd.get(target.cwd) : undefined;
193
const branchMatches =
194
target.branch !== null && status?.branch !== null && status?.branch === target.branch;
195
map.set(target.threadId, branchMatches && status?.openPr === null && status?.mergedPr !== null);
196
}
197
return map;
178
- }, [threadGitStatusQueries, threadGitTargets]);
198
+ }, [threadGitStatusCwds, threadGitStatusQueries, threadGitTargets]);
199
200
const handleNewThread = useCallback(
201
(projectId: string) => {