Skip to content

Keep the cache enabled for projects in submodules - #189

Open
djack42 wants to merge 1 commit into
microsoft:mainfrom
djack42:upstream-pr/submodule-repo-root
Open

djack42 wants to merge 1 commit into
microsoft:mainfrom
djack42:upstream-pr/submodule-repo-root

Conversation

@djack42

@djack42 djack42 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

GetRepoRoot takes the nearest .git above each entry point project. When a solution of a superproject also contains projects of one of its git submodules, those projects find the submodule's .git file first. The graph then has two repo roots, and the plugin disables the cache:

warning : Graph contains projects from multiple git repositories. Disabling the cache. Repo roots: <repo>, <repo>\<submodule>

The file hashes already support submodules: GitFileHashProvider lists the initialized submodules with git submodule status --recursive, hashes their files, and replaces the gitlink entry with them. Only the choice of the repo root stops them from being used.

With this change, when every other repo root is an initialized submodule of one of them, that superproject is the repo root. Paths in fingerprints are then relative to the superproject. The cache stays disabled, as today, for repo roots that are not nested in one another, and for a nested repository that is not an initialized submodule (e.g. a clone inside the working tree), whose files the superproject's hashes would not cover.

We use it for a repository that consumes another one as a submodule: its solution (64 graph nodes, part of them in the submodule) went from the warning above, and no caching, to 64/64 hits on warm CI builds, ~300 s → ~65 s per job.

Tests: MSBuildCachePluginBaseTests covers a superproject with a submodule, with a nested submodule (a/b as listed by git submodule status --recursive), a nested repository that is not a submodule, and unrelated roots, including a sibling whose path starts with the same characters.

🤖 Generated with Claude Code

The repo root is the nearest .git above each entry point project. When a
solution of a superproject also contains projects of one of its submodules,
those projects find the .git file of the submodule, so the graph has two
repo roots and the cache was disabled.

The file hashes of a repo root already include the files of its initialized
submodules (git submodule status --recursive). So when every other repo root
is an initialized submodule of one of them, that superproject is now the
repo root. Repo roots which are not nested, and nested repositories which are
not initialized submodules, still disable the cache.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant