Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
29 changes: 29 additions & 0 deletions apps/server/src/vcs/GitVcsDriverCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,35 @@
).pipe(Effect.provide(ServerConfigLayer.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* makeGitVcsDriverCore();
const cwd = yield* makeTmpDir();
const gitDir = NodeFS.realpathSync(yield* makeTmpDir());
yield* git(cwd, ["init", `--separate-git-dir=${gitDir}`]).pipe(
Effect.provideService(GitVcsDriver.GitVcsDriver, driver),
);
yield* git(cwd, ["config", "user.email", "test@example.com"]).pipe(
Effect.provideService(GitVcsDriver.GitVcsDriver, driver),
);
yield* git(cwd, ["config", "user.name", "Test"]).pipe(
Effect.provideService(GitVcsDriver.GitVcsDriver, driver),
);
yield* git(cwd, ["commit", "--allow-empty", "-m", "init"]).pipe(
Effect.provideService(GitVcsDriver.GitVcsDriver, driver),
);
const refs = yield* driver.listRefs({ cwd, refresh: true });

assert.isTrue(refs.isRepo);
const current = refs.refs.find((ref) => ref.current);
assert.isDefined(current);
assert.notEqual(current?.worktreePath, gitDir);
assert.equal(current?.worktreePath, NodeFS.realpathSync(cwd));
}),

Check failure on line 722 in apps/server/src/vcs/GitVcsDriverCore.test.ts

View workflow job for this annotation

GitHub Actions / Test Server 5

src/vcs/GitVcsDriverCore.test.ts > does not report a separate git dir as the worktree of its branch

ReferenceError: ServerConfigLayer is not defined ❯ src/vcs/GitVcsDriverCore.test.ts:722:25 ❯ PrimitiveImpl.~effect/Effect/evaluate ../../node_modules/.pnpm/effect@4.0.1_patch_hash=a33cba07c41f32374c2aaa86ea4a84d3ab9a872a78c94b65e929b19f8361856f/node_modules/effect/src/internal/effect.ts:976:22 ❯ FiberImpl.runLoop ../../node_modules/.pnpm/effect@4.0.1_patch_hash=a33cba07c41f32374c2aaa86ea4a84d3ab9a872a78c94b65e929b19f8361856f/node_modules/effect/src/internal/effect.ts:650:39 ❯ FiberImpl.evaluate ../../node_modules/.pnpm/effect@4.0.1_patch_hash=a33cba07c41f32374c2aaa86ea4a84d3ab9a872a78c94b65e929b19f8361856f/node_modules/effect/src/internal/effect.ts:592:23 ❯ ../../node_modules/.pnpm/effect@4.0.1_patch_hash=a33cba07c41f32374c2aaa86ea4a84d3ab9a872a78c94b65e929b19f8361856f/node_modules/effect/src/internal/effect.ts:5679:9 ❯ ../../node_modules/.pnpm/effect@4.0.1_patch_hash=a33cba07c41f32374c2aaa86ea4a84d3ab9a872a78c94b65e929b19f8361856f/node_modules/effect/src/internal/effect.ts:5757:19 ❯ Module.<anonymous> ../../node_modules/.pnpm/effect@4.0.1_patch_hash=a33cba07c41f32374c2aaa86ea4a84d3ab9a872a78c94b65e929b19f8361856f/node_modules/effect/src/internal/effect.ts:5776:5 ❯ fn ../../node_modules/.pnpm/effect@4.0.1_patch_hash=a33cba07c41f32374c2aaa86ea4a84d3ab9a872a78c94b65e929b19f8361856f/node_modules/effect/src/internal/effect.ts:1254:30
).pipe(Effect.provide(ServerConfigLayer.pipe(Layer.provideMerge(NodeServices.layer)))),
);

