The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 12:15 UTC
fix(server): check out cloned submodules when one submodule clone fails in a new worktree (#37030)
Julius Marminge committed
Nov 14, 2026 at 19:38 UTC
5c9e5c1e98d946c5647d4ef23519573fb45f58c9
2 files changed
+77
-32
apps/server/src/vcs/GitVcsDriverCore.test.ts
+11
-5
@@ -6896,12 +6896,16 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
6896
const fileSystem = yield* FileSystem.FileSystem;
6897
const pathService = yield* Path.Path;
6898
6899
+ const submoduleRepo = yield* makeTmpDir("git-submodule-");
6900
+ yield* initRepoWithCommit(submoduleRepo);
6901
+
6902
const cwd = yield* makeTmpDir();
6903
const { initialBranch } = yield* initRepoWithCommit(cwd);
6901
- yield* writeTextFile(
6902
- cwd,
6903
- ".gitmodules",
6904
- '[submodule "missing"]\n\tpath = missing\n\turl = /nonexistent/repo.git\n',
6904
+ yield* git(cwd, ["submodule", "add", NodeURL.pathToFileURL(submoduleRepo).href, "shared"]);
6905
+ yield* fileSystem.writeFileString(
6906
+ pathService.join(cwd, ".gitmodules"),
6907
+ (yield* fileSystem.readFileString(pathService.join(cwd, ".gitmodules"))) +
6908
+ '[submodule "missing"]\n\tpath = missing\n\turl = /nonexistent/repo.git\n',
6909
);
6910
yield* git(cwd, ["add", "."]);
6911
const gitlink = yield* git(cwd, ["rev-parse", "HEAD"]);
@@ -6934,7 +6938,9 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
6938
assert.lengthOf(results, 1);
6939
assert.isFalse(results[0]!.ok);
6940
assert.include(results[0]!.detail, "GitVcsDriver.createWorktree.updateSubmodules");
6937
- }),
6941
+ // A submodule that did clone must not be left as a bare gitdir that reads as modified.
6942
+ assert.equal(yield* git(worktreePath, ["status", "--porcelain"]), "");
6943
+ }).pipe(withGitFileProtocol),
6944
);
6945
6946
it.effect("creates worktrees under the configured worktrees directory", () =>
apps/server/src/vcs/GitVcsDriverCore.ts
+66
-27
@@ -5215,6 +5215,61 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
5215
yield* progress.onSubmodulesStarted();
5216
}
5217
const onSubmoduleLine = progress?.onSubmoduleLine;
5218
+ const updateSubmodules = (paths: readonly string[]) =>
5219
+ runGit(
5220
+ "GitVcsDriver.createWorktree.updateSubmodules",
5221
+ worktreePath,
5222
+ [
5223
+ "submodule",
5224
+ "update",
5225
+ "--init",
5226
+ ...(submoduleMode.value === "recursive" ? ["--recursive"] : []),
5227
+ // Git reports transfer progress to a pipe only when forced.
5228
+ ...(onSubmoduleLine ? ["--progress"] : []),
5229
+ // A clone left by a failed update already has HEAD at the gitlink, so Git would skip it.
5230
+ ...(paths.length > 0 ? ["--force", "--", ...paths] : []),
5231
+ ],
5232
+ {
5233
+ // Cloning scales with remote size; let it finish or be cancelled, like worktree add.
5234
+ timeoutMs: null,
5235
+ ...(onSubmoduleLine
5236
+ ? {
5237
+ env: { LANGUAGE: "C" },
5238
+ progress: { onStdoutLine: onSubmoduleLine, onStderrLine: onSubmoduleLine },
5239
+ // Progress for many submodules can pass the output cap; truncate instead of failing.
5240
+ appendTruncationMarker: true,
5241
+ keepLineCallbacksAfterTruncation: true,
5242
+ }
5243
+ : {}),
5244
+ },
5245
+ );
5246
+ // One failed clone stops Git before it checks out any submodule, leaving the cloned ones
5247
+ // as empty working trees that read as modified; check those out on their own.
5248
+ const checkOutClonedSubmodules = Effect.gen(function* () {
5249
+ // Records are "submodule.<name>.path\n<path>".
5250
+ const submodulePaths = splitNullSeparatedPaths(
5251
+ yield* runGitStdout("GitVcsDriver.createWorktree.listSubmodules", worktreePath, [
5252
+ "config",
5253
+ "-z",
5254
+ "--file",
5255
+ ".gitmodules",
5256
+ "--get-regexp",
5257
+ "^submodule\\..*\\.path$",
5258
+ ]),
5259
+ false,
5260
+ ).flatMap((record) => {
5261
+ const newline = record.indexOf("\n");
5262
+ return newline === -1 ? [] : [record.slice(newline + 1)];
5263
+ });
5264
+ const clonedPaths = yield* Effect.filter(submodulePaths, (submodulePath) =>
5265
+ fileSystem
5266
+ .exists(path.join(worktreePath, submodulePath, ".git"))
5267
+ .pipe(Effect.orElseSucceed(() => false)),
5268
+ );
5269
+ if (clonedPaths.length > 0) {
5270
+ yield* updateSubmodules(clonedPaths);
5271
+ }
5272
+ });
5273
// Registering submodule URLs writes the shared config; the clones that follow do not.
5274
yield* runGit(
5275
"GitVcsDriver.createWorktree.initSubmodules",
@@ -5222,39 +5277,23 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
5277
["submodule", "init"],
5278
{ writesSharedConfig: true },
5279
).pipe(
5225
- Effect.andThen(
5226
- runGit(
5227
- "GitVcsDriver.createWorktree.updateSubmodules",
5228
- worktreePath,
5229
- [
5230
- "submodule",
5231
- "update",
5232
- "--init",
5233
- ...(submoduleMode.value === "recursive" ? ["--recursive"] : []),
5234
- // Git reports transfer progress to a pipe only when forced.
5235
- ...(onSubmoduleLine ? ["--progress"] : []),
5236
- ],
5237
- {
5238
- // Cloning scales with remote size; let it finish or be cancelled, like worktree add.
5239
- timeoutMs: null,
5240
- ...(onSubmoduleLine
5241
- ? {
5242
- env: { LANGUAGE: "C" },
5243
- progress: { onStdoutLine: onSubmoduleLine, onStderrLine: onSubmoduleLine },
5244
- // Progress for many submodules can pass the output cap; truncate instead of failing.
5245
- appendTruncationMarker: true,
5246
- keepLineCallbacksAfterTruncation: true,
5247
- }
5248
- : {}),
5249
- },
5250
- ),
5251
- ),
5280
+ Effect.andThen(updateSubmodules([])),
5281
Effect.matchEffect({
5282
onFailure: (cause) =>
5283
Effect.logWarning("worktree submodule checkout failed; submodules may be incomplete", {
5284
worktreePath,
5285
cause,
5286
}).pipe(
5287
+ Effect.andThen(
5288
+ checkOutClonedSubmodules.pipe(
5289
+ Effect.catch((retryCause) =>
5290
+ Effect.logWarning("could not check out the submodules that did clone", {
5291
+ worktreePath,
5292
+ cause: retryCause,
5293
+ }),
5294
+ ),
5295
+ ),
5296
+ ),
5297
Effect.andThen(
5298
progress?.onSubmodulesFinished
5299
? progress.onSubmodulesFinished({ ok: false, detail: cause.message })