private static string GetScopeOption(GitConfigurationScope scope) { return(scope switch { GitConfigurationScope.Global => "--global", GitConfigurationScope.System => "--system", GitConfigurationScope.Unknown => throw new InvalidOperationException("Must specify valid scope"), _ => throw new ArgumentOutOfRangeException(nameof(scope), scope, "Unknown scope") });
public void AddConfig(string key, string value, GitConfigurationScope scope) { var args = new StringBuilder("config"); args.AppendFormat(" {0}", GetScopeOption(scope)); args.AppendFormat(" --add {0} {1}", QuoteArgument(key), QuoteArgument(value)); Process proc = this.CreateProcess(args); proc.Start(); proc.WaitForExit(); if (proc.ExitCode != 0) { throw new GitException("Failed to add configuration", proc.ExitCode); } }