Skip to content

Commit 80dd37c

Browse files
Add FetchByCommitForFullClone knob to enable fetch by commit for full clones (#5276)
* Add FetchByCommitForFullClone knob to enable fetch by commit for full clones * Log shouldFetchByCommit --------- Co-authored-by: Semih Okur <seokur@microsoft.com>
1 parent 6a547a3 commit 80dd37c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/Agent.Plugins/GitSourceProvider.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,11 +937,18 @@ public async Task GetSourceAsync(
937937
executionContext.Debug($"sourceVersion : {sourceVersion}");
938938
executionContext.Debug($"fetchTags : {fetchTags}");
939939

940+
// Determine if we should use fetch by commit based on shallow vs full clone scenarios
941+
bool shouldFetchByCommit = fetchByCommit && !string.IsNullOrEmpty(sourceVersion) &&
942+
(fetchDepth > 0 || AgentKnobs.FetchByCommitForFullClone.GetValue(executionContext).AsBoolean());
943+
944+
executionContext.Debug($"shouldFetchByCommit : {shouldFetchByCommit}");
945+
940946
if (IsPullRequest(sourceBranch))
941947
{
942948
// Build a 'fetch-by-commit' refspec iff the server allows us to do so in the shallow fetch scenario
949+
// or if it's a full clone and the FetchByCommitForFullClone knob is enabled
943950
// Otherwise, fall back to fetch all branches and pull request ref
944-
if (fetchDepth > 0 && fetchByCommit && !string.IsNullOrEmpty(sourceVersion))
951+
if (shouldFetchByCommit)
945952
{
946953
refFetchedByCommit = $"{_remoteRefsPrefix}{sourceVersion}";
947954
additionalFetchSpecs.Add($"+{sourceVersion}:{refFetchedByCommit}");
@@ -955,8 +962,9 @@ public async Task GetSourceAsync(
955962
else
956963
{
957964
// Build a refspec iff the server allows us to fetch a specific commit in the shallow fetch scenario
965+
// or if it's a full clone and the FetchByCommitForFullClone knob is enabled
958966
// Otherwise, use the default fetch behavior (i.e. with no refspecs)
959-
if (fetchDepth > 0 && fetchByCommit && !string.IsNullOrEmpty(sourceVersion))
967+
if (shouldFetchByCommit)
960968
{
961969
refFetchedByCommit = $"{_remoteRefsPrefix}{sourceVersion}";
962970
additionalFetchSpecs.Add($"+{sourceVersion}:{refFetchedByCommit}");

src/Agent.Sdk/Knob/AgentKnobs.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ public class AgentKnobs
200200
new EnvironmentKnobSource("AGENT_USE_NODE20_IN_UNSUPPORTED_SYSTEM"),
201201
new BuiltInDefaultKnobSource("false"));
202202

203+
public static readonly Knob FetchByCommitForFullClone = new Knob(
204+
nameof(FetchByCommitForFullClone),
205+
"If true, allow fetch by commit when doing a full clone (depth=0).",
206+
new RuntimeKnobSource("VSTS.FetchByCommitForFullClone"),
207+
new EnvironmentKnobSource("VSTS_FETCHBYCOMMITFORFULLCLONE"),
208+
new BuiltInDefaultKnobSource("false"));
209+
203210
// Agent logging
204211
public static readonly Knob AgentPerflog = new Knob(
205212
nameof(AgentPerflog),

0 commit comments

Comments
 (0)