Skip to content

Add only-branches option to VCS repositories - #13086

Merged
Seldaek merged 6 commits into
composer:mainfrom
shyim:vcs-only-branches
Oct 21, 2026
Merged

Seldaek merged 6 commits into
composer:mainfrom
shyim:vcs-only-branches

Conversation

@shyim

@shyim shyim commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Repositories with a large number of branches are slow to load through a VCS repository, as the composer.json of every single branch has to be read. For example shopware/shopware has 978 branches, while you usually only care about a handful of release branches.

This adds an only-branches option to VCS repositories. It takes a list of branch names, which can contain * wildcards, and skips all other branches before their composer.json is read. The default branch is always loaded, as it is read anyway to determine the package name and carries the default branch alias. Tags are not affected.

Usage

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/symfony/symfony",
            "only-branches": ["7.4", "8.*"]
        }
    ]
}

With -vvv, every skipped branch is reported as Skipped branch <name>, not matching the only-branches filter.

The naming follows the existing only option, which filters by package name and is applied after the repository has been fully loaded, so it cannot avoid this cost.

Performance

Loading shopware/shopware (978 branches) with the git driver and a cold composer.json cache (cache-repo-dir). The git mirror was already cloned (35s) and shared between both runs, so only the reading of the branches and tags is measured.

Time Packages
without filter 29.14s 1198
"only-branches": ["6.6.x", "6.7.*"] 7.05s 239

The remaining time is mostly spent reading the tags, which are not filtered.

Changes

  • VcsRepository: filter branches after getBranches(), so this applies to all drivers
  • composer-schema.json: add only-branches to the vcs-repository definition
  • Docs: new "Restricting the loaded branches" section in 05-repositories.md
  • Test: VcsRepositoryTest::testLoadVersionsWithOnlyBranchesFilter

🤖 Generated with Claude Code

shyim and others added 6 commits October 21, 2026 22:56
Repositories with many branches (e.g. symfony/symfony or shopware/shopware)
are slow to load as the composer.json of every branch has to be read. The
new only-branches option takes a list of branch names, supporting * wildcards,
and skips all other branches before reading them. The default branch is
always loaded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Seldaek

Seldaek commented Oct 21, 2026

Copy link
Copy Markdown
Member

Thanks

@Seldaek
Seldaek merged commit 1bd7c27 into composer:main Oct 21, 2026
23 checks passed
@Seldaek Seldaek added this to the 2.11 milestone Oct 21, 2026
@shyim
shyim deleted the vcs-only-branches branch October 22, 2026 02:53
@InvisibleSmiley

InvisibleSmiley commented Oct 22, 2026 •

Copy link
Copy Markdown

I think this is missing an explicit test and documentation that an empty list is allowed, resulting in only the default branch to be allowed. If that is in fact not allowed, that would be a bug.

Seldaek added a commit that referenced this pull request Oct 22, 2026
@Seldaek

Seldaek commented Oct 22, 2026

Copy link
Copy Markdown
Member

@InvisibleSmiley fixed in c172206

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants