Skip to content

Commit 9da7ed6

Browse files
fix(server): recognize child worktrees with dot-prefixed names
1 parent 26ef67a commit 9da7ed6

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

‎apps/server/src/project/ProjectService.test.ts‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,23 +377,24 @@ it.layer(layerTest)("ProjectService", (it) => {
377377
NodeFS.mkdirSync(source);
378378
git(source, "init", "-b", "develop");
379379
git(source, "commit", "--allow-empty", "-m", "init");
380-
const makeContainer = (name: string, coreBare: boolean) => {
380+
const makeContainer = (name: string, coreBare: boolean, checkoutName: string) => {
381381
const root = NodePath.join(fixture, name);
382382
git(fixture, "clone", "--bare", source, NodePath.join(root, ".bare"));
383383
NodeFS.writeFileSync(NodePath.join(root, ".git"), "gitdir: ./.bare\n");
384-
git(root, "worktree", "add", "develop", "develop");
385-
git(root, "worktree", "add", "feature-x", "-b", "feature-x");
384+
git(root, "worktree", "add", checkoutName, "develop");
386385
// With core.bare=false git treats the container itself as a checkout of HEAD, so the
387386
// bare metadata and every sibling worktree show up as changes.
388387
git(root, "config", "core.bare", String(coreBare));
389388
return root;
390389
};
391390

392-
for (const [name, coreBare] of [
393-
["bare-true", true],
394-
["bare-false", false],
391+
for (const [name, coreBare, checkoutName] of [
392+
["bare-true", true, "develop"],
393+
["bare-false", false, "develop"],
394+
["bare-dotdot-true", true, "..develop"],
395+
["bare-dotdot-false", false, "..develop"],
395396
] as const) {
396-
const root = makeContainer(name, coreBare);
397+
const root = makeContainer(name, coreBare, checkoutName);
397398
const rejected = yield* service
398399
.create({
399400
commandId: CommandId.make(`command:bare-root:${name}`),
@@ -405,7 +406,7 @@ it.layer(layerTest)("ProjectService", (it) => {
405406
assert.match(rejected.message, /worktree/i, `core.bare=${coreBare}`);
406407
assert.isTrue(Option.isNone(yield* service.getByWorkspaceRoot(root)));
407408

408-
const worktreeRoot = NodePath.join(root, "develop");
409+
const worktreeRoot = NodePath.join(root, checkoutName);
409410
const worktree = yield* service.create({
410411
commandId: CommandId.make(`command:bare-root:${name}:develop`),
411412
projectId: ProjectId.make(`project:bare-root:${name}:develop`),

‎apps/server/src/project/ProjectService.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,12 @@ export const make = Effect.gen(function* () {
246246
function* (workspaceRoot: string) {
247247
const isInsideRoot = (candidate: string) => {
248248
const relative = path.relative(workspaceRoot, candidate);
249-
return relative !== "" && !relative.startsWith("..") && !path.isAbsolute(relative);
249+
return (
250+
relative !== "" &&
251+
relative !== ".." &&
252+
!relative.startsWith(`..${path.sep}`) &&
253+
!path.isAbsolute(relative)
254+
);
250255
};
251256
const readGitdirFile = (file: string) =>
252257
fileSystem.readFileString(file).pipe(

0 commit comments

Comments
 (0)