Skip to content

NuGet: Filter out submodule paths during discovery#15093

Merged
brettfo merged 3 commits into
mainfrom
dev/brettfo/nuget-submodule
May 21, 2026
Merged

NuGet: Filter out submodule paths during discovery#15093
brettfo merged 3 commits into
mainfrom
dev/brettfo/nuget-submodule

Conversation

@brettfo
Copy link
Copy Markdown
Contributor

@brettfo brettfo commented May 20, 2026

Summary

During NuGet dependency discovery, the updater now parses .gitmodules in the repo root and excludes any projects, global.json, or dotnet-tools.json files that fall under submodule directories. This prevents the updater from attempting to update dependencies in submodules, which would produce corrupted PRs.

Details

  • Added GitSubmoduleParser utility that parses .gitmodules to extract submodule paths
  • Modified DiscoveryWorker.RunAsync to filter discovered projects and files against submodule paths
  • Logs when files/projects are excluded due to being in a submodule

Closes #9433

@brettfo brettfo requested a review from a team as a code owner May 20, 2026 23:00
Copilot AI review requested due to automatic review settings May 20, 2026 23:00
@github-actions github-actions Bot added the L: dotnet:nuget NuGet packages via nuget or dotnet label May 20, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds submodule-aware filtering to NuGet discovery so Dependabot won’t attempt to discover/update projects or build files that live under git submodules (preventing corrupted PR output when repos include submodules).

Changes:

  • Added GitSubmoduleParser to parse .gitmodules and identify submodule root paths.
  • Updated DiscoveryWorker.RunAsync to exclude discovered projects, global.json, and dotnet-tools.json that are under submodule paths (with logging).
  • Added unit tests for .gitmodules parsing / path checks and a discovery scenario that filters submodule projects.
Show a summary per file
File Description
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/GitSubmoduleParser.cs New utility to extract submodule paths from .gitmodules and check whether a candidate path is inside a submodule.
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DiscoveryWorker.cs Filters discovered projects and special files when they’re located under submodule directories.
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/GitSubmoduleParserTests.cs Adds tests for parsing .gitmodules content and identifying submodule-contained paths.
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.cs Adds a discovery test ensuring projects under a submodule directory are excluded.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 4

brettfo and others added 3 commits May 21, 2026 16:53
Parse .gitmodules in the repo root to identify submodule directories,
then exclude any discovered projects, global.json, or dotnet-tools.json
files that fall under those paths. Log when files are excluded.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…son test

- Apply NormalizeUnixPathParts() in IsPathInSubmodule and ParseSubmodulePaths
  to handle paths with .. segments correctly
- Add test cases for paths containing .. segments
- Add GlobalJsonInSubmoduleIsFilteredOut test verifying global.json and
  dotnet-tools.json are excluded when workspace is in a submodule

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Filter projects in submodules before ExpandEntryPointsIntoProjectsAsync
returns, preventing unnecessary project restore operations. The
repoRootPath parameter is now required so submodule detection always
runs during expansion.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@brettfo brettfo force-pushed the dev/brettfo/nuget-submodule branch from f496535 to b733e1a Compare May 21, 2026 22:53
@brettfo brettfo merged commit 229e572 into main May 21, 2026
106 checks passed
@brettfo brettfo deleted the dev/brettfo/nuget-submodule branch May 21, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L: dotnet:nuget NuGet packages via nuget or dotnet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dependabot corrupts gitmodules while trying to update nugets

3 participants