public void ShouldNotAllowIncrementOfVersion() { // When a branch is merged in you want to start building stable packages of that version // So we shouldn't bump the version var mockCommit = GitToolsTestingExtensions.CreateMockCommit(); mockCommit.Message.Returns("Merge branch 'release-0.1.5'"); mockCommit.Parents.Returns(GetParents(true)); var mockBranch = GitToolsTestingExtensions.CreateMockBranch(MainBranch, mockCommit); var branches = Substitute.For <IBranchCollection>(); branches.GetEnumerator().Returns(_ => ((IEnumerable <IBranch>) new[] { mockBranch }).GetEnumerator()); var mockRepository = Substitute.For <IGitRepository>(); mockRepository.Head.Returns(mockBranch); mockRepository.Branches.Returns(branches); mockRepository.Commits.Returns(mockBranch.Commits); var contextBuilder = new GitVersionContextBuilder().WithRepository(mockRepository); contextBuilder.Build(); var strategy = contextBuilder.ServicesProvider.GetServiceForType <IVersionStrategy, MergeMessageVersionStrategy>(); var baseVersion = strategy.GetVersions().Single(); baseVersion.ShouldIncrement.ShouldBe(false); }
private static void AssertMergeMessage(string message, string expectedVersion, IEnumerable <ICommit> parents, Config config = null) { var commit = GitToolsTestingExtensions.CreateMockCommit(); commit.Message.Returns(message); commit.Parents.Returns(parents); var mockBranch = GitToolsTestingExtensions.CreateMockBranch(MainBranch, commit, GitToolsTestingExtensions.CreateMockCommit()); var mockRepository = Substitute.For <IGitRepository>(); mockRepository.Head.Returns(mockBranch); mockRepository.Commits.Returns(mockBranch.Commits); var contextBuilder = new GitVersionContextBuilder() .WithConfig(config ?? new Config()) .WithRepository(mockRepository); contextBuilder.Build(); var strategy = contextBuilder.ServicesProvider.GetServiceForType <IVersionStrategy, MergeMessageVersionStrategy>(); var baseVersion = strategy.GetVersions().SingleOrDefault(); if (expectedVersion == null) { baseVersion.ShouldBe(null); } else { baseVersion.ShouldNotBeNull(); baseVersion.SemanticVersion.ToString().ShouldBe(expectedVersion); } }
public void CanInheritVersioningMode(VersioningMode mode) { using var fixture = new EmptyRepositoryFixture(); var config = new ConfigurationBuilder() .Add(new Config { VersioningMode = mode }) .Build(); const string branchName = MainBranch; var mockCommit = GitToolsTestingExtensions.CreateMockCommit(); var mockBranch = GitToolsTestingExtensions.CreateMockBranch(branchName, mockCommit); var branches = Substitute.For <IBranchCollection>(); branches.GetEnumerator().Returns(_ => ((IEnumerable <IBranch>) new[] { mockBranch }).GetEnumerator()); var mockRepository = Substitute.For <IGitRepository>(); mockRepository.Head.Returns(mockBranch); mockRepository.Branches.Returns(branches); mockRepository.Commits.Returns(mockBranch.Commits); var context = GetGitVersionContext(fixture.RepositoryPath, mockRepository, branchName, config); context.Configuration.VersioningMode.ShouldBe(mode); }
public void VerifyNullGuard2() { var commit = GitToolsTestingExtensions.CreateMockCommit(); var sut = new ShaVersionFilter(new[] { commit.Sha }); Should.Throw <ArgumentNullException>(() => sut.Exclude(null, out _)); }
public void WhenShaMismatchShouldNotExclude() { var commit = GitToolsTestingExtensions.CreateMockCommit(); var version = new BaseVersion("dummy", false, new SemanticVersion(1), commit, string.Empty); var sut = new ShaVersionFilter(new[] { "mismatched" }); sut.Exclude(version, out var reason).ShouldBeFalse(); reason.ShouldBeNull(); }
public void WhenShaMatchShouldExcludeWithReason() { var commit = GitToolsTestingExtensions.CreateMockCommit(); var version = new BaseVersion("dummy", false, new SemanticVersion(1), commit, string.Empty); var sut = new ShaVersionFilter(new[] { commit.Sha }); sut.Exclude(version, out var reason).ShouldBeTrue(); reason.ShouldNotBeNullOrWhiteSpace(); }
public void WhenShaMismatchShouldNotExclude() { var commit = GitToolsTestingExtensions.CreateMockCommit(); var version = new BaseVersion("dummy", false, new SemanticVersion(1), commit, string.Empty); var pastDate = DateTimeOffset.UtcNow.AddYears(-1); var sut = new MinDateVersionFilter(pastDate); sut.Exclude(version, out var reason).ShouldBeFalse(); reason.ShouldBeNull(); }
public void WhenCommitShouldExcludeWithReason() { var commit = GitToolsTestingExtensions.CreateMockCommit(); var version = new BaseVersion("dummy", false, new SemanticVersion(1), commit, string.Empty); var futureDate = DateTimeOffset.UtcNow.AddYears(1); var sut = new MinDateVersionFilter(futureDate); sut.Exclude(version, out var reason).ShouldBeTrue(); reason.ShouldNotBeNullOrWhiteSpace(); }
private GitVersionContextBuilder AddBranch(string branchName) { var mockCommit = GitToolsTestingExtensions.CreateMockCommit(); var mockBranch = GitToolsTestingExtensions.CreateMockBranch(branchName, mockCommit); var branches = this.repository.Branches.ToList(); branches.Add(mockBranch); this.repository.Branches.GetEnumerator().Returns(_ => ((IEnumerable <IBranch>)branches).GetEnumerator()); this.repository.Head.Returns(mockBranch); return(this); }
private static IGitRepository CreateRepository() { var mockCommit = GitToolsTestingExtensions.CreateMockCommit(); var mockBranch = GitToolsTestingExtensions.CreateMockBranch(TestBase.MainBranch, mockCommit); var branches = Substitute.For <IBranchCollection>(); branches.GetEnumerator().Returns(_ => ((IEnumerable <IBranch>) new[] { mockBranch }).GetEnumerator()); var mockRepository = Substitute.For <IGitRepository>(); mockRepository.Branches.Returns(branches); mockRepository.Head.Returns(mockBranch); mockRepository.Commits.Returns(mockBranch.Commits); return(mockRepository); }
public void ShouldIgnorePreReleaseVersionInMainlineMode() { var fakeIgnoreConfig = new TestIgnoreConfig(new ExcludeSourcesContainingExclude()); var lowerVersion = new BaseVersion("dummy", false, new SemanticVersion(1), GitToolsTestingExtensions.CreateMockCommit(), null); var preReleaseVersion = new BaseVersion( "prerelease", false, new SemanticVersion(1, 0, 1) { PreReleaseTag = new SemanticVersionPreReleaseTag { Name = "alpha", Number = 1 } }, GitToolsTestingExtensions.CreateMockCommit(), null ); var versionCalculator = GetBaseVersionCalculator(contextBuilder => { contextBuilder .WithConfig(new Config { VersioningMode = VersioningMode.Mainline, Ignore = fakeIgnoreConfig }) .OverrideServices(services => { services.RemoveAll <IVersionStrategy>(); services.AddSingleton <IVersionStrategy>(new TestVersionStrategy(preReleaseVersion, lowerVersion)); }); }); var baseVersion = versionCalculator.GetBaseVersion(); baseVersion.Source.ShouldNotBe(preReleaseVersion.Source); baseVersion.SemanticVersion.ShouldNotBe(preReleaseVersion.SemanticVersion); baseVersion.Source.ShouldBe(lowerVersion.Source); baseVersion.SemanticVersion.ShouldBe(lowerVersion.SemanticVersion); }
public void UsesBranchSpecificConfigOverTopLevelDefaults() { using var fixture = new EmptyRepositoryFixture(); const string branchName = "develop"; var config = new ConfigurationBuilder() .Add(new Config { VersioningMode = VersioningMode.ContinuousDelivery, Branches = { { branchName, new BranchConfig { VersioningMode = VersioningMode.ContinuousDeployment, Tag = "alpha" } } } }) .Build(); var main = GitToolsTestingExtensions.CreateMockBranch(MainBranch, GitToolsTestingExtensions.CreateMockCommit()); var develop = GitToolsTestingExtensions.CreateMockBranch(branchName, GitToolsTestingExtensions.CreateMockCommit()); var branches = Substitute.For <IBranchCollection>(); branches.GetEnumerator().Returns(_ => ((IEnumerable <IBranch>) new[] { main, develop }).GetEnumerator()); var mockRepository = Substitute.For <IGitRepository>(); mockRepository.Head.Returns(develop); mockRepository.Branches.Returns(branches); mockRepository.Commits.Returns(develop.Commits); var context = GetGitVersionContext(fixture.RepositoryPath, mockRepository, branchName, config); context.Configuration.Tag.ShouldBe("alpha"); }
public void ShouldFilterVersion() { var fakeIgnoreConfig = new TestIgnoreConfig(new ExcludeSourcesContainingExclude()); var higherVersion = new BaseVersion("exclude", false, new SemanticVersion(2), GitToolsTestingExtensions.CreateMockCommit(), null); var lowerVersion = new BaseVersion("dummy", false, new SemanticVersion(1), GitToolsTestingExtensions.CreateMockCommit(), null); var versionCalculator = GetBaseVersionCalculator(contextBuilder => contextBuilder .WithConfig(new Config { Ignore = fakeIgnoreConfig }) .OverrideServices(services => { services.RemoveAll <IVersionStrategy>(); services.AddSingleton <IVersionStrategy>(new TestVersionStrategy(higherVersion, lowerVersion)); })); var baseVersion = versionCalculator.GetBaseVersion(); baseVersion.Source.ShouldNotBe(higherVersion.Source); baseVersion.SemanticVersion.ShouldNotBe(higherVersion.SemanticVersion); baseVersion.Source.ShouldBe(lowerVersion.Source); baseVersion.SemanticVersion.ShouldBe(lowerVersion.SemanticVersion); }
public void AppliesBranchPreReleaseTag() { var semanticVersionBuildMetaData = new SemanticVersionBuildMetaData("ef7d0d7e1e700f1c7c9fa01ea6791bb778a5c37c", 2, "develop", "b1a34edbd80e141f7cc046c074f109be7d022074", "b1a34e", DateTimeOffset.Now, 0); var contextBuilder = new GitVersionContextBuilder(); contextBuilder .OverrideServices(services => { var testBaseVersionCalculator = new TestBaseVersionCalculator(false, new SemanticVersion(1), GitToolsTestingExtensions.CreateMockCommit()); services.AddSingleton <IBaseVersionCalculator>(testBaseVersionCalculator); services.AddSingleton <IMainlineVersionCalculator>(new TestMainlineVersionCalculator(semanticVersionBuildMetaData)); }) .WithDevelopBranch() .Build(); var nextVersionCalculator = contextBuilder.ServicesProvider.GetService <INextVersionCalculator>(); nextVersionCalculator.ShouldNotBeNull(); var version = nextVersionCalculator.FindVersion(); version.ToString("f").ShouldBe("1.0.0-alpha.1+2"); }
public void DoesNotIncrementWhenBaseVersionSaysNotTo() { var semanticVersionBuildMetaData = new SemanticVersionBuildMetaData("ef7d0d7e1e700f1c7c9fa01ea6791bb778a5c37c", 1, "master", "b1a34edbd80e141f7cc046c074f109be7d022074", "b1a34e", DateTimeOffset.Now, 0); var contextBuilder = new GitVersionContextBuilder(); contextBuilder .OverrideServices(services => { var testBaseVersionCalculator = new TestBaseVersionCalculator(false, new SemanticVersion(1), GitToolsTestingExtensions.CreateMockCommit()); services.AddSingleton <IBaseVersionCalculator>(testBaseVersionCalculator); services.AddSingleton <IMainlineVersionCalculator>(new TestMainlineVersionCalculator(semanticVersionBuildMetaData)); }) .WithConfig(new Config()) .Build(); var nextVersionCalculator = contextBuilder.ServicesProvider.GetService <INextVersionCalculator>(); nextVersionCalculator.ShouldNotBeNull(); var version = nextVersionCalculator.FindVersion(); version.ToString().ShouldBe("1.0.0"); }
public void UsesFirstBranchConfigWhenMultipleMatch() { using var fixture = new EmptyRepositoryFixture(); var branchConfig = new BranchConfig { VersioningMode = VersioningMode.Mainline, Increment = IncrementStrategy.None, PreventIncrementOfMergedBranchVersion = false, TrackMergeTarget = false, TracksReleaseBranches = false, IsReleaseBranch = false, SourceBranches = new HashSet <string>() }; var config = new ConfigurationBuilder() .Add(new Config { VersioningMode = VersioningMode.ContinuousDelivery, Branches = { { "release/latest", new BranchConfig(branchConfig) { Increment = IncrementStrategy.None, Regex = "release/latest" } }, { "release", new BranchConfig(branchConfig) { Increment = IncrementStrategy.Patch, Regex = "releases?[/-]" } } } }) .Build(); var releaseLatestBranch = GitToolsTestingExtensions.CreateMockBranch("release/latest", GitToolsTestingExtensions.CreateMockCommit()); var releaseVersionBranch = GitToolsTestingExtensions.CreateMockBranch("release/1.0.0", GitToolsTestingExtensions.CreateMockCommit()); var branches = Substitute.For <IBranchCollection>(); branches.GetEnumerator().Returns(_ => ((IEnumerable <IBranch>) new[] { releaseLatestBranch, releaseVersionBranch }).GetEnumerator()); var mockRepository = Substitute.For <IGitRepository>(); mockRepository.Branches.Returns(branches); mockRepository.Head.Returns(releaseLatestBranch); mockRepository.Commits.Returns(releaseLatestBranch.Commits); var latestContext = GetGitVersionContext(fixture.RepositoryPath, mockRepository, releaseLatestBranch.Name.Canonical, config); latestContext.Configuration.Increment.ShouldBe(IncrementStrategy.None); mockRepository.Head.Returns(releaseVersionBranch); var versionContext = GetGitVersionContext(fixture.RepositoryPath, mockRepository, releaseVersionBranch.Name.Canonical, config); versionContext.Configuration.Increment.ShouldBe(IncrementStrategy.Patch); }