From d92b1b416907d15ce060d89e0b5b53ba6beb7222 Mon Sep 17 00:00:00 2001 From: Semih Okur Date: Tue, 2 Dec 2025 00:17:33 -0800 Subject: [PATCH 1/3] Update the location of .autoManagedVhd marker file --- src/Agent.Plugins/GitSourceProvider.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Agent.Plugins/GitSourceProvider.cs b/src/Agent.Plugins/GitSourceProvider.cs index 03006a3714..d362514b84 100644 --- a/src/Agent.Plugins/GitSourceProvider.cs +++ b/src/Agent.Plugins/GitSourceProvider.cs @@ -618,12 +618,15 @@ public async Task GetSourceAsync( } } - if (File.Exists(Path.Combine(targetPath, ".autoManagedVhd")) + if (Directory.GetParent(targetPath) is DirectoryInfo parent + && File.Exists(Path.Combine(parent.FullName, ".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 parent directory of the sources). + // 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. From 751e73047ac604211f096f7df01db3ce575d1813 Mon Sep 17 00:00:00 2001 From: Semih Okur Date: Tue, 2 Dec 2025 01:08:57 -0800 Subject: [PATCH 2/3] Address feedback --- src/Agent.Plugins/GitSourceProvider.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Agent.Plugins/GitSourceProvider.cs b/src/Agent.Plugins/GitSourceProvider.cs index d362514b84..56fc228d91 100644 --- a/src/Agent.Plugins/GitSourceProvider.cs +++ b/src/Agent.Plugins/GitSourceProvider.cs @@ -618,12 +618,13 @@ public async Task GetSourceAsync( } } - if (Directory.GetParent(targetPath) is DirectoryInfo parent - && File.Exists(Path.Combine(parent.FullName, ".autoManagedVhd")) + string agentWorkFolder = Environment.GetEnvironmentVariable("AGENT_WORKFOLDER"); + if (!string.IsNullOrEmpty(agentWorkFolder) + && File.Exists(Path.Combine(agentWorkFolder, ".autoManagedVhd")) && !AgentKnobs.DisableAutoManagedVhdShallowOverride.GetValue(executionContext).AsBoolean()) { // The existing working directory comes from an AutoManagedVHD (indicated by the - // .autoManagedVhd marker file placed in the parent directory of the sources). + // .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. From 98435e337a794d03f78017c51f2cb538feebeacf Mon Sep 17 00:00:00 2001 From: Semih Okur Date: Tue, 2 Dec 2025 01:19:36 -0800 Subject: [PATCH 3/3] Use executionContext.Variables --- src/Agent.Plugins/GitSourceProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Agent.Plugins/GitSourceProvider.cs b/src/Agent.Plugins/GitSourceProvider.cs index 56fc228d91..326f9b9143 100644 --- a/src/Agent.Plugins/GitSourceProvider.cs +++ b/src/Agent.Plugins/GitSourceProvider.cs @@ -618,7 +618,7 @@ public async Task GetSourceAsync( } } - string agentWorkFolder = Environment.GetEnvironmentVariable("AGENT_WORKFOLDER"); + string agentWorkFolder = executionContext.Variables.GetValueOrDefault("agent.workfolder")?.Value; if (!string.IsNullOrEmpty(agentWorkFolder) && File.Exists(Path.Combine(agentWorkFolder, ".autoManagedVhd")) && !AgentKnobs.DisableAutoManagedVhdShallowOverride.GetValue(executionContext).AsBoolean())