Skip to content
Open
Changes from 1 commit
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
24 changes: 24 additions & 0 deletions src/Agent.Plugins/GitSourceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,30 @@ public async Task GetSourceAsync(
}
}

if (File.Exists(Path.Combine(targetPath, ".autoManagedVhd")))
{
// The existing working directory comes from an auto-managed VHD and is a full,
// non-shallow clone of the repository. Some pipelines enable shallow fetch, but
// Git cannot convert an existing full clone into a shallow one in-place.
//
// Technical reason:
// A full clone already has complete commit history and object reachability.
// When a fetch is issued with a non-zero --depth against a full clone, Git
// does *not* rewrite the local history to match the requested shallow boundary.
// Instead, to honor the depth constraint, Git falls back to creating a brand-new
// shallow clone in an empty directory.
//
// That behavior causes the agent to discard the VHD-provided clone and re-clone
// from scratch—defeating the whole purpose of using AutoManagedVHDs for fast sync.
//
// To avoid this, force a normal full fetch by disabling shallow behavior:
// clean = false → preserve the VHD clone
// fetchDepth = 0 → perform a standard "sync" fetch
clean = false;
fetchDepth = 0;
executionContext.Debug($"Detected an auto-managed VHD at {targetPath}. Setting clean to false and fetchDepth to 0.");
}

// When repo.clean is selected for a git repo, execute git clean -ffdx and git reset --hard HEAD on the current repo.
// This will help us save the time to reclone the entire repo.
// If any git commands exit with non-zero return code or any exception happened during git.exe invoke, fall back to delete the repo folder.
Expand Down
Loading