Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
Handle branch recency lookup failures in branch listing
Julius Marminge6b916d3a6fbe
diff --git a/apps/server/src/git.test.ts b/apps/server/src/git.test.tsindex 9155cb04e..1d9067b7a 100644--- a/apps/server/src/git.test.ts+++ b/apps/server/src/git.test.ts@@ -2,7 +2,7 @@ import { existsSync } from "node:fs";import { mkdtemp, rm, writeFile } from "node:fs/promises";import { tmpdir } from "node:os";import path from "node:path";-import { describe, expect, it } from "vitest";+import { describe, expect, it, vi } from "vitest";import {GitCoreService,@@ -603,5 +603,21 @@ describe("git integration", () => {const skipped = await core.pushCurrentBranch(tmp.path, null);expect(skipped.status).toBe("skipped_up_to_date");});++ it("lists branches when recency lookup fails", async () => {+ await using tmp = await makeTmpDir();+ await initRepoWithCommit(tmp.path);+ const core = new GitCoreService();+ const recencySpy = vi+ .spyOn(core as any, "readBranchRecency")+ .mockRejectedValueOnce(new Error("timeout"));++ const result = await core.listBranches({ cwd: tmp.path });++ expect(result.isRepo).toBe(true);+ expect(result.branches.length).toBeGreaterThan(0);+ expect(result.branches[0]?.current).toBe(true);+ recencySpy.mockRestore();+ });});});diff --git a/apps/server/src/git.ts b/apps/server/src/git.tsindex 39e4e1f93..b6fdbe63a 100644--- a/apps/server/src/git.ts+++ b/apps/server/src/git.ts@@ -312,7 +312,40 @@ export class GitCoreService {return value.length > 0 ? value : null;}+ private async readBranchRecency(cwd: string): Promise<Map<string, number>> {+ const branchRecency = await executeGit(+ cwd,+ ["for-each-ref", "--format=%(refname:short)%09%(committerdate:unix)", "refs/heads"],+ {+ timeoutMs: 15_000,+ allowNonZeroExit: true,+ },+ );++ const branchLastCommit = new Map<string, number>();+ if (branchRecency.code !== 0) {+ return branchLastCommit;+ }++ for (const line of branchRecency.stdout.split("\n")) {+ if (line.length === 0) {+ continue;+ }+ const [name, lastCommitRaw] = line.split("\t");+ if (!name) {+ continue;+ }+ const lastCommit = Number.parseInt(lastCommitRaw ?? "0", 10);+ branchLastCommit.set(name, Number.isFinite(lastCommit) ? lastCommit : 0);+ }++ return branchLastCommit;+ }+async listBranches(input: GitListBranchesInput): Promise<GitListBranchesResult> {+ const branchRecencyPromise = this.readBranchRecency(input.cwd).catch(+ () => new Map<string, number>(),+ );const result = await executeGit(input.cwd, ["branch", "--no-color"], {timeoutMs: 10_000,allowNonZeroExit: true,@@ -326,7 +359,7 @@ export class GitCoreService {throw new Error(stderr || "git branch failed");}- const [defaultRef, worktreeList, branchRecency] = await Promise.all([+ const [defaultRef, worktreeList, branchLastCommit] = await Promise.all([executeGit(input.cwd, ["symbolic-ref", "refs/remotes/origin/HEAD"], {timeoutMs: 5_000,allowNonZeroExit: true,@@ -335,14 +368,7 @@ export class GitCoreService {timeoutMs: 5_000,allowNonZeroExit: true,}),- executeGit(- input.cwd,- ["for-each-ref", "--format=%(refname:short)%09%(committerdate:unix)", "refs/heads"],- {- timeoutMs: 5_000,- allowNonZeroExit: true,- },- ),+ branchRecencyPromise,]);const defaultBranch =defaultRef.code === 0@@ -364,21 +390,6 @@ export class GitCoreService {}}- const branchLastCommit = new Map<string, number>();- if (branchRecency.code === 0) {- for (const line of branchRecency.stdout.split("\n")) {- if (line.length === 0) {- continue;- }- const [name, lastCommitRaw] = line.split("\t");- if (!name) {- continue;- }- const lastCommit = Number.parseInt(lastCommitRaw ?? "0", 10);- branchLastCommit.set(name, Number.isFinite(lastCommit) ? lastCommit : 0);- }- }-const branches = result.stdout.split("\n").map((line) => line.trim())