public void DoNotThrowWhenWorkingAndRepoPathsAreSame() { this.workingPath = DefaultRepoPath; var sp = GetServiceProvider(this.gitVersionOptions); this.configFileLocator = sp.GetRequiredService <IConfigFileLocator>(); this.fileSystem = sp.GetRequiredService <IFileSystem>(); SetupConfigFileContent(string.Empty, path: this.workingPath); Should.NotThrow(() => this.configFileLocator.Verify(this.workingPath, this.repoPath)); }
public void DoNotThrowWhenWorkingAndRepoPathsAreSame_WithDifferentCasing() { workingPath = DefaultRepoPath.ToLower(); var sp = GetServiceProvider(gitVersionOptions); configFileLocator = sp.GetService <IConfigFileLocator>(); fileSystem = sp.GetService <IFileSystem>(); SetupConfigFileContent(string.Empty, path: workingPath); Should.NotThrow(() => { configFileLocator.Verify(workingPath, repoPath); }); }
public ConfigProvider(IConfigTargetProvider targetProvider, string configBaseDir, IConfigFileReader configFileReader = null, IConfigFileLocator configFileLocator = null) { baseDir = configBaseDir; targets = targetProvider.GetTargetsSequence().Select(t => t.ToLower().Trim()); configurations = new ConcurrentDictionary <Type, object>(); metadatas = new ConcurrentDictionary <string, ConfigFileMetadata>(); configLoaded = false; this.configFileLocator = configFileLocator ?? new ConfigFileLocator(baseDir); this.configFileReader = configFileReader ?? new ConfigFileReader(); }
public void DoNotThrowWhenWorkingAndRepoPathsAreSame() { workingPath = DefaultRepoPath; var sp = GetServiceProvider(arguments); configFileLocator = sp.GetService <IConfigFileLocator>(); fileSystem = sp.GetService <IFileSystem>(); SetupConfigFileContent(string.Empty, path: workingPath); Should.NotThrow(() => { configFileLocator.Verify(workingPath, repoPath); }); }
public GitVersionExecutor(ILog log, IConsole console, IConfigFileLocator configFileLocator, IConfigProvider configProvider, IGitVersionTool gitVersionTool, IVersionWriter versionWriter, IHelpWriter helpWriter) { this.log = log ?? throw new ArgumentNullException(nameof(log)); this.console = console ?? throw new ArgumentNullException(nameof(console)); this.configFileLocator = configFileLocator ?? throw new ArgumentNullException(nameof(configFileLocator)); this.configProvider = configProvider ?? throw new ArgumentNullException(nameof(configFileLocator)); this.gitVersionTool = gitVersionTool ?? throw new ArgumentNullException(nameof(gitVersionTool)); this.versionWriter = versionWriter ?? throw new ArgumentNullException(nameof(versionWriter)); this.helpWriter = helpWriter ?? throw new ArgumentNullException(nameof(helpWriter)); }
public void ThrowsExceptionOnCustomYmlFileDoesNotExist() { var sp = GetServiceProvider(arguments); configFileLocator = sp.GetService <IConfigFileLocator>(); var exception = Should.Throw <WarningException>(() => { configFileLocator.Verify(workingPath, repoPath); }); var workingPathFileConfig = Path.Combine(workingPath, arguments.ConfigFile); var repoPathFileConfig = Path.Combine(repoPath, arguments.ConfigFile); var expectedMessage = $"The configuration file was not found at '{workingPathFileConfig}' or '{repoPathFileConfig}'"; exception.Message.ShouldBe(expectedMessage); }
public void ThrowsExceptionOnCustomYmlFileDoesNotExist() { var sp = GetServiceProvider(this.gitVersionOptions); this.configFileLocator = sp.GetService <IConfigFileLocator>(); var exception = Should.Throw <WarningException>(() => this.configFileLocator.Verify(this.workingPath, this.repoPath)); var workingPathFileConfig = Path.Combine(this.workingPath, this.gitVersionOptions.ConfigInfo.ConfigFile); var repoPathFileConfig = Path.Combine(this.repoPath, this.gitVersionOptions.ConfigInfo.ConfigFile); var expectedMessage = $"The configuration file was not found at '{workingPathFileConfig}' or '{repoPathFileConfig}'"; exception.Message.ShouldBe(expectedMessage); }
public void SetUp() { fileSystem = new FileSystem(); environment = new TestEnvironment(); log = new NullLog(); configFileLocator = new DefaultConfigFileLocator(fileSystem, log); buildServerResolver = new BuildServerResolver(null, log); gitVersionCache = new GitVersionCache(fileSystem, log); metaDataCalculator = new MetaDataCalculator(); var baseVersionCalculator = new TestBaseVersionStrategiesCalculator(log); var mainlineVersionCalculator = new MainlineVersionCalculator(log, metaDataCalculator); var nextVersionCalculator = new NextVersionCalculator(log, metaDataCalculator, baseVersionCalculator, mainlineVersionCalculator); gitVersionFinder = new GitVersionFinder(log, nextVersionCalculator); }
public void ThrowsExceptionOnAmbiguousConfigFileLocation() { var sp = GetServiceProvider(this.gitVersionOptions); this.configFileLocator = sp.GetRequiredService <IConfigFileLocator>(); this.fileSystem = sp.GetRequiredService <IFileSystem>(); var repositoryConfigFilePath = SetupConfigFileContent(string.Empty, path: this.repoPath); var workingDirectoryConfigFilePath = SetupConfigFileContent(string.Empty, path: this.workingPath); var exception = Should.Throw <WarningException>(() => this.configFileLocator.Verify(this.workingPath, this.repoPath)); var expectedMessage = $"Ambiguous config file selection from '{workingDirectoryConfigFilePath}' and '{repositoryConfigFilePath}'"; exception.Message.ShouldBe(expectedMessage); }
public static Config Provide(string workingDirectory, IConfigFileLocator configFileLocator, bool applyDefaults = true, Config overrideConfig = null) { var readConfig = configFileLocator.ReadConfig(workingDirectory); VerifyConfiguration(readConfig); if (applyDefaults) { ApplyDefaultsTo(readConfig); } if (null != overrideConfig) { ApplyOverridesTo(readConfig, overrideConfig); } return(readConfig); }
public void DoNotThrowWhenConfigFileIsInSubDirectoryOfRepoPath() { workingPath = DefaultRepoPath; arguments = new Arguments { ConfigFile = "./src/my-config.yaml" }; var sp = GetServiceProvider(arguments); configFileLocator = sp.GetService <IConfigFileLocator>(); fileSystem = sp.GetService <IFileSystem>(); SetupConfigFileContent(string.Empty, path: workingPath); Should.NotThrow(() => { configFileLocator.Verify(workingPath, repoPath); }); }
public GitVersionExecutor(ILog log, IConfigFileLocator configFileLocator, IConfigProvider configProvider, IBuildServerResolver buildServerResolver, IGitPreparer gitPreparer, IGitVersionCalculator gitVersionCalculator, IVersionWriter versionWriter, IHelpWriter helpWriter, IExecCommand execCommand) { this.log = log ?? throw new ArgumentNullException(nameof(log)); this.configFileLocator = configFileLocator ?? throw new ArgumentNullException(nameof(configFileLocator)); this.configProvider = configProvider ?? throw new ArgumentNullException(nameof(configFileLocator)); this.buildServerResolver = buildServerResolver ?? throw new ArgumentNullException(nameof(buildServerResolver)); this.gitPreparer = gitPreparer ?? throw new ArgumentNullException(nameof(gitPreparer)); this.gitVersionCalculator = gitVersionCalculator ?? throw new ArgumentNullException(nameof(gitVersionCalculator)); this.versionWriter = versionWriter ?? throw new ArgumentNullException(nameof(versionWriter)); this.helpWriter = helpWriter ?? throw new ArgumentNullException(nameof(helpWriter)); this.execCommand = execCommand ?? throw new ArgumentNullException(nameof(execCommand)); }
public void DoNotThrowWhenConfigFileIsInSubDirectoryOfRepoPath() { this.workingPath = DefaultRepoPath; this.gitVersionOptions = new GitVersionOptions { ConfigInfo = { ConfigFile = "./src/my-config.yaml" } }; var sp = GetServiceProvider(this.gitVersionOptions); this.configFileLocator = sp.GetService <IConfigFileLocator>(); this.fileSystem = sp.GetService <IFileSystem>(); SetupConfigFileContent(string.Empty, path: this.workingPath); Should.NotThrow(() => this.configFileLocator.Verify(this.workingPath, this.repoPath)); }
public void Setup() { this.repoPath = DefaultRepoPath; this.workingPath = DefaultWorkingPath; var options = Options.Create(new GitVersionOptions { WorkingDirectory = repoPath }); var sp = ConfigureServices(services => services.AddSingleton(options)); this.fileSystem = sp.GetService <IFileSystem>(); this.configurationProvider = sp.GetService <IConfigProvider>(); this.configFileLocator = sp.GetService <IConfigFileLocator>(); ShouldlyConfiguration.ShouldMatchApprovedDefaults.LocateTestMethodUsingAttribute <TestAttribute>(); }
public GitVersionCalculator(IFileSystem fileSystem, ILog log, IConfigFileLocator configFileLocator, IConfigProvider configProvider, IBuildServerResolver buildServerResolver, IGitVersionCache gitVersionCache, IGitVersionFinder gitVersionFinder, IGitPreparer gitPreparer, IVariableProvider variableProvider, IOptions <Arguments> options) { this.fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); this.log = log ?? throw new ArgumentNullException(nameof(log)); this.configFileLocator = configFileLocator ?? throw new ArgumentNullException(nameof(configFileLocator)); this.configProvider = configProvider ?? throw new ArgumentNullException(nameof(configProvider)); this.buildServerResolver = buildServerResolver ?? throw new ArgumentNullException(nameof(buildServerResolver)); this.gitVersionCache = gitVersionCache ?? throw new ArgumentNullException(nameof(gitVersionCache)); this.gitVersionFinder = gitVersionFinder ?? throw new ArgumentNullException(nameof(gitVersionFinder)); this.gitPreparer = gitPreparer ?? throw new ArgumentNullException(nameof(gitPreparer)); this.variableProvider = variableProvider ?? throw new ArgumentNullException(nameof(variableProvider)); this.arguments = options.Value; }
public void ThrowsExceptionOnAmbiguousConfigFileLocation() { var sp = GetServiceProvider(arguments); configFileLocator = sp.GetService <IConfigFileLocator>(); fileSystem = sp.GetService <IFileSystem>(); var repositoryConfigFilePath = SetupConfigFileContent(string.Empty, path: repoPath); var workingDirectoryConfigFilePath = SetupConfigFileContent(string.Empty, path: workingPath); var exception = Should.Throw <WarningException>(() => { configFileLocator.Verify(workingPath, repoPath); }); var expectedMessage = $"Ambiguous config file selection from '{workingDirectoryConfigFilePath}' and '{repositoryConfigFilePath}'"; exception.Message.ShouldBe(expectedMessage); }
public GitVersionExecutor(ILog log, IConsole console, IConfigFileLocator configFileLocator, IConfigProvider configProvider, IGitVersionCalculateTool gitVersionCalculateTool, IGitVersionOutputTool gitVersionOutputTool, IVersionWriter versionWriter, IHelpWriter helpWriter, IGitRepositoryInfo repositoryInfo) { this.log = log ?? throw new ArgumentNullException(nameof(log)); this.console = console ?? throw new ArgumentNullException(nameof(console)); this.configFileLocator = configFileLocator ?? throw new ArgumentNullException(nameof(configFileLocator)); this.configProvider = configProvider ?? throw new ArgumentNullException(nameof(configFileLocator)); this.gitVersionCalculateTool = gitVersionCalculateTool ?? throw new ArgumentNullException(nameof(gitVersionCalculateTool)); this.gitVersionOutputTool = gitVersionOutputTool ?? throw new ArgumentNullException(nameof(gitVersionOutputTool)); this.versionWriter = versionWriter ?? throw new ArgumentNullException(nameof(versionWriter)); this.helpWriter = helpWriter ?? throw new ArgumentNullException(nameof(helpWriter)); this.repositoryInfo = repositoryInfo ?? throw new ArgumentNullException(nameof(repositoryInfo)); }
public GitVersionExecutor(ILog log, IConsole console, IConfigFileLocator configFileLocator, IConfigProvider configProvider, IGitVersionCalculateTool gitVersionCalculateTool, IGitVersionOutputTool gitVersionOutputTool, IVersionWriter versionWriter, IHelpWriter helpWriter, IGitRepositoryInfo repositoryInfo) { this.log = log.NotNull(); this.console = console.NotNull(); this.configFileLocator = configFileLocator.NotNull(); this.configProvider = configProvider.NotNull(); this.gitVersionCalculateTool = gitVersionCalculateTool.NotNull(); this.gitVersionOutputTool = gitVersionOutputTool.NotNull(); this.versionWriter = versionWriter.NotNull(); this.helpWriter = helpWriter.NotNull(); this.repositoryInfo = repositoryInfo.NotNull(); }
public void Setup() { repoPath = DefaultRepoPath; workingPath = DefaultWorkingPath; var options = Options.Create(new Arguments { TargetPath = repoPath }); var sp = ConfigureServices(services => { services.AddSingleton(options); }); fileSystem = sp.GetService <IFileSystem>(); configurationProvider = sp.GetService <IConfigProvider>(); configFileLocator = sp.GetService <IConfigFileLocator>(); ShouldlyConfiguration.ShouldMatchApprovedDefaults.LocateTestMethodUsingAttribute <TestAttribute>(); }
public void NoWarnOnCustomYmlFile() { var stringLogger = string.Empty; void Action(string info) => stringLogger = info; var logAppender = new TestLogAppender(Action); var log = new Log(logAppender); var sp = GetServiceProvider(gitVersionOptions, log); configFileLocator = sp.GetService <IConfigFileLocator>(); fileSystem = sp.GetService <IFileSystem>(); SetupConfigFileContent(string.Empty); var configurationProvider = sp.GetService <IConfigProvider>(); configurationProvider.Provide(repoPath); stringLogger.Length.ShouldBe(0); }
public void Setup() { fileSystem = new TestFileSystem(); var log = new NullLog(); environment = new TestEnvironment(); var stepFactory = new ConfigInitStepFactory(); configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory); configFileLocator = new DefaultConfigFileLocator(fileSystem, log); repoPath = DefaultRepoPath; var gitPreparer = new GitPreparer(log, environment, Options.Create(new Arguments { TargetPath = repoPath })); configProvider = new ConfigProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard); ShouldlyConfiguration.ShouldMatchApprovedDefaults.LocateTestMethodUsingAttribute <TestAttribute>(); }
public void NoWarnOnCustomYmlFileOutsideRepoPath() { var stringLogger = string.Empty; void Action(string info) => stringLogger = info; var logAppender = new TestLogAppender(Action); var log = new Log(logAppender); var sp = GetServiceProvider(arguments, log); configFileLocator = sp.GetService <IConfigFileLocator>(); fileSystem = sp.GetService <IFileSystem>(); SetupConfigFileContent(string.Empty, path: @"c:\\Unrelated\\path"); var configurationProvider = sp.GetService <IConfigProvider>(); configurationProvider.Provide(repoPath); stringLogger.Length.ShouldBe(0); }
public void CacheKeySameAfterReNormalizing() { RepositoryScope((fixture, vv) => { var targetUrl = "https://github.com/GitTools/GitVersion.git"; var targetBranch = "refs/head/master"; var arguments = new Arguments { TargetUrl = targetUrl, TargetPath = fixture.RepositoryPath }; var gitPreparer = new GitPreparer(log, environment, Options.Create(arguments)); configFileLocator = new DefaultConfigFileLocator(fileSystem, log); gitPreparer.Prepare(true, targetBranch); var cacheKey1 = GitVersionCacheKeyFactory.Create(fileSystem, log, gitPreparer, configFileLocator, null); gitPreparer.Prepare(true, targetBranch); var cacheKey2 = GitVersionCacheKeyFactory.Create(fileSystem, log, gitPreparer, configFileLocator, null); cacheKey2.Value.ShouldBe(cacheKey1.Value); }); }
public GitVersionCacheKeyFactory(IFileSystem fileSystem, ILog log, IGitPreparer gitPreparer, IConfigFileLocator configFileLocator) { this.fileSystem = fileSystem; this.log = log; this.gitPreparer = gitPreparer; this.configFileLocator = configFileLocator; }
public ConfigProvider(IConfigTargetProvider targetProvider, IConfigFileLocator configFileLocator, IConfigFileReader configFileReader = null) : this(targetProvider, null, configFileLocator, configFileReader) { }
public GitVersionApplication(IFileSystem fileSystem, IEnvironment environment, ILog log, IConfigFileLocator configFileLocator) { this.fileSystem = fileSystem; this.environment = environment; this.log = log; this.configFileLocator = configFileLocator; versionWriter = new VersionWriter(); helpWriter = new HelpWriter(versionWriter); }
private static string GetConfigFileHash(IFileSystem fileSystem, IGitPreparer gitPreparer, IConfigFileLocator configFileLocator) { // will return the same hash even when config file will be moved // from workingDirectory to rootProjectDirectory. It's OK. Config essentially is the same. var configFilePath = configFileLocator.SelectConfigFilePath(gitPreparer); if (!fileSystem.Exists(configFilePath)) { return(string.Empty); } var configFileContent = fileSystem.ReadAllText(configFilePath); return(GetHash(configFileContent)); }
public static GitVersionCacheKey Create(IFileSystem fileSystem, ILog log, IGitPreparer gitPreparer, IConfigFileLocator configFileLocator, Config overrideConfig) { var gitSystemHash = GetGitSystemHash(gitPreparer, log); var configFileHash = GetConfigFileHash(fileSystem, gitPreparer, configFileLocator); var repositorySnapshotHash = GetRepositorySnapshotHash(gitPreparer); var overrideConfigHash = GetOverrideConfigHash(overrideConfig); var compositeHash = GetHash(gitSystemHash, configFileHash, repositorySnapshotHash, overrideConfigHash); return(new GitVersionCacheKey(compositeHash)); }
public GitVersionCacheKeyFactory(IFileSystem fileSystem, ILog log, IOptions <GitVersionOptions> options, IConfigFileLocator configFileLocator) { this.fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); this.log = log ?? throw new ArgumentNullException(nameof(log)); this.options = options ?? throw new ArgumentNullException(nameof(options)); this.configFileLocator = configFileLocator ?? throw new ArgumentNullException(nameof(configFileLocator)); }
public void Execute(Arguments arguments, IFileSystem fileSystem, IEnvironment environment, ILog log, IConfigFileLocator configFileLocator) { log.Info($"Running on {(runningOnUnix ? "Unix" : "Windows")}."); var noFetch = arguments.NoFetch; var authentication = arguments.Authentication; var targetPath = arguments.TargetPath; var targetUrl = arguments.TargetUrl; var dynamicRepositoryLocation = arguments.DynamicRepositoryLocation; var targetBranch = arguments.TargetBranch; var commitId = arguments.CommitId; var overrideConfig = arguments.HasOverrideConfig ? arguments.OverrideConfig : null; var noCache = arguments.NoCache; var noNormalize = arguments.NoNormalize; var executeCore = new ExecuteCore(fileSystem, environment, log, configFileLocator); var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig, noCache, noNormalize); switch (arguments.Output) { case OutputType.BuildServer: { BuildServerList.Init(environment, log); foreach (var buildServer in BuildServerList.GetApplicableBuildServers(log)) { buildServer.WriteIntegration(Console.WriteLine, variables); } break; } case OutputType.Json: switch (arguments.ShowVariable) { case null: Console.WriteLine(JsonOutputFormatter.ToJson(variables)); break; default: if (!variables.TryGetValue(arguments.ShowVariable, out var part)) { throw new WarningException($"'{arguments.ShowVariable}' variable does not exist"); } Console.WriteLine(part); break; } break; default: throw new ArgumentOutOfRangeException(); } if (arguments.UpdateWixVersionFile) { using (var wixVersionFileUpdater = new WixVersionFileUpdater(targetPath, variables, fileSystem, log)) { wixVersionFileUpdater.Update(); } } using (var assemblyInfoUpdater = new AssemblyInfoFileUpdater(arguments.UpdateAssemblyInfoFileName, targetPath, variables, fileSystem, log, arguments.EnsureAssemblyInfo)) { if (arguments.UpdateAssemblyInfo) { assemblyInfoUpdater.Update(); } var execRun = RunExecCommandIfNeeded(arguments, targetPath, variables, log); var msbuildRun = RunMsBuildIfNeeded(arguments, targetPath, variables, log); if (!execRun && !msbuildRun) { assemblyInfoUpdater.CommitChanges(); //TODO Put warning back //if (!context.CurrentBuildServer.IsRunningInBuildAgent()) //{ // Console.WriteLine("WARNING: Not running in build server and /ProjectFile or /Exec arguments not passed"); // Console.WriteLine(); // Console.WriteLine("Run GitVersion.exe /? for help"); //} } } }