@devries-cameron20 / t3code-1 / commits / 21580dc1b0
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Prioritize current and default branches in branch list ordering

- Keep the current branch first - Place the default branch second - Sort remaining branches by most recent commit and update tests for this behavior Co-authored-by: codex <codex@users.noreply.github.com>

Julius Marminge committed Feb 12, 2026 at 23:24 UTC 21580dc1b0860e5cc711ab2cc494b52e64103d92
2 files changed +50 -5
apps/server/src/git.test.ts
+46 -3
@@ -125,7 +125,7 @@ describe("git integration", () => {
125 expect(current!.current).toBe(true);
126 });
127
128 - it("sorts branches by most recent commit first", async () => {
128 + it("keeps current branch first and sorts the remaining branches by recency", async () => {
129 await using tmp = await makeTmpDir();
130 await initRepoWithCommit(tmp.path);
131 const initialBranch = (await listGitBranches({ cwd: tmp.path })).branches.find(
@@ -153,11 +153,54 @@ describe("git integration", () => {
153 "newer branch change",
154 );
155
156 - // Switch away to show sort order is recency-based, not "current"-based.
156 + // Switch away to show current branch is pinned, then remaining branches are recency-sorted.
157 await checkoutGitBranch({ cwd: tmp.path, branch: "older-branch" });
158
159 const result = await listGitBranches({ cwd: tmp.path });
160 - expect(result.branches[0]!.name).toBe("newer-branch");
160 + expect(result.branches[0]!.name).toBe("older-branch");
161 + expect(result.branches[1]!.name).toBe("newer-branch");
162 + });
163 +
164 + it("keeps default branch right after current branch", async () => {
165 + await using tmp = await makeTmpDir();
166 + await using remote = await makeTmpDir();
167 + await initRepoWithCommit(tmp.path);
168 + const defaultBranch = (await listGitBranches({ cwd: tmp.path })).branches.find(
169 + (branch) => branch.current,
170 + )!.name;
171 +
172 + await git(remote.path, "init --bare");
173 + await git(tmp.path, `remote add origin ${JSON.stringify(remote.path)}`);
174 + await git(tmp.path, `push -u origin ${defaultBranch}`);
175 + await git(tmp.path, `remote set-head origin ${defaultBranch}`);
176 +
177 + await createGitBranch({ cwd: tmp.path, branch: "current-branch" });
178 + await checkoutGitBranch({ cwd: tmp.path, branch: "current-branch" });
179 + await commitWithDate(
180 + tmp.path,
181 + "current.txt",
182 + "current change\n",
183 + "Thu, 1 Jan 2037 00:00:00 +0000",
184 + "current change",
185 + );
186 +
187 + await checkoutGitBranch({ cwd: tmp.path, branch: defaultBranch });
188 + await createGitBranch({ cwd: tmp.path, branch: "newer-branch" });
189 + await checkoutGitBranch({ cwd: tmp.path, branch: "newer-branch" });
190 + await commitWithDate(
191 + tmp.path,
192 + "newer.txt",
193 + "newer change\n",
194 + "Fri, 1 Jan 2038 00:00:00 +0000",
195 + "newer change",
196 + );
197 +
198 + await checkoutGitBranch({ cwd: tmp.path, branch: "current-branch" });
199 +
200 + const result = await listGitBranches({ cwd: tmp.path });
201 + expect(result.branches[0]!.name).toBe("current-branch");
202 + expect(result.branches[1]!.name).toBe(defaultBranch);
203 + expect(result.branches[2]!.name).toBe("newer-branch");
204 });
205
206 it("lists multiple branches after creating them", async () => {
apps/server/src/git.ts
+4 -2
@@ -393,11 +393,13 @@ export class GitCoreService {
393 };
394 })
395 .toSorted((a, b) => {
396 + const aPriority = a.current ? 0 : a.isDefault ? 1 : 2;
397 + const bPriority = b.current ? 0 : b.isDefault ? 1 : 2;
398 + if (aPriority !== bPriority) return aPriority - bPriority;
399 +
400 const aLastCommit = branchLastCommit.get(a.name) ?? 0;
401 const bLastCommit = branchLastCommit.get(b.name) ?? 0;
402 if (aLastCommit !== bLastCommit) return bLastCommit - aLastCommit;
399 - if (a.current !== b.current) return a.current ? -1 : 1;
400 - if (a.isDefault !== b.isDefault) return a.isDefault ? -1 : 1;
403 return a.name.localeCompare(b.name);
404 });
405