예제 #1
0
        private void CreatePolicyFile(string path, Policy policy)
        {
            Console.Error.WriteLine("info: creating policy configuration file '{0}'", policy.Id);

            // Overwrite any existing file and include the auto-generated warning header
            // and policy description to the file
            var header = new StringBuilder(AutoGenFileHeader);

            if (!string.IsNullOrWhiteSpace(policy.Description))
            {
                header.AppendLine($"# Description: {policy.Description}");
                header.AppendLine("#");
            }
            _fs.WriteAllText(path, header.ToString());

            // Write out the configuration entries for this policy
            foreach (GitConfiguration config in policy.Configuration)
            {
                try
                {
                    _git.SetConfigInFile(config.Key, config.Value, path);
                }
                catch (GitException ex)
                {
                    Console.Error.WriteLine("error: failed to add configuration in policy file '{0}': {1} (exit={2})",
                                            policy.Id, ex.Message, ex.ExitCode);
                }
            }
        }