The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 16:00 UTC
fix(server): cached refs include a newly checked-out external branch (#36626)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 14, 2026 at 11:11 UTC
38b3feeb75d6c02a3988d4ea2983ceebc4a1b66e
2 files changed
+44
-17
apps/server/src/vcs/GitVcsDriverCore.test.ts
+23
-16
@@ -722,24 +722,31 @@ it.effect("reads a branch whose name starts with a parenthesis as attached", ()
722
).pipe(Effect.provide(layerTest)),
723
);
724
725
-it.effect("follows a checkout made outside the driver after refs were cached", () =>
726
- Effect.scoped(
727
- Effect.gen(function* () {
728
- const cwd = yield* makeTmpDir();
729
- const { initialBranch } = yield* initRepoWithCommit(cwd);
730
- yield* git(cwd, ["branch", "feature/outside"]);
731
- const driver = yield* GitVcsDriver.GitVcsDriver;
732
- yield* driver.listRefs({ cwd });
725
+it.effect.each(["an existing", "a new"] as const)(
726
+ "follows a checkout of %s branch made outside the driver after refs were cached",
727
+ (branch) =>
728
+ Effect.scoped(
729
+ Effect.gen(function* () {
730
+ const cwd = yield* makeTmpDir();
731
+ const { initialBranch } = yield* initRepoWithCommit(cwd);
732
+ if (branch === "an existing") yield* git(cwd, ["branch", "feature/outside"]);
733
+ const driver = yield* GitVcsDriver.GitVcsDriver;
734
+ yield* driver.listRefs({ cwd });
735
734
- yield* git(cwd, ["switch", "feature/outside"]);
736
+ yield* git(
737
+ cwd,
738
+ branch === "an existing"
739
+ ? ["switch", "feature/outside"]
740
+ : ["switch", "-c", "feature/outside"],
741
+ );
742
736
- const refs = (yield* driver.listRefs({ cwd })).refs;
737
- const previous = refs.find((ref) => ref.name === initialBranch);
738
- assert.isTrue(refs.find((ref) => ref.name === "feature/outside")?.current);
739
- assert.isFalse(previous?.current);
740
- assert.isNull(previous?.worktreePath ?? null);
741
- }),
742
- ).pipe(Effect.provide(layerTest)),
743
+ const refs = (yield* driver.listRefs({ cwd })).refs;
744
+ const previous = refs.find((ref) => ref.name === initialBranch);
745
+ assert.isTrue(refs.find((ref) => ref.name === "feature/outside")?.current);
746
+ assert.isFalse(previous?.current);
747
+ assert.isNull(previous?.worktreePath ?? null);
748
+ }),
749
+ ).pipe(Effect.provide(layerTest)),
750
);
751
752
it.effect.each(["on a branch", "detached", "unborn"] as const)(
apps/server/src/vcs/GitVcsDriverCore.ts
+21
-1
@@ -194,6 +194,7 @@ interface GitRepositoryPaths {
194
}
195
196
interface GitRefsSnapshot {
197
+ readonly defaultBranch: string | null;
198
readonly localBranches: ReadonlyArray<VcsRef>;
199
readonly remoteBranches: ReadonlyArray<VcsRef>;
200
readonly hasPrimaryRemote: boolean;
@@ -4387,6 +4388,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
4388
: left.ref.name.localeCompare(right.ref.name);
4389
4390
return {
4391
+ defaultBranch,
4392
localBranches: localBranches.toSorted(byRecencyThenName).map(({ ref }) => ref),
4393
remoteBranches: remoteBranches.toSorted(byRecencyThenName).map(({ ref }) => ref),
4394
hasPrimaryRemote: remoteNames.length > 0,
@@ -4527,7 +4529,24 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
4529
{ concurrency: 2 },
4530
);
4531
const { worktreeRoot } = repositoryPaths;
4530
- const localBranches = snapshot.localBranches.map((ref) => {
4532
+ // The snapshot misses a branch created outside T3 Code until it refreshes. An unborn HEAD
4533
+ // names a branch with no ref yet, so the ref must exist before it is listed.
4534
+ const currentBranchUnlisted =
4535
+ currentBranch !== null && !snapshot.localBranches.some((ref) => ref.name === currentBranch);
4536
+ const unlistedCurrentBranch: ReadonlyArray<VcsRef> =
4537
+ currentBranchUnlisted &&
4538
+ (yield* branchExists(input.cwd, currentBranch).pipe(Effect.orElseSucceed(() => false)))
4539
+ ? [
4540
+ {
4541
+ name: currentBranch,
4542
+ current: true,
4543
+ isRemote: false,
4544
+ isDefault: currentBranch === snapshot.defaultBranch,
4545
+ worktreePath: worktreeRoot,
4546
+ },
4547
+ ]
4548
+ : [];
4549
+ const listedBranches = snapshot.localBranches.map((ref) => {
4550
const current = ref.name === currentBranch;
4551
return {
4552
...ref,
@@ -4542,6 +4561,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
4561
current,
4562
};
4563
});
4564
+ const localBranches = [...unlistedCurrentBranch, ...listedBranches];
4565
const combinedBranches = input.includeMatchingRemoteRefs
4566
? [...localBranches, ...snapshot.remoteBranches]
4567
: dedupeRemoteBranchesWithLocalMatches([...localBranches, ...snapshot.remoteBranches]);