Skip to content

Commit e80cb32

Browse files
fix(server): let Git resolve bare-root gitfiles
1 parent 2b1d4d8 commit e80cb32

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

‎apps/server/src/workspace/WorkspacePaths.test.ts‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,79 @@ it.layer(TestLayer)("WorkspacePathsLive", (it) => {
255255
}),
256256
);
257257

258+
it.effect("lets Git reject malformed gitfiles instead of probing an unrelated target", () =>
259+
Effect.gen(function* () {
260+
const workspacePaths = yield* WorkspacePaths.WorkspacePaths;
261+
const vcsProcess = yield* VcsProcess.VcsProcess;
262+
const root = yield* makeBareRoot();
263+
for (const pointer of ["metadata\ngitdir: .bare\n", "gitdir:.bare\n", " gitdir: .bare\n"]) {
264+
yield* writeTextFile(root, ".git", pointer);
265+
const native = yield* vcsProcess.run({
266+
operation: "WorkspacePaths.test.malformedGitfile",
267+
command: "git",
268+
cwd: root,
269+
args: ["rev-parse", "--is-bare-repository"],
270+
allowNonZeroExit: true,
271+
});
272+
expect(native.exitCode).not.toBe(0);
273+
expect(yield* workspacePaths.ensureNotBareRepositoryLayout(root)).toBe(root);
274+
}
275+
}),
276+
);
277+
278+
it.effect.skipIf(HostProcessPlatform.defaultValue() === "win32")(
279+
"preserves trailing spaces in POSIX gitdir names",
280+
() =>
281+
Effect.gen(function* () {
282+
const workspacePaths = yield* WorkspacePaths.WorkspacePaths;
283+
const path = yield* Path.Path;
284+
const root = yield* makeTempDir();
285+
yield* runGit(root, ["init", "--separate-git-dir", path.join(root, "store ")]);
286+
yield* runGit(root, ["init", "--bare", path.join(root, "store")]);
287+
expect((yield* runGit(root, ["rev-parse", "--is-inside-work-tree"])).stdout.trim()).toBe(
288+
"true",
289+
);
290+
291+
expect(yield* workspacePaths.ensureNotBareRepositoryLayout(root)).toBe(root);
292+
}),
293+
);
294+
295+
it.effect(
296+
"classifies the root independently of inherited Git worktree and gitdir overrides",
297+
() =>
298+
Effect.gen(function* () {
299+
const vcsProcess = yield* VcsProcess.VcsProcess;
300+
const path = yield* Path.Path;
301+
const root = yield* makeBareRoot();
302+
const otherRoot = yield* makeTempDir();
303+
yield* runGit(otherRoot, ["init"]);
304+
for (const inheritedEnv of [
305+
{ GIT_WORK_TREE: root },
306+
{ GIT_DIR: path.join(otherRoot, ".git") },
307+
]) {
308+
const native = yield* vcsProcess.run({
309+
operation: "WorkspacePaths.test.inheritedGitEnvironment",
310+
command: "git",
311+
cwd: root,
312+
args: ["rev-parse", "--is-bare-repository"],
313+
env: inheritedEnv,
314+
});
315+
expect(native.stdout.trim()).toBe("false");
316+
const workspacePaths = yield* WorkspacePaths.make.pipe(
317+
Effect.provideService(VcsProcess.VcsProcess, {
318+
run: (input) =>
319+
vcsProcess.run({ ...input, env: { ...inheritedEnv, ...input.env } }),
320+
}),
321+
);
322+
323+
const error = yield* workspacePaths
324+
.ensureNotBareRepositoryLayout(root)
325+
.pipe(Effect.flip);
326+
expect(error).toBeInstanceOf(WorkspacePaths.WorkspaceRootBareRepositoryLayoutError);
327+
}
328+
}),
329+
);
330+
258331
it.effect.skipIf(HostProcessPlatform.defaultValue() === "win32")(
259332
"preserves literal backslashes in POSIX gitdir names",
260333
() =>

‎apps/server/src/workspace/WorkspacePaths.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,10 @@ export const make = Effect.gen(function* () {
202202
.run({
203203
operation: "WorkspacePaths.isBareRepositoryLayout",
204204
command: "git",
205-
args: ["--git-dir", gitDir, "rev-parse", "--is-bare-repository"],
205+
// Let Git read its own gitfile syntax; the parsed target is only a fast-path filter.
206+
args: ["--git-dir", gitPath, "rev-parse", "--is-bare-repository"],
206207
cwd: normalizedWorkspaceRoot,
208+
env: { GIT_WORK_TREE: undefined },
207209
allowNonZeroExit: true,
208210
timeoutMs: 5_000,
209211
maxOutputBytes: 4_096,

0 commit comments

Comments
 (0)