Skip to content

feat: git CLI backend for mutating/network operations behind GITVERSION_GIT_BACKEND switch - #5042

Merged
arturcic merged 7 commits into
GitTools:feature/managed-gitfrom
arturcic:feature/managed-git-migration
Jul 11, 2026
Merged

arturcic merged 7 commits into
GitTools:feature/managed-gitfrom
arturcic:feature/managed-git-migration

Conversation

@arturcic

Copy link
Copy Markdown
Member

Description

First step of the LibGit2Sharp replacement (#5031): a git CLI backend for all mutating and network operations, selectable via a single environment variable, with the design document and the interface cleanups that later phases build on.

Closes #5032

What's included

  • Design document (docs/design/managed-git-migration.md): motivation, library landscape research, LibGit2Sharp surface analysis, target architecture, phases A–F with the explicit release mapping (v7.0 default libgit2, v7.1 default managed, removal later), risks and verification strategy.
  • Interface cleanups (Phase B-pre): CommitFilter.IncludeReachableFrom/ExcludeReachableFrom typed via new ICommitish marker (implemented by ICommit/IBranch) instead of object?; CommitSortStrategies mapped explicitly to LibGit2Sharp instead of a numeric cast; public IRepository.ToGitRepository() extension internalized.
  • Phase A — GitVersion.Git.CommandLine: Process-based GitCliExecutor (argument lists, LC_ALL=C, GIT_TERMINAL_PROMPT=0) and GitCliMutator implementing clone (--no-checkout), fetch, checkout and ls-remote, with per-invocation basic auth via http.extraHeader and stderr mapped onto the existing LockedFileException/401/403/404 handling.
  • Single backend switch: GITVERSION_GIT_BACKEND=libgit2|managed; GitRepository routes its IMutatingGitRepository operations through the CLI when managed is selected. Default remains libgit2 for v7.0.
  • Dual-backend CI: the unit-test workflow matrix gains a git_backend dimension — the full suite runs against both backends on every OS until libgit2 is removed.
  • Breaking-changes entries for the backend selection table and the abstraction API changes.
  • Cache-key fix: GitVersionCacheKeyFactory no longer throws when .git/refs is absent (fresh clones by recent git versions keep all refs packed).

Parity notes (managed backend vs libgit2)

  • Checkout strips the refs/heads/ prefix (git would detach where libgit2 attaches) and passes --no-guess (libgit2 has no remote-branch DWIM).
  • ls-remote parsing drops peeled ^{} and symbolic HEAD entries to match ListReferences.
  • After CLI mutations only the cached collection wrappers are dropped; the libgit2 handle is not disposed (handed-out wrappers reference its native memory).

Verification

  • Full GitVersion.Core.Tests (36k) and GitVersion.App.Tests (345) pass with both GITVERSION_GIT_BACKEND=libgit2 and =managed; CI matrix green on all OS × .NET × backend legs.

🤖 Generated with Claude Code

arturcic and others added 6 commits July 11, 2026 01:07
…a managed Git implementation

Hybrid approach: vendored managed reader (ported from NBGV ManagedGit) for
all read/history operations, git CLI shell-out for writes and network.
Removes all native libgit2 binaries. See GitTools#5031.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Type CommitFilter.IncludeReachableFrom/ExcludeReachableFrom as new
  ICommitish marker interface (implemented by ICommit and IBranch)
  instead of object?
- Map CommitSortStrategies to LibGit2Sharp explicitly instead of relying
  on numeric enum value parity
- Internalize LibGit2SharpExtensions.ToGitRepository (test-only usage)
  and expose it to test assemblies via InternalsVisibleTo

Preparation for the managed Git backend (GitTools#5031),
so both backends implement the same honest contract.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
New GitVersion.Git.CommandLine project with a Process-based GitCliExecutor
and GitCliMutator implementing clone (--no-checkout), fetch, checkout and
ls-remote. GitRepository routes its IMutatingGitRepository operations to
the CLI when GITVERSION_GIT_BACKEND_MUTATOR=cli is set (default remains
libgit2), refreshing cached collections after external mutations.

Parity details vs libgit2: canonical refs/heads/* checkout attaches HEAD
(git would detach), --no-guess suppresses remote-branch DWIM, ls-remote
drops peeled and symbolic HEAD entries, stderr mapped to the existing
LockedFileException/401/403/404 handling, basic auth passed per invocation
via http.extraHeader.

Phase A of GitTools#5031.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ar and test both in CI

- GITVERSION_GIT_BACKEND=libgit2|managed selects the whole backend stack;
  'managed' opts into the new implementation as far as it exists (currently
  the git CLI mutator, later also the managed reader). Default: libgit2.
- Unit-test workflow matrix gains a git_backend dimension so the full suite
  runs against both backends on every OS until libgit2 is removed; coverage
  and test summaries publish from the libgit2 leg only.
- Both backends will ship side by side for several releases to give users a
  testing window before libgit2 is dropped (GitTools#5031).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ction API changes

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… key

Recent git versions write clone refs only to packed-refs and may not
create the refs directory at all, so a git-CLI clone (managed backend)
can produce a repository without .git/refs. Hash empty contents instead
of throwing DirectoryNotFoundException.

Fixes the ubuntu managed-backend CI legs (CacheKeyForWorktree,
CacheKeySameAfterReNormalizing).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@arturcic arturcic added this to the 7.x milestone Jul 11, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@arturcic arturcic linked an issue Jul 11, 2026 that may be closed by this pull request
@arturcic
arturcic changed the base branch from next/v7 to feature/managed-git July 11, 2026 09:26
@mergify

mergify Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@arturcic
arturcic merged commit 14d43d3 into GitTools:feature/managed-git Jul 11, 2026
132 checks passed
@arturcic
arturcic deleted the feature/managed-git-migration branch July 11, 2026 09:55
@mergify

mergify Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Thank you @arturcic for your contribution!

arturcic added a commit that referenced this pull request Jul 16, 2026
feat: git CLI backend for mutating/network operations behind GITVERSION_GIT_BACKEND switch
arturcic added a commit to arturcic/GitVersion that referenced this pull request Jul 17, 2026
…gration

feat: git CLI backend for mutating/network operations behind GITVERSION_GIT_BACKEND switch
arturcic added a commit that referenced this pull request Jul 17, 2026
feat: git CLI backend for mutating/network operations behind GITVERSION_GIT_BACKEND switch
@arturcic arturcic mentioned this pull request Aug 19, 2026
78 of 100 tasks
@arturcic arturcic modified the milestones: 7.0.x, 7.0.0 Nov 15, 2026
@arturcic arturcic removed this from the 7.0.0 milestone Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git CLI backend for mutating and network operations (Phase A)

1 participant