Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(server): check out submodules in a new worktree (#7674)

Rodrigo Brechardbe3da50e96bb
diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.ts
index 66dc7b96a..33279fe00 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.test.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts
@@ -1374,6 +1374,92 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
}),
);
+ it.effect("checks out submodules in a new worktree", () =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const pathService = yield* Path.Path;
+
+ // Git refuses `file:` submodule transports by default (CVE-2022-39253)
+ // and ignores repo-level config for it, so a local fixture needs the
+ // env allowance. Real submodules are https/ssh and need none of this.
+ const previousAllowedProtocol = process.env.GIT_ALLOW_PROTOCOL;
+ process.env.GIT_ALLOW_PROTOCOL = "file";
+ yield* Effect.addFinalizer(() =>
+ Effect.sync(() => {
+ if (previousAllowedProtocol === undefined) {
+ delete process.env.GIT_ALLOW_PROTOCOL;
+ } else {
+ process.env.GIT_ALLOW_PROTOCOL = previousAllowedProtocol;
+ }
+ }),
+ );
+
+ // A real submodule: `git worktree add` leaves these empty, which is
+ // what silently strips shared tooling out of every new worktree.
+ const submoduleRepo = yield* makeTmpDir("git-submodule-");
+ yield* initRepoWithCommit(submoduleRepo);
+ yield* writeTextFile(submoduleRepo, "SHARED.md", "# shared\n");
+ yield* git(submoduleRepo, ["add", "."]);
+ yield* git(submoduleRepo, ["commit", "-m", "shared"]);
+
+ const cwd = yield* makeTmpDir();
+ const { initialBranch } = yield* initRepoWithCommit(cwd);
+ yield* git(cwd, ["submodule", "add", submoduleRepo, "shared"]);
+ yield* git(cwd, ["commit", "-m", "add submodule"]);
+
+ const worktreePath = pathService.join(
+ yield* makeTmpDir("git-worktrees-"),
+ "submodule-worktree",
+ );
+ const driver = yield* GitVcsDriver.GitVcsDriver;
+ yield* driver.createWorktree({
+ cwd,
+ path: worktreePath,
+ refName: initialBranch,
+ newRefName: "feature/submodules",
+ });
+
+ assert.equal(
+ yield* fileSystem.exists(pathService.join(worktreePath, "shared", "SHARED.md")),
+ true,
+ );
+ }),
+ );
+
+ it.effect("still creates the worktree when submodule checkout fails", () =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const pathService = yield* Path.Path;
+
+ const cwd = yield* makeTmpDir();
+ const { initialBranch } = yield* initRepoWithCommit(cwd);
+ // Points at a repository that does not exist, so the checkout fails the
+ // way an unreachable private remote would. Creation must still succeed.
+ yield* writeTextFile(
+ cwd,
+ ".gitmodules",
+ '[submodule "missing"]\n\tpath = missing\n\turl = /nonexistent/repo.git\n',
+ );
+ yield* git(cwd, ["add", "."]);
+ yield* git(cwd, ["commit", "-m", "add unreachable submodule"]);
+
+ const worktreePath = pathService.join(
+ yield* makeTmpDir("git-worktrees-"),
+ "broken-submodule-worktree",
+ );
+ const driver = yield* GitVcsDriver.GitVcsDriver;
+ const created = yield* driver.createWorktree({
+ cwd,
+ path: worktreePath,
+ refName: initialBranch,
+ newRefName: "feature/broken-submodules",
+ });
+
+ assert.equal(created.worktree.path, worktreePath);
+ assert.equal(yield* fileSystem.exists(worktreePath), true);
+ }),
+ );
+
it.effect("creates and removes a worktree for a new refName", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.ts
index 800ec6d4e..f48ac5f3b 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.ts
@@ -2776,6 +2776,30 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
timeoutMs: WORKTREE_ADD_TIMEOUT_MS,
});
+ // `git worktree add` leaves submodules empty, so a repo that keeps agent
+ // skills, tooling or source in one gets a worktree that is quietly missing
+ // them. Best-effort: the objects are usually already in the parent's
+ // `.git/modules`, but a first-ever clone needs the network, and failing to
+ // populate a submodule must not roll back the caller's thread.
+ const hasSubmodules = yield* fileSystem
+ .exists(path.join(worktreePath, ".gitmodules"))
+ .pipe(Effect.orElseSucceed(() => false));
+ if (hasSubmodules) {
+ yield* runGit("GitVcsDriver.createWorktree.updateSubmodules", worktreePath, [
+ "submodule",
+ "update",
+ "--init",
+ "--recursive",
+ ]).pipe(
+ Effect.catch((cause) =>
+ Effect.logWarning("worktree submodule checkout failed; submodule paths are empty", {
+ worktreePath,
+ cause,
+ }),
+ ),
+ );
+ }
+
if (input.newRefName && input.baseRefName) {
const remoteNames = yield* listRemoteNames(input.cwd).pipe(Effect.orElseSucceed(() => []));
const parsedBaseRef = parseRemoteRefWithRemoteNames(