Skip to content

Commit ce87dc7

Browse files
fix(server): opening a folder without Git installed no longer shows a spawn error (pingdotgg#14942)
Co-authored-by: Julius Marminge <[email protected]>
1 parent 3496ecb commit ce87dc7

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,47 @@ it.effect("GitVcsDriver forwards execute env to the VCS process", () => {
12771277
);
12781278
});
12791279

1280+
// The real VCS process, spawning `command` wherever the driver runs git.
1281+
const vcsProcessSpawning = (command: string) =>
1282+
Layer.effect(
1283+
VcsProcess.VcsProcess,
1284+
Effect.map(VcsProcess.make, (vcsProcess) =>
1285+
VcsProcess.VcsProcess.of({ run: (input) => vcsProcess.run({ ...input, command }) }),
1286+
),
1287+
).pipe(Layer.provide(ProcessRunner.layer), Layer.provideMerge(NodeServices.layer));
1288+
1289+
it.effect("GitVcsDriver treats a missing git executable as outside any repository", () =>
1290+
Effect.gen(function* () {
1291+
const fileSystem = yield* FileSystem.FileSystem;
1292+
const path = yield* Path.Path;
1293+
const cwd = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-missing-git-" });
1294+
const driver = yield* GitVcsDriver.makeVcsDriverShape().pipe(
1295+
Effect.provide(vcsProcessSpawning(path.join(cwd, "git"))),
1296+
);
1297+
1298+
assert.strictEqual(yield* driver.isInsideWorkTree(cwd), false);
1299+
assert.strictEqual(yield* driver.detectRepository(cwd), null);
1300+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
1301+
);
1302+
1303+
it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
1304+
"GitVcsDriver still fails detection when git exists but cannot be spawned",
1305+
() =>
1306+
Effect.gen(function* () {
1307+
const fileSystem = yield* FileSystem.FileSystem;
1308+
// A file without the execute bit fails to spawn with a permission error.
1309+
const notExecutable = yield* fileSystem.makeTempFileScoped({ prefix: "t3-git-" });
1310+
const driver = yield* GitVcsDriver.makeVcsDriverShape().pipe(
1311+
Effect.provide(vcsProcessSpawning(notExecutable)),
1312+
);
1313+
1314+
const error = yield* driver.isInsideWorkTree(process.cwd()).pipe(Effect.flip);
1315+
assert.strictEqual(error._tag, "VcsProcessSpawnError");
1316+
const detectionError = yield* driver.detectRepository(process.cwd()).pipe(Effect.flip);
1317+
assert.strictEqual(detectionError._tag, "VcsProcessSpawnError");
1318+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
1319+
);
1320+
12801321
it.effect("GitVcsDriver flushes checkpoint objects and refs to disk before publishing them", () => {
12811322
const observedArgs: ReadonlyArray<string>[] = [];
12821323

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
type VcsStatusResult,
3434
type WorktreeSubmodules,
3535
} from "@t3tools/contracts";
36+
import { isMissingExecutable } from "@t3tools/source-control-core/server/discovery";
3637
import * as HostProcess from "@t3tools/shared/HostProcess";
3738
import {
3839
makeGitVcsDriverCore,
@@ -561,7 +562,10 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
561562
timeoutMs: 5_000,
562563
maxOutputBytes: 4_096,
563564
},
564-
).pipe(Effect.map((result) => result.exitCode === 0 && result.stdout.trim() === "true"));
565+
).pipe(
566+
Effect.map((result) => result.exitCode === 0 && result.stdout.trim() === "true"),
567+
Effect.catchIf(isMissingExecutable, () => Effect.succeed(false)),
568+
);
565569

566570
const execute: VcsDriver.VcsDriver["Service"]["execute"] = (input) =>
567571
gitCommand(vcsProcess, input.operation, input.cwd, input.args, {

0 commit comments

Comments
 (0)