Skip to content

Commit ee05ba2

Browse files
Add fetchFilter option to the git submodules (#5518)
* add fetchfilter option to the git submodules * add fearure flag * minor chnage
1 parent ba213e1 commit ee05ba2

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/Agent.Plugins/GitCliManager.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,19 @@ public async Task<int> GitSubmoduleReset(AgentTaskPluginExecutionContext context
447447
}
448448

449449
// git submodule update --init --force [--depth=15] [--recursive]
450-
public async Task<int> GitSubmoduleUpdate(AgentTaskPluginExecutionContext context, string repositoryPath, int fetchDepth, string additionalCommandLine, bool recursive, CancellationToken cancellationToken)
450+
public async Task<int> GitSubmoduleUpdate(AgentTaskPluginExecutionContext context, string repositoryPath, int fetchDepth, IEnumerable<string> filters, string additionalCommandLine, bool recursive, CancellationToken cancellationToken)
451451
{
452452
context.Debug("Update the registered git submodules.");
453453
string options = "update --init --force";
454454
if (fetchDepth > 0)
455455
{
456456
options = options + $" --depth={fetchDepth}";
457457
}
458+
if (AgentKnobs.UseFetchFilterInGitSubmoduleUpdate.GetValue(context).AsBoolean() && filters != null)
459+
{
460+
options += " " + string.Join(" ", filters.Select(f => "--filter=" + f));
461+
}
462+
458463
if (recursive)
459464
{
460465
options = options + " --recursive";

src/Agent.Plugins/GitSourceProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ public async Task GetSourceAsync(
12001200
}
12011201
}
12021202

1203-
int exitCode_submoduleUpdate = await gitCommandManager.GitSubmoduleUpdate(executionContext, targetPath, fetchDepth, string.Join(" ", additionalSubmoduleUpdateArgs), checkoutNestedSubmodules, cancellationToken);
1203+
int exitCode_submoduleUpdate = await gitCommandManager.GitSubmoduleUpdate(executionContext, targetPath, fetchDepth, additionalFetchFilterOptions, string.Join(" ", additionalSubmoduleUpdateArgs), checkoutNestedSubmodules, cancellationToken);
12041204
if (exitCode_submoduleUpdate != 0)
12051205
{
12061206
throw new InvalidOperationException($"Git submodule update failed with exit code: {exitCode_submoduleUpdate}");

src/Agent.Sdk/Knob/AgentKnobs.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,14 @@ public class AgentKnobs
811811
new RuntimeKnobSource("AGENT_USE_FETCH_FILTER_IN_CHECKOUT_TASK"),
812812
new BuiltInDefaultKnobSource("false"));
813813

814+
public static readonly Knob UseFetchFilterInGitSubmoduleUpdate = new Knob(
815+
nameof(UseFetchFilterInGitSubmoduleUpdate),
816+
"If true, agent will pass fetch filter options in checkout task to git submodule update.",
817+
new PipelineFeatureSource("UseFetchFilterInGitSubmoduleUpdate"),
818+
new RuntimeKnobSource("AGENT_USE_FETCH_FILTER_IN_GIT_SUBMODULE_UPDATE"),
819+
new EnvironmentKnobSource("AGENT_USE_FETCH_FILTER_IN_GIT_SUBMODULE_UPDATE"),
820+
new BuiltInDefaultKnobSource("false"));
821+
814822
public static readonly Knob StoreAgentKeyInCSPContainer = new Knob(
815823
nameof(StoreAgentKeyInCSPContainer),
816824
"Store agent key in named container (Windows).",

0 commit comments

Comments
 (0)