it.effect("refreshes the current branch after an external checkout", () =>
Effect.scoped(
Effect.gen(function* () {
Expand Down Expand Up @@ -776,7 +805,7 @@
yield* runGit(cwd, ["worktree", "add", "-b", "feature/linked", worktreePath]);
yield* runGit(worktreePath, [
"branch",
"--set-upstream-to",

Check failure on line 808 in apps/server/src/vcs/GitVcsDriverCore.test.ts

View workflow job for this annotation

GitHub Actions / Test Server 5

src/vcs/GitVcsDriverCore.test.ts > does not report a separate git dir as the worktree of its branch

ReferenceError: ServerConfigLayer is not defined ❯ src/vcs/GitVcsDriverCore.test.ts:808:25 ❯ PrimitiveImpl.~effect/Effect/evaluate ../../node_modules/.pnpm/effect@4.0.2_patch_hash=ec61ee307eaec3e17f757e0e6a16296ea4b7a8c3188df0c6ec5e66301fd78688/node_modules/effect/src/internal/effect.ts:980:22 ❯ FiberImpl.runLoop ../../node_modules/.pnpm/effect@4.0.2_patch_hash=ec61ee307eaec3e17f757e0e6a16296ea4b7a8c3188df0c6ec5e66301fd78688/node_modules/effect/src/internal/effect.ts:653:41 ❯ FiberImpl.evaluate ../../node_modules/.pnpm/effect@4.0.2_patch_hash=ec61ee307eaec3e17f757e0e6a16296ea4b7a8c3188df0c6ec5e66301fd78688/node_modules/effect/src/internal/effect.ts:594:23 ❯ ../../node_modules/.pnpm/effect@4.0.2_patch_hash=ec61ee307eaec3e17f757e0e6a16296ea4b7a8c3188df0c6ec5e66301fd78688/node_modules/effect/src/internal/effect.ts:5681:9 ❯ ../../node_modules/.pnpm/effect@4.0.2_patch_hash=ec61ee307eaec3e17f757e0e6a16296ea4b7a8c3188df0c6ec5e66301fd78688/node_modules/effect/src/internal/effect.ts:5759:19 ❯ Module.<anonymous> ../../node_modules/.pnpm/effect@4.0.2_patch_hash=ec61ee307eaec3e17f757e0e6a16296ea4b7a8c3188df0c6ec5e66301fd78688/node_modules/effect/src/internal/effect.ts:5778:5 ❯ fn ../../node_modules/.pnpm/effect@4.0.2_patch_hash=ec61ee307eaec3e17f757e0e6a16296ea4b7a8c3188df0c6ec5e66301fd78688/node_modules/effect/src/internal/effect.ts:1258:30
`origin/${initialBranch}`,
"feature/linked",
]);
Expand Down
11 changes: 11 additions & 0 deletions apps/server/src/vcs/GitVcsDriverCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2829,9 +2829,13 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
[branchName, path.normalize(path.resolve(worktreePath))] as const,
)
: [];
// With a separate git dir lacking `core.worktree`, git lists the git dir itself as the
// main worktree. It is not a checkout, so it must never be offered as one.
const normalizedGitCommonDir = path.normalize(path.resolve(gitCommonDir));
const existingWorktreeEntries = yield* Effect.filter(
parsedWorktreeEntries,
([, worktreePath]) =>
worktreePath !== normalizedGitCommonDir &&
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
fileSystem.stat(worktreePath).pipe(
Effect.as(true),
Effect.orElseSucceed(() => false),
Expand Down Expand Up @@ -3026,6 +3030,13 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
snapshot.localBranches.some((ref) => ref.worktreePath === repositoryPaths.worktreeRoot);
const localBranches = snapshot.localBranches.map((ref) => ({
...ref,
// A separate git dir is filtered out of the worktree list, which leaves the
// current branch without a path; fall back to the folder the user opened.
worktreePath:
ref.worktreePath ??
(!ref.isRemote && ref.name === repositoryPaths.currentBranch
? repositoryPaths.worktreeRoot
: null),
current: hasCurrentWorktreeBranch
? ref.worktreePath === repositoryPaths.worktreeRoot
: ref.name === repositoryPaths.currentBranch,
Expand Down
Loading