Skip to content

Commit 7b4316c

Browse files
committed
fix(server): reject directories as sparse pattern files
1 parent bd744be commit 7b4316c

2 files changed

Lines changed: 26 additions & 17 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4363,30 +4363,39 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
43634363
}),
43644364
);
43654365

4366-
it.effect("fails without a worktree when the t3.json sparse pattern file is missing", () =>
4366+
it.effect("fails without a worktree when the t3.json sparse pattern path is not a file", () =>
43674367
Effect.gen(function* () {
43684368
const fileSystem = yield* FileSystem.FileSystem;
43694369
const pathService = yield* Path.Path;
43704370
const cwd = yield* makeTmpDir();
43714371
const { initialBranch } = yield* initRepoWithCommit(cwd);
4372-
yield* writeTextFile(cwd, "t3.json", `{ "worktreeSparsePatternsPath": "missing.txt" }`);
4373-
yield* git(cwd, ["add", "t3.json"]);
4374-
yield* git(cwd, ["commit", "-m", "missing sparse patterns"]);
4372+
yield* writeTextFile(cwd, "patterns/keep.txt", "/*\n");
43754373
const driver = yield* GitVcsDriver.GitVcsDriver;
4376-
const worktreePath = pathService.join(yield* makeTmpDir("git-worktrees-"), "missing");
4377-
4378-
const error = yield* Effect.flip(
4379-
driver.createWorktree({
4374+
const worktrees = yield* makeTmpDir("git-worktrees-");
4375+
for (const patternsPath of ["missing.txt", "patterns"]) {
4376+
yield* writeTextFile(
43804377
cwd,
4381-
path: worktreePath,
4382-
refName: initialBranch,
4383-
newRefName: "feature/missing",
4384-
}),
4385-
);
4378+
"t3.json",
4379+
JSON.stringify({ worktreeSparsePatternsPath: patternsPath }),
4380+
);
4381+
yield* git(cwd, ["add", "."]);
4382+
yield* git(cwd, ["commit", "-m", "missing sparse patterns"]);
4383+
const worktreePath = pathService.join(worktrees, patternsPath);
4384+
4385+
const error = yield* Effect.flip(
4386+
driver.createWorktree({
4387+
cwd,
4388+
path: worktreePath,
4389+
refName: initialBranch,
4390+
newRefName: `feature/${patternsPath}`,
4391+
}),
4392+
);
43864393

4387-
assert.match(error.detail, /missing\.txt/);
4388-
assert.isFalse(yield* fileSystem.exists(worktreePath));
4389-
assert.notInclude(yield* git(cwd, ["worktree", "list"]), "missing");
4394+
assert.include(error.detail, patternsPath);
4395+
assert.isFalse(yield* fileSystem.exists(worktreePath));
4396+
assert.notInclude(yield* git(cwd, ["worktree", "list"]), worktreePath);
4397+
assert.equal(yield* git(cwd, ["branch", "--list", `feature/${patternsPath}`]), "");
4398+
}
43904399
}),
43914400
);
43924401

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4067,7 +4067,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
40674067
: yield* executeGit(
40684068
"GitVcsDriver.createWorktree.readSparsePatterns",
40694069
cwd,
4070-
["show", `${ref}:${patternsPath}`],
4070+
["cat-file", "blob", `${ref}:${patternsPath}`],
40714071
{ allowNonZeroExit: true },
40724072
);
40734073
if (patterns === null || patterns.exitCode !== 0) {

0 commit comments

Comments
 (0)