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 23, 00:30 UTC
fix(server): stop reporting a separate git dir as a branch's worktree (#14157)
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com> Co-authored-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Pujitha Paladugu committed
Oct 19, 2026 at 17:40 UTC
462810f0b801e3f0e714fe841e44870ea49877eb
2 files changed
+33
-4
apps/server/src/vcs/GitVcsDriverCore.test.ts
+22
@@ -825,6 +825,28 @@ it.effect("reads worktrees from git that rejects worktree list -z", () =>
825
).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))),
826
);
827
828
+it.effect("does not report a separate git dir as the worktree of its branch", () =>
829
+ Effect.scoped(
830
+ Effect.gen(function* () {
831
+ const driver = yield* GitVcsDriver.GitVcsDriver;
832
+ const cwd = yield* makeTmpDir();
833
+ const gitDir = yield* makeTmpDir();
834
+ yield* git(cwd, ["init", `--separate-git-dir=${gitDir}`]);
835
+ yield* git(cwd, ["config", "user.email", "test@test.com"]);
836
+ yield* git(cwd, ["config", "user.name", "Test"]);
837
+ yield* git(cwd, ["commit", "--allow-empty", "-m", "init"]);
838
+
839
+ const refs = yield* driver.listRefs({ cwd, refresh: true });
840
+ const worktreePath = refs.refs.find((ref) => ref.current)?.worktreePath;
841
+
842
+ assert.equal(
843
+ worktreePath && NodeFS.realpathSync.native(worktreePath),
844
+ NodeFS.realpathSync.native(cwd),
845
+ );
846
+ }),
847
+ ).pipe(Effect.provide(layerTest)),
848
+);
849
+
850
it.effect("refreshes the current branch after an external checkout", () =>
851
Effect.scoped(
852
Effect.gen(function* () {
apps/server/src/vcs/GitVcsDriverCore.ts
+11
-4
@@ -3287,13 +3287,17 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
3287
[branchName, path.normalize(path.resolve(worktreePath))] as const,
3288
)
3289
: [];
3290
+ // Without `core.worktree`, Git reports a separate git dir as the main checkout.
3291
+ const normalizedGitCommonDir = path.normalize(path.resolve(gitCommonDir));
3292
const existingWorktreeEntries = yield* Effect.filter(
3293
parsedWorktreeEntries,
3294
([, worktreePath]) =>
3293
- fileSystem.stat(worktreePath).pipe(
3294
- Effect.as(true),
3295
- Effect.orElseSucceed(() => false),
3296
- ),
3295
+ worktreePath === normalizedGitCommonDir
3296
+ ? Effect.succeed(false)
3297
+ : fileSystem.stat(worktreePath).pipe(
3298
+ Effect.as(true),
3299
+ Effect.orElseSucceed(() => false),
3300
+ ),
3301
{ concurrency: 16 },
3302
);
3303
const worktreeMap = new Map(existingWorktreeEntries);
@@ -3484,6 +3488,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
3488
snapshot.localBranches.some((ref) => ref.worktreePath === repositoryPaths.worktreeRoot);
3489
const localBranches = snapshot.localBranches.map((ref) => ({
3490
...ref,
3491
+ worktreePath:
3492
+ ref.worktreePath ??
3493
+ (ref.name === repositoryPaths.currentBranch ? repositoryPaths.worktreeRoot : null),
3494
current: hasCurrentWorktreeBranch
3495
? ref.worktreePath === repositoryPaths.worktreeRoot
3496
: ref.name === repositoryPaths.currentBranch,