Skip to content

Fast worktree checkout breaks submodules when git config sets submodule.recurse=true #45836

Done

Description

@maxdavidson

What happened

With fast worktree checkout on (the macOS default) and submodule.recurse = true in my global git config, every new worktree of a repository with a submodule comes up with that submodule broken. In the worktree, git status fails with gitfile does not point to a valid repository and git submodule update --init fails with could not get a repository handle for submodule. Checkpoint capture fails too. worktreeSubmodules: "none" doesn't avoid it.

Diagnosis

The checkout cache's read-tree calls in apps/server/src/vcs/worktreeCheckoutCache.ts inherit the user's submodule.recurse: the two in build, through CACHE_INDEX_CONFIG, and the read-tree -m -u in create. With it on, git tries to populate the submodule. A linked worktree has no gitdir for it yet, so git writes a config-only one at .git/worktrees/<worktree>/modules/<name>, with no objects, HEAD or refs, and exits 128. That's the git read-tree failed below, which the background build only logs. The following git submodule update (from createWorktree or a setup script) then fails on that gitdir.

git worktree add passes --no-recurse-submodules internally, so fastWorktreeCheckout: false is unaffected.

Suggested fix: add submodule.recurse=false to CACHE_INDEX_CONFIG and to the -c flags of the read-tree in create, as #42520 did for git grep. The cache stores only tracked files, and createWorktree populates submodules afterwards, so recursing there never helps.

Steps to reproduce

Fast checkout only runs on macOS. On a Mac: set git config --global submodule.recurse true, add a project with an initialized submodule, and start two threads in new worktrees. The first builds the cache, the second clones from it. Both worktrees end up broken.

On any platform, this test in apps/server/src/vcs/worktreeCheckoutCache.test.ts reproduces it with the existing fixture (vp test run src/vcs/worktreeCheckoutCache.test.ts -t "submodule.recurse" from apps/server):

Test
it.effect("keeps submodules working when the user's config sets submodule.recurse", () =>
  Effect.gen(function* () {
    const fixture = yield* setup;
    const library = NodePath.join(fixture.root, "library");
    NodeFS.mkdirSync(library);
    sh(library, ["init", "-q", "-b", "main"]);
    NodeFS.writeFileSync(NodePath.join(library, "lib.txt"), "library\n");
    sh(library, ["add", "."]);
    sh(library, ["-c", "user.name=Test", "-c", "[email protected]", "commit", "-qm", "lib"]);
    const allowFile = ["-c", "protocol.file.allow=always"];
    sh(fixture.repo, [...allowFile, "submodule", "add", "-q", library, "lib"]);
    // T3's own submodule step can't clone a local path, so the test checks it out like a setup script.
    NodeFS.writeFileSync(
      NodePath.join(fixture.repo, "t3.json"),
      JSON.stringify({ worktreeSubmodules: "none" }),
    );
    sh(fixture.repo, ["add", "t3.json"]);
    sh(fixture.repo, ["commit", "-qm", "add submodule"]);
    // Set in the repository rather than globally, because the fixture ignores global config.
    sh(fixture.repo, ["config", "submodule.recurse", "true"]);

    const stock = yield* fixture.create("stock", "main", false);
    // Background builds swallow their failures, so the damage shows up afterwards.
    yield* fixture.build(stock).pipe(Effect.ignore);
    sh(stock, [...allowFile, "submodule", "update", "--init"]);
    assert.match(sh(stock, ["submodule", "status"]), /^ [0-9a-f]{40} lib/u);

    const fast = yield* fixture.create("fast");
    assert.isFalse(fixture.checkedOutWithGit("fast"));
    sh(fast, [...allowFile, "submodule", "update", "--init"]);
    assert.match(sh(fast, ["submodule", "status"]), /^ [0-9a-f]{40} lib/u);
    assert.equal(sh(fast, ["status", "--porcelain"]), "");
  }).pipe(Effect.scoped, Effect.provide(layerTest)),
);

On main @ 5712039 it fails at the first submodule update with fatal: could not get a repository handle for submodule 'lib'. With the suggested fix it passes, and so do the other 15 tests in the file.

Version

0.1.13 (desktop app); same code on main @ 5712039

Environment

macOS, git 2.56.1

Evidence

INFO  WorktreeCheckoutCacheError: git read-tree failed
        at WorktreeCheckoutCache.build
        at createWorktree
WARN  worktree submodule checkout failed; submodules may be incomplete
        operation: 'GitVcsDriver.createWorktree.updateSubmodules', exitCode: 128, reason: 'not_a_repository'
WARN  VcsProcessExitError: ... git rev-parse (<worktree>/packages/grpc/proto/gcs-bolt) exited with 128
        - fatal: gitfile does not point to a valid repository: <worktree>/packages/grpc/proto/gcs-bolt/.git

.git/worktrees/<worktree>/modules/gcs-bolt/ contains only a config with core.worktree.

Related issues

#37027 (closed) was about T3 carrying on after a failed submodule update. This issue is about the cache causing that failure.

Fix applied or workaround

fastWorktreeCheckout: false, or git config submodule.recurse false in the repository. To repair a broken worktree, delete its modules/<name> gitdir and <submodule path>/.git, then run git submodule update --init.

Filed by

Claude Opus 5.5 in T3 Code (Cursor harness), on Max's behalf

Activity

  1. added
    via-triage
    on Nov 30, 2026
  2. added a commit that references this issue on Nov 30, 2026
    11c62ec
  3. maxdavidson commented on Nov 30, 2026

    @maxdavidson
    ContributorAuthor

    Fix with the test from this report: #45839

  4. juliusmarminge commented on Nov 30, 2026

    @juliusmarminge
    Member

    Fixed by #45839, now on main: With submodule.recurse=true and fast worktree checkout enabled, newly created worktrees now permit git submodule update --init and git status without the invalid submodule gitdir errors reported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    via-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions