@@ -220,6 +220,9 @@ public abstract class GitSourceProvider : ISourceProvider
220
220
// Info: https://github.com/git/git/commit/ce81b1da230cf04e231ce337c2946c0671ffb303
221
221
protected Version _minGitVersionConfigEnv = new Version ( 2 , 31 ) ;
222
222
223
+ // min git version that supports sparse checkout
224
+ protected Version _minGitVersionSupportSparseCheckout = new Version ( 2 , 25 ) ;
225
+
223
226
public abstract bool GitSupportUseAuthHeader ( AgentTaskPluginExecutionContext executionContext , GitCliManager gitCommandManager ) ;
224
227
public abstract bool GitLfsSupportUseAuthHeader ( AgentTaskPluginExecutionContext executionContext , GitCliManager gitCommandManager ) ;
225
228
public abstract void RequirementCheck ( AgentTaskPluginExecutionContext executionContext , Pipelines . RepositoryResource repository , GitCliManager gitCommandManager ) ;
@@ -704,22 +707,27 @@ public async Task GetSourceAsync(
704
707
// Sparse checkout needs to be before any `fetch` task to avoid fetching the excluded trees and blobs, or to not _not_ fetch them if we're disabling a previous sparse checkout.
705
708
if ( enableSparseCheckout )
706
709
{
710
+ gitCommandManager . EnsureGitVersion ( _minGitVersionSupportSparseCheckout , throwOnNotMatch : true ) ;
711
+
707
712
// Set up sparse checkout
708
713
int exitCode_sparseCheckout = await gitCommandManager . GitSparseCheckout ( executionContext , targetPath , sparseCheckoutDirectories , sparseCheckoutPatterns , cancellationToken ) ;
709
-
710
714
if ( exitCode_sparseCheckout != 0 )
711
715
{
712
716
throw new InvalidOperationException ( $ "Git sparse checkout failed with exit code: { exitCode_sparseCheckout } ") ;
713
717
}
714
718
}
715
719
else
716
720
{
717
- // Disable sparse checkout in case it was enabled in a previous checkout
718
- int exitCode_sparseCheckoutDisable = await gitCommandManager . GitSparseCheckoutDisable ( executionContext , targetPath , cancellationToken ) ;
719
-
720
- if ( exitCode_sparseCheckoutDisable != 0 )
721
+ // Only disable if git supports sparse checkout
722
+ if ( gitCommandManager . EnsureGitVersion ( _minGitVersionSupportSparseCheckout , throwOnNotMatch : false ) )
721
723
{
722
- throw new InvalidOperationException ( $ "Git sparse checkout disable failed with exit code: { exitCode_sparseCheckoutDisable } ") ;
724
+ // Disable sparse checkout in case it was enabled in a previous checkout
725
+ int exitCode_sparseCheckoutDisable = await gitCommandManager . GitSparseCheckoutDisable ( executionContext , targetPath , cancellationToken ) ;
726
+
727
+ if ( exitCode_sparseCheckoutDisable != 0 )
728
+ {
729
+ throw new InvalidOperationException ( $ "Git sparse checkout disable failed with exit code: { exitCode_sparseCheckoutDisable } ") ;
730
+ }
723
731
}
724
732
}
725
733
}
0 commit comments