Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apps/server/src/vcs/GitVcsDriverCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,28 @@ it.effect("reads worktrees from git that rejects worktree list -z", () =>
).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))),
);

it.effect("does not report a separate git dir as the worktree of its branch", () =>
Effect.scoped(
Effect.gen(function* () {
const driver = yield* GitVcsDriver.GitVcsDriver;
const cwd = yield* makeTmpDir();
const gitDir = yield* makeTmpDir();
yield* git(cwd, ["init", `--separate-git-dir=${gitDir}`]);
yield* git(cwd, ["config", "user.email", "test@test.com"]);
yield* git(cwd, ["config", "user.name", "Test"]);
yield* git(cwd, ["commit", "--allow-empty", "-m", "init"]);

const refs = yield* driver.listRefs({ cwd, refresh: true });
const worktreePath = refs.refs.find((ref) => ref.current)?.worktreePath;

assert.equal(
worktreePath && NodeFS.realpathSync.native(worktreePath),
NodeFS.realpathSync.native(cwd),
);
}),
).pipe(Effect.provide(layerTest)),
);

it.effect("refreshes the current branch after an external checkout", () =>
Effect.scoped(
Effect.gen(function* () {
Expand Down
15 changes: 11 additions & 4 deletions apps/server/src/vcs/GitVcsDriverCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3285,13 +3285,17 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
[branchName, path.normalize(path.resolve(worktreePath))] as const,
)
: [];
// Without `core.worktree`, Git reports a separate git dir as the main checkout.
const normalizedGitCommonDir = path.normalize(path.resolve(gitCommonDir));
const existingWorktreeEntries = yield* Effect.filter(
parsedWorktreeEntries,
([, worktreePath]) =>
fileSystem.stat(worktreePath).pipe(
Effect.as(true),
Effect.orElseSucceed(() => false),
),
worktreePath === normalizedGitCommonDir
? Effect.succeed(false)
: fileSystem.stat(worktreePath).pipe(
Effect.as(true),
Effect.orElseSucceed(() => false),
),
{ concurrency: 16 },
);
const worktreeMap = new Map(existingWorktreeEntries);
Expand Down Expand Up @@ -3482,6 +3486,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
snapshot.localBranches.some((ref) => ref.worktreePath === repositoryPaths.worktreeRoot);
const localBranches = snapshot.localBranches.map((ref) => ({
...ref,
worktreePath:
ref.worktreePath ??
(ref.name === repositoryPaths.currentBranch ? repositoryPaths.worktreeRoot : null),
current: hasCurrentWorktreeBranch
? ref.worktreePath === repositoryPaths.worktreeRoot
: ref.name === repositoryPaths.currentBranch,
Expand Down
Loading