diff --git a/src/Agent.Plugins/GitSourceProvider.cs b/src/Agent.Plugins/GitSourceProvider.cs index 03006a3714..326f9b9143 100644 --- a/src/Agent.Plugins/GitSourceProvider.cs +++ b/src/Agent.Plugins/GitSourceProvider.cs @@ -618,12 +618,16 @@ public async Task GetSourceAsync( } } - if (File.Exists(Path.Combine(targetPath, ".autoManagedVhd")) + string agentWorkFolder = executionContext.Variables.GetValueOrDefault("agent.workfolder")?.Value; + if (!string.IsNullOrEmpty(agentWorkFolder) + && File.Exists(Path.Combine(agentWorkFolder, ".autoManagedVhd")) && !AgentKnobs.DisableAutoManagedVhdShallowOverride.GetValue(executionContext).AsBoolean()) { - // 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. + // The existing working directory comes from an AutoManagedVHD (indicated by the + // .autoManagedVhd marker file placed in the agent work folder). + // An AutoManagedVHD always contains a full, non-shallow clone of the repository. + // Some pipelines enable shallow fetch parameters (e.g., fetchDepth > 0). However, + // 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.