Skip to content
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

[Checkout] Configure sparse checkouts before fetch #5103

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions src/Agent.Plugins/GitSourceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,31 @@ public async Task GetSourceAsync(
}
}

if (AgentKnobs.UseSparseCheckoutInCheckoutTask.GetValue(executionContext).AsBoolean())
{
// 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.
if (enableSparseCheckout)
{
// Set up sparse checkout
int exitCode_sparseCheckout = await gitCommandManager.GitSparseCheckout(executionContext, targetPath, sparseCheckoutDirectories, sparseCheckoutPatterns, cancellationToken);

if (exitCode_sparseCheckout != 0)
{
throw new InvalidOperationException($"Git sparse checkout failed with exit code: {exitCode_sparseCheckout}");
}
}
else
{
// Disable sparse checkout in case it was enabled in a previous checkout
int exitCode_sparseCheckoutDisable = await gitCommandManager.GitSparseCheckoutDisable(executionContext, targetPath, cancellationToken);

if (exitCode_sparseCheckoutDisable != 0)
{
throw new InvalidOperationException($"Git sparse checkout disable failed with exit code: {exitCode_sparseCheckoutDisable}");
}
}
}

await RunGitStatusIfSystemDebug(executionContext, gitCommandManager, targetPath);

cancellationToken.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -974,30 +999,6 @@ public async Task GetSourceAsync(
}
}

if (AgentKnobs.UseSparseCheckoutInCheckoutTask.GetValue(executionContext).AsBoolean())
{
if (enableSparseCheckout)
{
// Set up sparse checkout
int exitCode_sparseCheckout = await gitCommandManager.GitSparseCheckout(executionContext, targetPath, sparseCheckoutDirectories, sparseCheckoutPatterns, cancellationToken);

if (exitCode_sparseCheckout != 0)
{
throw new InvalidOperationException($"Git sparse checkout failed with exit code: {exitCode_sparseCheckout}");
}
}
else
{
// Disable sparse checkout in case it was enabled in a previous checkout
int exitCode_sparseCheckoutDisable = await gitCommandManager.GitSparseCheckoutDisable(executionContext, targetPath, cancellationToken);

if (exitCode_sparseCheckoutDisable != 0)
{
throw new InvalidOperationException($"Git sparse checkout disable failed with exit code: {exitCode_sparseCheckoutDisable}");
}
}
}

// Finally, checkout the sourcesToBuild (if we didn't find a valid git object this will throw)
int exitCode_checkout = await gitCommandManager.GitCheckout(executionContext, targetPath, sourcesToBuild, string.Join(" ", additionalCheckoutArgs), cancellationToken);
if (exitCode_checkout != 0)
Expand Down
Loading