Skip to content

Feature: Support shallow cloning of git repositories #4561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

joaopbnogueira
Copy link

Description

This PR adds support for shallow cloning of git repositories. While having the full git history available is the only way to truly be certain of the next version, this is not desirable on larger repositories with many thousands of commits as a full clone can take several minutes and is usually neither desirable nor needed as there is sufficient information (e.g. git tags) available on the N most recent commits to be able to reliably determine the next version without requiring a full clone.

Since this is a special scenario it put behind an explicit flag allowshallow to ensure both backwards compatibility and awareness of the user of the tool.

Motivation and Context

Observation that the git checkout step on CI pipelines is taking 5-20 minutes on large internal repositories due to having to fetch the whole history as required by GitVersion. This step sometimes represents more time than the rest of the steps, leading to costs and undesirable long iteration cycles.

How Has This Been Tested?

  • Unit tests

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@Copilot Copilot AI review requested due to automatic review settings May 30, 2025 13:26
Copy link

@Copilot 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

This PR adds support for shallow cloning of git repositories through an explicit flag, allowing users to bypass the full-history clone for improved performance on large repositories. Key changes include the addition of the AllowShallow flag in settings and command-line arguments, updates to GitPreparer to conditionally allow shallow clones, and comprehensive tests and documentation updates supporting the new feature.

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.props Added MSBuild properties and tool arguments for shallow cloning support
src/GitVersion.Core/PublicAPI.Shipped.txt Updated public API to expose the new AllowShallow flag
src/GitVersion.Core/Options/Settings.cs Introduced the AllowShallow setting
src/GitVersion.Core/Core/GitPreparer.cs Modified shallow repository handling to log a warning when AllowShallow is enabled
src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs Added unit tests to validate the shallow clone behavior with AllowShallow flag
src/GitVersion.App/Arguments.cs Included the AllowShallow flag in application arguments
src/GitVersion.App/ArgumentParserExtensions.cs Extended boolean arguments to include allowshallow
src/GitVersion.App/ArgumentParser.cs Integrated allowshallow parsing logic
src/GitVersion.App.Tests/ArgumentParserTests.cs Added tests to verify correct parsing of the allowshallow argument
docs/input/docs/usage/msbuild.md, docs/input/docs/usage/cli/arguments.md, docs/input/docs/reference/requirements.md Updated documentation to reflect shallow cloning support
Comments suppressed due to low confidence (1)

src/GitVersion.App.Tests/ArgumentParserTests.cs:633

  • [nitpick] The test method name 'AllowshallowTrueWhenDefined' is inconsistent with the PascalCase used elsewhere for the 'AllowShallow' property. Consider renaming it to 'AllowShallowTrueWhenDefined' for consistency.
public void AllowshallowTrueWhenDefined()

@arturcic arturcic self-requested a review May 31, 2025 07:41
@arturcic
Copy link
Member

@joaopbnogueira good stuff, mind to rebase on top of main and add the new argument to https://github.com/GitTools/GitVersion/blob/main/src/GitVersion.App.Tests/HelpWriterTests.cs#L18
I will then take these changes for a spin, want to test some scenarios

@joaopbnogueira
Copy link
Author

joaopbnogueira commented May 31, 2025

Thanks @arturcic will do, I'll be off for 2 weeks but will pick this up as soon as I'm back.

Edit: found a few minutes and just did it, ready to take it for a spin @arturcic .

@joaopbnogueira joaopbnogueira force-pushed the feature/allow-unshallow-clones branch from 8b06315 to 4b19250 Compare June 1, 2025 08:50
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.

2 participants