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.
Prioritize current and default branches in branch list ordering
Julius Marminge21580dc1b086
diff --git a/apps/server/src/git.test.ts b/apps/server/src/git.test.tsindex e0612f09f..9155cb04e 100644--- a/apps/server/src/git.test.ts+++ b/apps/server/src/git.test.ts@@ -125,7 +125,7 @@ describe("git integration", () => {expect(current!.current).toBe(true);});- it("sorts branches by most recent commit first", async () => {+ it("keeps current branch first and sorts the remaining branches by recency", async () => {await using tmp = await makeTmpDir();await initRepoWithCommit(tmp.path);const initialBranch = (await listGitBranches({ cwd: tmp.path })).branches.find(@@ -153,11 +153,54 @@ describe("git integration", () => {"newer branch change",);- // Switch away to show sort order is recency-based, not "current"-based.+ // Switch away to show current branch is pinned, then remaining branches are recency-sorted.await checkoutGitBranch({ cwd: tmp.path, branch: "older-branch" });const result = await listGitBranches({ cwd: tmp.path });- expect(result.branches[0]!.name).toBe("newer-branch");+ expect(result.branches[0]!.name).toBe("older-branch");+ expect(result.branches[1]!.name).toBe("newer-branch");+ });++ it("keeps default branch right after current branch", async () => {+ await using tmp = await makeTmpDir();+ await using remote = await makeTmpDir();+ await initRepoWithCommit(tmp.path);+ const defaultBranch = (await listGitBranches({ cwd: tmp.path })).branches.find(+ (branch) => branch.current,+ )!.name;++ await git(remote.path, "init --bare");+ await git(tmp.path, `remote add origin ${JSON.stringify(remote.path)}`);+ await git(tmp.path, `push -u origin ${defaultBranch}`);+ await git(tmp.path, `remote set-head origin ${defaultBranch}`);++ await createGitBranch({ cwd: tmp.path, branch: "current-branch" });+ await checkoutGitBranch({ cwd: tmp.path, branch: "current-branch" });+ await commitWithDate(+ tmp.path,+ "current.txt",+ "current change\n",+ "Thu, 1 Jan 2037 00:00:00 +0000",+ "current change",+ );++ await checkoutGitBranch({ cwd: tmp.path, branch: defaultBranch });+ await createGitBranch({ cwd: tmp.path, branch: "newer-branch" });+ await checkoutGitBranch({ cwd: tmp.path, branch: "newer-branch" });+ await commitWithDate(+ tmp.path,+ "newer.txt",+ "newer change\n",+ "Fri, 1 Jan 2038 00:00:00 +0000",+ "newer change",+ );++ await checkoutGitBranch({ cwd: tmp.path, branch: "current-branch" });++ const result = await listGitBranches({ cwd: tmp.path });+ expect(result.branches[0]!.name).toBe("current-branch");+ expect(result.branches[1]!.name).toBe(defaultBranch);+ expect(result.branches[2]!.name).toBe("newer-branch");});it("lists multiple branches after creating them", async () => {diff --git a/apps/server/src/git.ts b/apps/server/src/git.tsindex 734ee3038..39e4e1f93 100644--- a/apps/server/src/git.ts+++ b/apps/server/src/git.ts@@ -393,11 +393,13 @@ export class GitCoreService {};}).toSorted((a, b) => {+ const aPriority = a.current ? 0 : a.isDefault ? 1 : 2;+ const bPriority = b.current ? 0 : b.isDefault ? 1 : 2;+ if (aPriority !== bPriority) return aPriority - bPriority;+const aLastCommit = branchLastCommit.get(a.name) ?? 0;const bLastCommit = branchLastCommit.get(b.name) ?? 0;if (aLastCommit !== bLastCommit) return bLastCommit - aLastCommit;- if (a.current !== b.current) return a.current ? -1 : 1;- if (a.isDefault !== b.isDefault) return a.isDefault ? -1 : 1;return a.name.localeCompare(b.name);});