Пример #1
0
        public static string GetEffectiveConfigAsString(string gitDirectory, IFileSystem fileSystem)
        {
            var config        = Provide(gitDirectory, fileSystem);
            var stringBuilder = new StringBuilder();

            using (var stream = new StringWriter(stringBuilder))
            {
                ConfigSerialiser.Write(config, stream);
                stream.Flush();
            }
            return(stringBuilder.ToString());
        }
        static Config ReadConfig(string workingDirectory, IFileSystem fileSystem)
        {
            var configFilePath = GetConfigFilePath(workingDirectory, fileSystem);

            if (fileSystem.Exists(configFilePath))
            {
                var readAllText = fileSystem.ReadAllText(configFilePath);
                LegacyConfigNotifier.Notify(new StringReader(readAllText));
                return(ConfigSerialiser.Read(new StringReader(readAllText)));
            }

            return(new Config());
        }
        public static void WriteSample(string gitDirectory, IFileSystem fileSystem)
        {
            var configFilePath = GetConfigFilePath(gitDirectory);

            if (!fileSystem.Exists(configFilePath))
            {
                using (var stream = fileSystem.OpenWrite(configFilePath))
                    using (var writer = new StreamWriter(stream))
                    {
                        ConfigSerialiser.WriteSample(writer);
                    }
            }
            else
            {
                Logger.WriteError("Cannot write sample, GitVersionConfig.yaml already exists");
            }
        }
Пример #4
0
        public static void Init(string workingDirectory, IFileSystem fileSystem)
        {
            var configFilePath = GetConfigFilePath(workingDirectory);
            var config         = new ConfigInitWizard().Run(Provide(workingDirectory, fileSystem), workingDirectory, fileSystem);

            if (config == null)
            {
                return;
            }

            using (var stream = fileSystem.OpenWrite(configFilePath))
                using (var writer = new StreamWriter(stream))
                {
                    Logger.WriteInfo("Saving config file");
                    ConfigSerialiser.Write(config, writer);
                    stream.Flush();
                }
        }
        public static void Init(string workingDirectory, IFileSystem fileSystem, IConsole console)
        {
            var configFilePath       = GetConfigFilePath(workingDirectory, fileSystem);
            var currentConfiguration = Provide(workingDirectory, fileSystem, applyDefaults: false);
            var config = new ConfigInitWizard(console, fileSystem).Run(currentConfiguration, workingDirectory);

            if (config == null)
            {
                return;
            }

            using (var stream = fileSystem.OpenWrite(configFilePath))
                using (var writer = new StreamWriter(stream))
                {
                    Logger.WriteInfo("Saving config file");
                    ConfigSerialiser.Write(config, writer);
                    stream.Flush();
                }
        }
Пример #6
0
        private static string GetOverrideConfigHash(Config overrideConfig)
        {
            if (overrideConfig == null)
            {
                return(string.Empty);
            }

            // Doesn't depend on command line representation and
            // includes possible changes in default values of Config per se.
            var stringBuilder = new StringBuilder();

            using (var stream = new StringWriter(stringBuilder))
            {
                ConfigSerialiser.Write(overrideConfig, stream);
                stream.Flush();
            }
            var configContent = stringBuilder.ToString();

            return(GetHash(configContent));
        }