diff --git a/src/shared/Core/Authentication/AuthenticationBase.cs b/src/shared/Core/Authentication/AuthenticationBase.cs
index 03e4d8ca6..6ecc53091 100644
--- a/src/shared/Core/Authentication/AuthenticationBase.cs
+++ b/src/shared/Core/Authentication/AuthenticationBase.cs
@@ -90,6 +90,11 @@ protected void ThrowIfUserInteractionDisabled()
{
if (!Context.Settings.IsInteractionAllowed)
{
+ if (Context.Settings.SilentExit)
+ {
+ Environment.Exit(0);
+ }
+
string envName = Constants.EnvironmentVariables.GcmInteractive;
string cfgName = string.Format("{0}.{1}",
Constants.GitConfiguration.Credential.SectionName,
@@ -104,6 +109,11 @@ protected void ThrowIfGuiPromptsDisabled()
{
if (!Context.Settings.IsGuiPromptsEnabled)
{
+ if (Context.Settings.SilentExit)
+ {
+ Environment.Exit(0);
+ }
+
Context.Trace.WriteLine($"{Constants.EnvironmentVariables.GitTerminalPrompts} is 0; GUI prompts have been disabled.");
throw new Trace2InvalidOperationException(Context.Trace2, "Cannot show prompt because GUI prompts have been disabled.");
}
@@ -113,6 +123,11 @@ protected void ThrowIfTerminalPromptsDisabled()
{
if (!Context.Settings.IsTerminalPromptsEnabled)
{
+ if (Context.Settings.SilentExit)
+ {
+ Environment.Exit(0);
+ }
+
Context.Trace.WriteLine($"{Constants.EnvironmentVariables.GitTerminalPrompts} is 0; terminal prompts have been disabled.");
throw new Trace2InvalidOperationException(Context.Trace2, "Cannot prompt because terminal prompts have been disabled.");
}
@@ -122,6 +137,11 @@ protected void ThrowIfWindowCancelled(WindowViewModel viewModel)
{
if (!viewModel.WindowResult)
{
+ if (Context.Settings.SilentExit)
+ {
+ Environment.Exit(0);
+ }
+
throw new Exception("User cancelled dialog.");
}
}
diff --git a/src/shared/Core/Settings.cs b/src/shared/Core/Settings.cs
index 2aa71edf4..410558856 100644
--- a/src/shared/Core/Settings.cs
+++ b/src/shared/Core/Settings.cs
@@ -82,6 +82,11 @@ public interface ISettings : IDisposable
///
bool IsInteractionAllowed { get; }
+ ///
+ /// Whether to exit silently with status 0 in cases such interaction not allowed and terminal prompts disabled.
+ ///
+ bool SilentExit { get; }
+
///
/// Get if tracing has been enabled, returning trace setting value in the out parameter.
///
@@ -558,6 +563,9 @@ public bool IsInteractionAllowed
}
}
+ public bool SilentExit =>
+ !TryGetSetting("GCM_SILENT_EXIT", GitCredCfg.SectionName, "silentExit", out string value) || value.ToBooleanyOrDefault(false);
+
public bool GetTracingEnabled(out string value) =>
TryGetSetting(KnownEnvars.GcmTrace,
KnownGitCfg.Credential.SectionName,
diff --git a/src/shared/TestInfrastructure/Objects/TestSettings.cs b/src/shared/TestInfrastructure/Objects/TestSettings.cs
index f14bf6cc9..91ea0d86d 100644
--- a/src/shared/TestInfrastructure/Objects/TestSettings.cs
+++ b/src/shared/TestInfrastructure/Objects/TestSettings.cs
@@ -17,6 +17,8 @@ public class TestSettings : ISettings
public bool IsInteractionAllowed { get; set; } = true;
+ public bool SilentExit {get; } = false;
+
public string Trace { get; set; }
public bool IsSecretTracingEnabled { get; set; }