public void CanSetNextVersion() { ILog log = new NullLog(); IFileSystem fileSystem = new TestFileSystem(); IConsole testConsole = new TestConsole("3", "2.0.0", "0"); var serviceCollections = new ServiceCollection(); serviceCollections.AddModule(new GitVersionInitModule()); serviceCollections.AddSingleton(log); serviceCollections.AddSingleton(fileSystem); serviceCollections.AddSingleton(testConsole); var serviceProvider = serviceCollections.BuildServiceProvider(); var stepFactory = new ConfigInitStepFactory(serviceProvider); var configInitWizard = new ConfigInitWizard(testConsole, stepFactory); var configFileLocator = new DefaultConfigFileLocator(fileSystem, log); var workingDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "c:\\proj" : "/proj"; var gitPreparer = new GitPreparer(log, new TestEnvironment(), Options.Create(new Arguments { TargetPath = workingDirectory })); var configurationProvider = new ConfigProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard); configurationProvider.Init(workingDirectory); fileSystem.ReadAllText(Path.Combine(workingDirectory, "GitVersion.yml")).ShouldMatchApproved(); }
public void CacheKeyForWorktree() { var versionAndBranchFinder = new ExecuteCore(fileSystem, environment); RepositoryScope(versionAndBranchFinder, (fixture, vv) => { var worktreePath = Path.Combine(Directory.GetParent(fixture.RepositoryPath).FullName, Guid.NewGuid().ToString()); try { // create a branch and a new worktree for it var repo = new Repository(fixture.RepositoryPath); repo.Worktrees.Add("worktree", worktreePath, false); var targetUrl = "https://github.com/GitTools/GitVersion.git"; var gitPreparer = new GitPreparer(targetUrl, null, new Authentication(), false, worktreePath); var configFileLocator = new DefaultConfigFileLocator(); var cacheKey = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, null, configFileLocator); cacheKey.Value.ShouldNotBeEmpty(); } finally { DirectoryHelper.DeleteDirectory(worktreePath); } }); }
public void Setup() { fileSystem = new TestFileSystem(); configFileLocator = new DefaultConfigFileLocator(); repoPath = DefaultRepoPath; workingPath = DefaultWorkingPath; ShouldlyConfiguration.ShouldMatchApprovedDefaults.LocateTestMethodUsingAttribute <TestAttribute>(); }
public void CanSetNextVersion() { var testFileSystem = new TestFileSystem(); var testConsole = new TestConsole("3", "2.0.0", "0"); var configFileLocator = new DefaultConfigFileLocator(); ConfigurationProvider.Init("c:\\proj", testFileSystem, testConsole, configFileLocator); testFileSystem.ReadAllText("c:\\proj\\GitVersion.yml").ShouldMatchApproved(); }
public void CanSetNextVersion() { var testFileSystem = new TestFileSystem(); var testConsole = new TestConsole("3", "2.0.0", "0"); var configFileLocator = new DefaultConfigFileLocator(); var workingDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "c:\\proj" : "/proj"; ConfigurationProvider.Init(workingDirectory, testFileSystem, testConsole, configFileLocator); testFileSystem.ReadAllText(Path.Combine(workingDirectory, "GitVersion.yml")).ShouldMatchApproved(); }
private string WithDefaultConfigFileLocator(Action <IConfigFileLocator> action) { var stringLogger = string.Empty; void Action(string info) => stringLogger = info; var logAppender = new TestLogAppender(Action); var log = new Log(logAppender); var configFileLocator = new DefaultConfigFileLocator(fileSystem, log); action(configFileLocator); return(stringLogger); }
public void NoWarnOnGitVersionYmlFile() { SetupConfigFileContent(string.Empty); var stringLogger = string.Empty; void Action(string info) => stringLogger = info; var logAppender = new TestLogAppender(Action); var log = new Log(logAppender); var defaultConfigFileLocator = new DefaultConfigFileLocator(fileSystem, log); ConfigurationProvider.Provide(repoPath, defaultConfigFileLocator); stringLogger.Length.ShouldBe(0); }
public void CacheKeySameAfterReNormalizing() { var versionAndBranchFinder = new ExecuteCore(fileSystem); RepositoryScope(versionAndBranchFinder, (fixture, vv) => { var targetUrl = "https://github.com/GitTools/GitVersion.git"; var targetBranch = "refs/head/master"; var gitPreparer = new GitPreparer(targetUrl, null, new Authentication(), false, fixture.RepositoryPath); var configFileLocator = new DefaultConfigFileLocator(); gitPreparer.Initialise(true, targetBranch); var cacheKey1 = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, null, configFileLocator); gitPreparer.Initialise(true, targetBranch); var cacheKey2 = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, null, configFileLocator); cacheKey2.Value.ShouldBe(cacheKey1.Value); }); }
public void FindsVersionInDynamicRepo(string name, string url, string targetBranch, string commitId, string expectedFullSemVer) { var root = Path.Combine(workDirectory, name); var dynamicDirectory = Path.Combine(root, "D"); // dynamic, keeping directory as short as possible var workingDirectory = Path.Combine(root, "W"); // working, keeping directory as short as possible var arguments = new Arguments { TargetUrl = url, DynamicRepositoryLocation = dynamicDirectory, TargetBranch = targetBranch, NoFetch = false, TargetPath = workingDirectory, CommitId = commitId }; var options = Options.Create(arguments); Directory.CreateDirectory(dynamicDirectory); Directory.CreateDirectory(workingDirectory); var testFileSystem = new TestFileSystem(); var log = new NullLog(); var configFileLocator = new DefaultConfigFileLocator(testFileSystem, log); var gitVersionCache = new GitVersionCache(testFileSystem, log); var buildServerResolver = new BuildServerResolver(null, log); var metadataCalculator = new MetaDataCalculator(); var baseVersionCalculator = new TestBaseVersionStrategiesCalculator(log); var mainlineVersionCalculator = new MainlineVersionCalculator(log, metadataCalculator); var nextVersionCalculator = new NextVersionCalculator(log, metadataCalculator, baseVersionCalculator, mainlineVersionCalculator); var gitVersionFinder = new GitVersionFinder(log, nextVersionCalculator); var gitPreparer = new GitPreparer(log, new TestEnvironment(), options); var stepFactory = new ConfigInitStepFactory(); var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory); var configurationProvider = new ConfigProvider(testFileSystem, log, configFileLocator, gitPreparer, configInitWizard); var variableProvider = new VariableProvider(nextVersionCalculator, new TestEnvironment()); var gitVersionCalculator = new GitVersionCalculator(testFileSystem, log, configFileLocator, configurationProvider, buildServerResolver, gitVersionCache, gitVersionFinder, gitPreparer, variableProvider, options); var versionVariables = gitVersionCalculator.CalculateVersionVariables(); Assert.AreEqual(expectedFullSemVer, versionVariables.FullSemVer); }
public void NoWarnOnGitVersionYmlFile() { SetupConfigFileContent(string.Empty); var output = WithDefaultConfigFileLocator(configFileLocator => { var log = new NullLog(); var defaultConfigFileLocator = new DefaultConfigFileLocator(fileSystem, log); var gitPreparer = new GitPreparer(log, new TestEnvironment(), Options.Create(new Arguments { TargetPath = repoPath })); var stepFactory = new ConfigInitStepFactory(); var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory); var configurationProvider = new ConfigProvider(fileSystem, log, defaultConfigFileLocator, gitPreparer, configInitWizard); configurationProvider.Provide(repoPath); }); output.Length.ShouldBe(0); }
public void NoWarnOnGitVersionYmlFile() { SetupConfigFileContent(string.Empty); var stringLogger = string.Empty; void Action(string info) => stringLogger = info; var logAppender = new TestLogAppender(Action); var log = new Log(logAppender); var defaultConfigFileLocator = new DefaultConfigFileLocator(fileSystem, log); var gitPreparer = new GitPreparer(log, environment, Options.Create(new Arguments { TargetPath = repoPath })); configProvider = new ConfigProvider(fileSystem, log, defaultConfigFileLocator, gitPreparer, configInitWizard); configProvider.Provide(repoPath); stringLogger.Length.ShouldBe(0); }