public void multiple_version_tags_on_the_same_commit() { var repoTest = TestHelper.TestGitRepository; var cRealDevInAlpha = repoTest.Commits.Single(sc => sc.Message.StartsWith("Real Dev in Alpha.")); var overrides = new TagsOverride().MutableAdd(cRealDevInAlpha.Sha, "1.0.0") .MutableAdd(cRealDevInAlpha.Sha, "2.0.0"); { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cRealDevInAlpha.Sha, OverriddenTags = overrides.Overrides, }); i.ValidReleaseTag.Should().BeNull(); i.Error.Trim().Should().Be($"Commit '{cRealDevInAlpha.Sha}' has 2 different released version tags. Delete some of them or create +invalid tag(s) if they are already pushed to a remote repository."); } { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cRealDevInAlpha.Sha, OverriddenTags = overrides.Overrides, StartingVersionForCSemVer = "2.0.0" }); i.ValidReleaseTag.Should().Be(CSVersion.Parse("2.0.0")); } }
public void CIBuildVersion_from_DevInAlpha_commits_ahead_tests(string vDevInAlpha, string branchName, string ciBuildVersion, string branchNameVersion, string ciBuildVersionNuGet) { var repoTest = TestHelper.TestGitRepository; var cRoot = repoTest.Commits.First(sc => sc.Message.StartsWith("First in parallel world.")); var cPickChange = repoTest.Commits.First(sc => sc.Message.StartsWith("Cherry Pick - Change in parallel-world.txt content (1).")); var cDevInAlpha = repoTest.Commits.First(sc => sc.Message.StartsWith("Dev in Alpha.")); var overrides = new TagsOverride() .MutableAdd(cRoot.Sha, "v0.0.0-alpha") .MutableAdd(cPickChange.Sha, "v0.0.0-alpha.1") .MutableAdd(cDevInAlpha.Sha, vDevInAlpha); { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingBranchName = branchName, OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = branchName, CIVersionMode = CIBranchVersionMode.LastReleaseBased, VersionName = branchNameVersion } } }); Assert.That(i.ValidReleaseTag, Is.Null); Assert.That(i.CIRelease.BuildVersion, Is.EqualTo(ciBuildVersion)); Assert.That(i.CIRelease.BuildVersionNuGet, Is.EqualTo(ciBuildVersionNuGet)); } }
public void CIBuildVersion_from_DevInAlpha_commits_ahead_tests( string vDevInAlpha, string branchName, string ciBuildVersion, string branchNameVersion, string ciBuildVersionNuGet ) { var repoTest = TestHelper.TestGitRepository; var cRoot = repoTest.Commits.First( sc => sc.Message.StartsWith( "First in parallel world." ) ); var cPickChange = repoTest.Commits.First( sc => sc.Message.StartsWith( "Cherry Pick - Change in parallel-world.txt content (1)." ) ); var cDevInAlpha = repoTest.Commits.First( sc => sc.Message.StartsWith( "Dev in Alpha." ) ); var overrides = new TagsOverride() .MutableAdd( cRoot.Sha, "v0.0.0-alpha" ) .MutableAdd( cPickChange.Sha, "v0.0.0-alpha.1" ) .MutableAdd( cDevInAlpha.Sha, vDevInAlpha ); { RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingBranchName = branchName, OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = branchName, CIVersionMode = CIBranchVersionMode.LastReleaseBased, VersionName = branchNameVersion } } } ); Assert.That( i.ValidReleaseTag, Is.Null ); Assert.That( i.CIRelease.BuildVersion, Is.EqualTo( ciBuildVersion ) ); Assert.That( i.CIRelease.BuildVersionNuGet, Is.EqualTo( ciBuildVersionNuGet ) ); } }
public void repository_with_the_very_first_version_only() { var repoTest = TestHelper.TestGitRepository; var tagged = repoTest.Commits.First( sc => sc.Message.StartsWith( "Second b/b1" ) ); var bb1Tag = ReleaseTagVersion.VeryFirstVersion; var overrides = new TagsOverride().MutableAdd( tagged.Sha, bb1Tag.ToString() ); Action<SimpleCommit> checkOK = sc => { var i = repoTest.GetRepositoryInfo( sc.Sha, overrides ); Assert.That( i.ValidReleaseTag, Is.Null ); CollectionAssert.AreEqual( bb1Tag.GetDirectSuccessors(), i.PossibleVersions ); // Now tag the commit and checks that each tag is valid. foreach( var next in bb1Tag.GetDirectSuccessors() ) { var iWithTag = repoTest.GetRepositoryInfo( sc.Sha, overrides.Add( sc.Sha, next.ToString() ) ); Assert.That( iWithTag.ValidReleaseTag, Is.EqualTo( next ) ); } }; Action<SimpleCommit> checkKO = sc => { var i = repoTest.GetRepositoryInfo( sc.Sha, overrides ); Assert.That( i.ValidReleaseTag, Is.Null ); Assert.That( i.PossibleVersions, Is.Empty ); // Now tag the commit and checks that each tag is invalid. foreach( var next in bb1Tag.GetDirectSuccessors() ) { var iWithTag = repoTest.GetRepositoryInfo( sc.Sha, overrides.Add( sc.Sha, next.ToString() ) ); Assert.That( iWithTag.ValidReleaseTag, Is.Null ); Assert.That( iWithTag.ReleaseTagErrorLines, Is.Not.Null ); } }; // The version on the commit point. { var i = repoTest.GetRepositoryInfo( tagged.Sha, overrides ); Assert.That( i.ValidReleaseTag, Is.EqualTo( bb1Tag ) ); CollectionAssert.AreEqual( ReleaseTagVersion.FirstPossibleVersions, i.PossibleVersionsStrict ); }; // Checking possible versions before: none. var before1 = repoTest.Commits.First( sc => sc.Message.StartsWith( "Merge branch 'a' into b" ) ); checkKO( before1 ); var before2 = repoTest.Commits.First( sc => sc.Message.StartsWith( "Second a/a2" ) ); checkKO( before2 ); var before3 = repoTest.Commits.First( sc => sc.Message.StartsWith( "On master again" ) ); checkKO( before3 ); // Checking possible versions after: all successors are allowed. var after1 = repoTest.Commits.First( sc => sc.Message.StartsWith( "Second b/b2" ) ); checkOK( after1 ); var after2 = repoTest.Commits.First( sc => sc.Message.StartsWith( "Merge branch 'b' into c" ) ); checkOK( after2 ); var after3 = repoTest.Commits.First( sc => sc.Message.StartsWith( "Merge branches 'c', 'd' and 'e'" ) ); checkOK( after3 ); }
public void fumble_commit_scenario() { var repoTest = TestHelper.TestGitRepository; var cD = repoTest.Commits.First(sc => sc.Message.StartsWith("D-Commit.")); var cC = repoTest.Commits.First(sc => sc.Message.StartsWith("C-Commit.")); var cF = repoTest.Commits.First(sc => sc.Sha == "27a629754c6b9034f7ca580442b589a0241773c5"); var cB = repoTest.Commits.First(sc => sc.Message.StartsWith("B-Commit.")); var cA = repoTest.Commits.First(sc => sc.Message.StartsWith("Merge branch 'fumble-develop' into fumble-master")); var cFix = repoTest.Commits.First(sc => sc.Sha == "e6766d127f9a2df42567151222c6569601614626"); var cX = repoTest.Commits.First(sc => sc.Message.StartsWith("X-Commit.")); var overrides = new TagsOverride() .MutableAdd(cD.Sha, "v4.3.2") .MutableAdd(cC.Sha, "v4.4.0-alpha") .MutableAdd(cB.Sha, "v5.0.0-rc") .MutableAdd(cA.Sha, "v5.0.0"); var v5 = ReleaseTagVersion.TryParse("v5.0.0"); var v5rc = ReleaseTagVersion.TryParse("v5.0.0-rc"); var v5rc01 = ReleaseTagVersion.TryParse("v5.0.0-rc.0.1"); var v5rc1 = ReleaseTagVersion.TryParse("v5.0.0-rc.1"); { // On the fix of the fumble commit, only v5.0.0-rc.0.1 is possible in Restricted mode. // Restricted mode disallow rc.1 (next version below the first already released next one). RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cFix.Sha }); Assert.That(i.PreviousRelease.ThisTag, Is.EqualTo(v5rc)); Assert.That(i.PreviousMaxRelease.ThisTag, Is.SameAs(i.PreviousRelease.ThisTag)); CollectionAssert.AreEqual(new[] { v5rc01 }, i.PossibleVersionsStrict); // In default mode, the fix of the fumble commit, v5.0.0-rc.0.1 and rc.1 are possible. CollectionAssert.AreEqual(new[] { v5rc01, v5rc1 }, i.PossibleVersions); } { // Above the fix of the fumble commit, v5.0.0-rc.0.1 and any successor of the 5.0.0 is possible. RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cX.Sha }); Assert.That(i.PreviousRelease.ThisTag, Is.EqualTo(v5rc)); Assert.That(i.PreviousMaxRelease.ThisTag, Is.EqualTo(v5)); var possible = new List <ReleaseTagVersion>() { v5rc01, v5rc1 }; possible.AddRange(v5.GetDirectSuccessors()); CollectionAssert.AreEqual(possible, i.PossibleVersions); var possibleStrict = new List <ReleaseTagVersion>() { v5rc01 }; possibleStrict.AddRange(v5.GetDirectSuccessors()); CollectionAssert.AreEqual(possibleStrict, i.PossibleVersionsStrict); } }
public void CIBuildVersion_from_RealDevInAlpha_commits_ahead_tests( string vRealDevInAlpha, string branchName, string ciBuildVersion, string branchVersionName, string ciBuildVersionNuGet ) { var repoTest = TestHelper.TestGitRepository; var cRealDevInAlpha = repoTest.Commits.Single( sc => sc.Message.StartsWith( "Real Dev in Alpha." ) ); var overrides = new TagsOverride().MutableAdd( cRealDevInAlpha.Sha, vRealDevInAlpha ); { RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingBranchName = branchName, OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = branchName, CIVersionMode = CIBranchVersionMode.LastReleaseBased, VersionName = branchVersionName } } } ); Assert.That( i.ValidReleaseTag, Is.Null ); Assert.That( i.CIRelease.BuildVersion, Is.EqualTo( ciBuildVersion ) ); Assert.That( i.CIRelease.BuildVersionNuGet, Is.EqualTo( ciBuildVersionNuGet ) ); } }
public void CIBuildVersion_from_RealDevInAlpha_commits_ahead_tests(string vRealDevInAlpha, string branchName, string ciBuildVersion, string branchVersionName, string ciBuildVersionNuGet) { var repoTest = TestHelper.TestGitRepository; var cRealDevInAlpha = repoTest.Commits.Single(sc => sc.Message.StartsWith("Real Dev in Alpha.")); var overrides = new TagsOverride().MutableAdd(cRealDevInAlpha.Sha, vRealDevInAlpha); { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingBranchName = branchName, OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = branchName, CIVersionMode = CIBranchVersionMode.LastReleaseBased, VersionName = branchVersionName } } }); Assert.That(i.ValidReleaseTag, Is.Null); Assert.That(i.CIRelease.BuildVersion.NormalizedText, Is.EqualTo(ciBuildVersion)); Assert.That(i.CIRelease.BuildVersionNuGet.NormalizedText, Is.EqualTo(ciBuildVersionNuGet)); } }
public void ignoring_legacy_versions_with_StartingVersionForCSemVer_option() { var repoTest = TestHelper.TestGitRepository; var c*K = repoTest.Commits.First( sc => sc.Message.StartsWith( "Second b/b1" ) ); var cKO1 = repoTest.Commits.First( sc => sc.Message.StartsWith( "Second a/a1" ) ); var cKO2 = repoTest.Commits.First( sc => sc.Message.StartsWith( "First b/b1" ) ); var cKO3 = repoTest.Commits.First( sc => sc.Message.StartsWith( "First a/a2" ) ); var overrides = new TagsOverride() .MutableAdd( c*K.Sha, "4.0.3-beta" ) .MutableAdd( cKO1.Sha, "0.0.0-alpha" ) .MutableAdd( cKO2.Sha, "1.1.0" ) .MutableAdd( cKO3.Sha, "2.0.2" ); { RepositoryInfo i = repoTest.GetRepositoryInfo( c*K.Sha, overrides ); Assert.That( i.ReleaseTagErrorText, Is.Not.Null ); } { RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingCommitSha = c*K.Sha, OverriddenTags = overrides.Overrides, StartingVersionForCSemVer = "4.0.3-beta" } ); Assert.That( i.ReleaseTagErrorText, Is.Null ); Assert.That( i.ValidReleaseTag.ToString(), Is.EqualTo( "v4.0.3-beta" ) ); Assert.That( i.PreviousRelease, Is.Null ); CollectionAssert.AreEqual( i.PossibleVersions.Select( t => t.ToString() ), new[] { "v4.0.3-beta" } ); } { var cAbove = repoTest.Commits.First( sc => sc.Message.StartsWith( "Second b/b2" ) ); RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingCommitSha = cAbove.Sha, OverriddenTags = overrides.Overrides, StartingVersionForCSemVer = "4.0.3-beta" } ); Assert.That( i.ReleaseTagErrorText, Is.Null ); Assert.That( i.PreviousRelease.ThisTag.ToString(), Is.EqualTo( "v4.0.3-beta" ) ); Assert.That( i.ValidReleaseTag, Is.Null ); CollectionAssert.Contains( i.PossibleVersions.Select( t => t.ToString() ), "v4.0.3-beta.0.1", "v4.0.3-beta.1", "v4.0.3-delta", "v4.0.3", "v4.1.0-rc", "v4.1.0", "v5.0.0" ); } // Commit before the StartingVersionForCSemVer has no PossibleVersions. { var cBelow = repoTest.Commits.First( sc => sc.Message.StartsWith( "On master again" ) ); RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingCommitSha = cBelow.Sha, OverriddenTags = overrides.Overrides, StartingVersionForCSemVer = "4.0.3-beta" } ); Assert.That( i.ReleaseTagErrorText, Is.Null ); Assert.That( i.PreviousRelease, Is.Null ); Assert.That( i.ValidReleaseTag, Is.Null ); CollectionAssert.IsEmpty( i.PossibleVersions ); } { var cBelow = repoTest.Commits.First( sc => sc.Message.StartsWith( "Merge branch 'a' into b" ) ); RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingCommitSha = cBelow.Sha, OverriddenTags = overrides.Overrides, StartingVersionForCSemVer = "4.0.3-beta" } ); Assert.That( i.ReleaseTagErrorText, Is.Null ); Assert.That( i.PreviousRelease, Is.Null ); Assert.That( i.ValidReleaseTag, Is.Null ); CollectionAssert.IsEmpty( i.PossibleVersions ); } }
public void fumble_commit_scenario() { var repoTest = TestHelper.TestGitRepository; var cD = repoTest.Commits.First( sc => sc.Message.StartsWith( "D-Commit." ) ); var cC = repoTest.Commits.First( sc => sc.Message.StartsWith( "C-Commit." ) ); var cF = repoTest.Commits.First( sc => sc.Sha == "27a629754c6b9034f7ca580442b589a0241773c5" ); var cB = repoTest.Commits.First( sc => sc.Message.StartsWith( "B-Commit." ) ); var cA = repoTest.Commits.First( sc => sc.Message.StartsWith( "Merge branch 'fumble-develop' into fumble-master" ) ); var cFix = repoTest.Commits.First( sc => sc.Sha == "e6766d127f9a2df42567151222c6569601614626" ); var cX = repoTest.Commits.First( sc => sc.Message.StartsWith( "X-Commit." ) ); var overrides = new TagsOverride() .MutableAdd( cD.Sha, "v4.3.2" ) .MutableAdd( cC.Sha, "v4.4.0-alpha" ) .MutableAdd( cB.Sha, "v5.0.0-rc" ) .MutableAdd( cA.Sha, "v5.0.0" ); var v5 = ReleaseTagVersion.TryParse( "v5.0.0" ); var v5rc = ReleaseTagVersion.TryParse( "v5.0.0-rc" ); var v5rc01 = ReleaseTagVersion.TryParse( "v5.0.0-rc.0.1" ); var v5rc1 = ReleaseTagVersion.TryParse( "v5.0.0-rc.1" ); { // On the fix of the fumble commit, only v5.0.0-rc.0.1 is possible in Restricted mode. // Restricted mode disallow rc.1 (next version below the first already released next one). RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cFix.Sha } ); Assert.That( i.PreviousRelease.ThisTag, Is.EqualTo( v5rc ) ); Assert.That( i.PreviousMaxRelease.ThisTag, Is.SameAs( i.PreviousRelease.ThisTag ) ); CollectionAssert.AreEqual( new[] { v5rc01 }, i.PossibleVersionsStrict ); // In default mode, the fix of the fumble commit, v5.0.0-rc.0.1 and rc.1 are possible. CollectionAssert.AreEqual( new[] { v5rc01, v5rc1 }, i.PossibleVersions ); } { // Above the fix of the fumble commit, v5.0.0-rc.0.1 and any successor of the 5.0.0 is possible. RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cX.Sha } ); Assert.That( i.PreviousRelease.ThisTag, Is.EqualTo( v5rc ) ); Assert.That( i.PreviousMaxRelease.ThisTag, Is.EqualTo( v5 ) ); var possible = new List<ReleaseTagVersion>() { v5rc01, v5rc1 }; possible.AddRange( v5.GetDirectSuccessors() ); CollectionAssert.AreEqual( possible, i.PossibleVersions ); var possibleStrict = new List<ReleaseTagVersion>() { v5rc01 }; possibleStrict.AddRange( v5.GetDirectSuccessors() ); CollectionAssert.AreEqual( possibleStrict, i.PossibleVersionsStrict ); } }
public void fumble_commit_plus_an_extra_content_with_a_big_release_number() { var repoTest = TestHelper.TestGitRepository; var cD = repoTest.Commits.First( sc => sc.Message.StartsWith( "D-Commit." ) ); var cC = repoTest.Commits.First( sc => sc.Message.StartsWith( "C-Commit." ) ); var cF = repoTest.Commits.First( sc => sc.Sha == "27a629754c6b9034f7ca580442b589a0241773c5" ); var cB = repoTest.Commits.First( sc => sc.Message.StartsWith( "B-Commit." ) ); var cA = repoTest.Commits.First( sc => sc.Message.StartsWith( "Merge branch 'fumble-develop' into fumble-master" ) ); var cFix = repoTest.Commits.First( sc => sc.Sha == "e6766d127f9a2df42567151222c6569601614626" ); var cX = repoTest.Commits.First( sc => sc.Message.StartsWith( "X-Commit." ) ); var cExtra = repoTest.Commits.First( sc => sc.Message.StartsWith( "C-Commit (cherry pick)." ) ); var overrides = new TagsOverride() .MutableAdd( cD.Sha, "v4.3.2" ) .MutableAdd( cC.Sha, "v4.4.0-alpha" ) .MutableAdd( cB.Sha, "v5.0.0-rc" ) .MutableAdd( cA.Sha, "v5.0.0" ) .MutableAdd( cExtra.Sha, "v10.0.0" ); var v5 = ReleaseTagVersion.TryParse( "v5.0.0" ); var v5rc = ReleaseTagVersion.TryParse( "v5.0.0-rc" ); var v5rc01 = ReleaseTagVersion.TryParse( "v5.0.0-rc.0.1" ); var v5rc1 = ReleaseTagVersion.TryParse( "v5.0.0-rc.1" ); var v10 = ReleaseTagVersion.TryParse( "v10.0.0" ); { // The injected v10 overrides everything except the possibilty to release the v5.0.0-rc.0.1. RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cFix.Sha } ); Assert.That( i.PreviousRelease.ThisTag, Is.EqualTo( v5rc ) ); Assert.That( i.PreviousMaxRelease.ThisTag, Is.EqualTo( v10 ) ); var possibleStrict = new List<ReleaseTagVersion>() { v5rc01 }; possibleStrict.AddRange( v10.GetDirectSuccessors() ); CollectionAssert.AreEqual( possibleStrict, i.PossibleVersionsStrict ); var possible = new List<ReleaseTagVersion>() { v5rc01, v5rc1 }; possible.AddRange( v10.GetDirectSuccessors() ); CollectionAssert.AreEqual( possible, i.PossibleVersions ); } { // On B-Commit: // Restricted Mode: it is the same, v4.4.0-alpha.0.1 and successors of v10. // AllSuccessors Mode: all successors of v4.4.0-alpha (except the v5.0.0) are allowed and successors of v10. var v44a = ReleaseTagVersion.TryParse( "v4.4.0-alpha" ); var v44a01 = ReleaseTagVersion.TryParse( "v4.4.0-alpha.0.1" ); var v44a1 = ReleaseTagVersion.TryParse( "v4.4.0-alpha.1" ); var v500 = ReleaseTagVersion.TryParse( "v5.0.0" ); RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cB.Sha } ); Assert.That( i.PreviousRelease.ThisTag, Is.EqualTo( v44a ) ); Assert.That( i.PreviousMaxRelease.ThisTag, Is.EqualTo( v10 ) ); var possibleStrict = new List<ReleaseTagVersion>() { v44a01 }; possibleStrict.AddRange( v10.GetDirectSuccessors() ); CollectionAssert.AreEqual( possibleStrict, i.PossibleVersionsStrict ); var possible = new List<ReleaseTagVersion>(); possible.AddRange( v44a.GetDirectSuccessors().Where( v => v != v500 ) ); possible.AddRange( v10.GetDirectSuccessors() ); CollectionAssert.AreEqual( possible, i.PossibleVersions ); } }
public void StrictMode_content_based_decisions_saves_the_cherry_picks() { var repoTest = TestHelper.TestGitRepository; var cRoot = repoTest.Commits.Single(sc => sc.Message.StartsWith("First in parallel world.")); var cChange = repoTest.Commits.Single(sc => sc.Message.StartsWith("Change in parallel-world.txt content (1).")); var cReset = repoTest.Commits.Single(sc => sc.Message.StartsWith("Reset change in parallel-world.txt content (2).")); var cPickReset = repoTest.Commits.Single(sc => sc.Message.StartsWith("Cherry Pick - Reset change in parallel-world.txt content (2).")); var cPickChange = repoTest.Commits.Single(sc => sc.Message.StartsWith("Cherry Pick - Change in parallel-world.txt content (1).")); var cPostReset = repoTest.Commits.Single(sc => sc.Sha == "3035a581af1302293739e5caf7dfbc009a71454f"); // "Merge branch 'gamma' into parallel-world" (there are two of them); var cDevInGamma = repoTest.Commits.Single(sc => sc.Message.StartsWith("Dev in Gamma.")); var cMergeAll = repoTest.Commits.Single(sc => sc.Message.StartsWith("Merge branch 'parallel-world' into alpha")); var v1 = ReleaseTagVersion.TryParse("1.0.0"); var v2 = ReleaseTagVersion.TryParse("2.0.0"); var overrides = new TagsOverride() .MutableAdd(cRoot.Sha, v1.ToString()) .MutableAdd(cChange.Sha, v2.ToString()); // cMergeAll => succ(v2.0.0) // / \ // / \ // | | // cDevInGamma | => fixes(v1.0.0)+succ(v2.0.0). // | | // cPickReset | => fixes(v1.0.0)+succ(v2.0.0) because the cherry pick makes cPickChange content v2.0.0 // | | // cPickChange | => fixes(v1.0.0). (Its content is actually v2.0.0) // | | // | cPostReset => succ(v2.0.0) // | | // | cReset => succ(v2.0.0) // | | // | cChange - v2.0.0 // | / // | / // | / // |/ // cRoot - v1.0.0 Action <SimpleCommit> v1Successors = commit => { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = commit.Sha, OverriddenTags = overrides.Overrides }); CollectionAssert.AreEqual(v1.GetDirectSuccessors().Where(t => t.ToString() != "v2.0.0"), i.PossibleVersionsStrict); }; Action <SimpleCommit> v1FixSuccessors = commit => { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = commit.Sha, OverriddenTags = overrides.Overrides }); CollectionAssert.AreEqual(v1.GetDirectSuccessors(true).Where(t => t.ToString() != "v2.0.0"), i.PossibleVersionsStrict); }; Action <SimpleCommit> v1FixAndV2Successors = commit => { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = commit.Sha, OverriddenTags = overrides.Overrides }); CollectionAssert.AreEqual(v1.GetDirectSuccessors(true).Where(t => t.ToString() != "v2.0.0").Concat(v2.GetDirectSuccessors()), i.PossibleVersionsStrict); }; Action <SimpleCommit> v2Successors = commit => { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = commit.Sha, PossibleVersionsMode = PossibleVersionsMode.Restricted, OverriddenTags = overrides.Overrides }); CollectionAssert.AreEqual(v2.GetDirectSuccessors(), i.PossibleVersionsStrict); }; v2Successors(cReset); v1FixSuccessors(cPickChange); v1FixAndV2Successors(cPickReset); v2Successors(cPostReset); v1FixAndV2Successors(cDevInGamma); v2Successors(cMergeAll); }
public void CIBuildVersion_with_merged_tags() { var repoTest = TestHelper.TestGitRepository; var cRoot = repoTest.Commits.Single( sc => sc.Message.StartsWith( "First in parallel world." ) ); var cDevInAlpha = repoTest.Commits.Single( sc => sc.Message.StartsWith( "Dev in Alpha." ) ); var cDevInBeta = repoTest.Commits.Single( sc => sc.Message.StartsWith( "Dev in Beta." ) ); var cDevInGamma = repoTest.Commits.Single( sc => sc.Message.StartsWith( "Dev in Gamma." ) ); var overrides = new TagsOverride() .MutableAdd( cRoot.Sha, "v1.0.0" ) .MutableAdd( cDevInAlpha.Sha, "v2.0.0" ); // cDevInBeta // | // | cDevInGamma // | / // |/ cDevInAlpha - v2.0.0 // | / // | / // | / // cRoot - v1.0.0 { RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingCommitSha = cDevInAlpha.Sha, OverriddenTags = overrides.Overrides } ); Assert.That( i.ValidReleaseTag, Is.EqualTo( ReleaseTagVersion.TryParse( "v2.0.0" ) ) ); } overrides.MutableAdd( cDevInBeta.Sha, "v1.0.1-beta" ); // cDevInBeta - v1.0.1-beta // | // | cDevInGamma // | / // |/ cDevInAlpha - v2.0.0 // | / // | / // cRoot - v1.0.0 { RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingCommitSha = cDevInBeta.Sha, OverriddenTags = overrides.Overrides } ); Assert.That( i.ValidReleaseTag, Is.EqualTo( ReleaseTagVersion.TryParse( "v1.0.1-beta" ) ) ); } overrides.MutableAdd( cDevInGamma.Sha, "v1.0.1-alpha" ); // cDevInBeta - v1.0.1-beta // | // | cDevInGamma - v1.0.1-alpha // | / // |/ cDevInAlpha - v2.0.0 // | / // | / // cRoot - v1.0.0 { RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingCommitSha = cDevInGamma.Sha, OverriddenTags = overrides.Overrides } ); Assert.That( i.ValidReleaseTag, Is.EqualTo( ReleaseTagVersion.TryParse( "v1.0.1-alpha" ) ) ); } // On "gamma" branch, the head is 7 commits ahead of the v2.0.0 tag: this is the longest path. { RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingBranchName = "gamma", OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = "gamma", CIVersionMode = CIBranchVersionMode.LastReleaseBased } } } ); Assert.That( i.ValidReleaseTag, Is.Null ); Assert.That( i.CIRelease.BuildVersion, Is.EqualTo( "2.0.1--ci-gamma.7" ) ); } // On "alpha" branch, the head is 6 commits ahead of the v2.0.0 tag (always the take the longest path). { RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingBranchName = "alpha", OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = "alpha", VersionName="ALPHAAAA", CIVersionMode = CIBranchVersionMode.LastReleaseBased } } } ); Assert.That( i.ValidReleaseTag, Is.Null ); Assert.That( i.CIRelease.BuildVersion, Is.EqualTo( "2.0.1--ci-ALPHAAAA.6" ) ); } // On "beta" branch, the head is 6 commits ahead of the v2.0.0 tag. { RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingBranchName = "beta", OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = "beta", VersionName="BBBBBB", CIVersionMode = CIBranchVersionMode.LastReleaseBased } } } ); Assert.That( i.ValidReleaseTag, Is.Null ); Assert.That( i.CIRelease.BuildVersion, Is.EqualTo( "2.0.1--ci-BBBBBB.6" ) ); } }
public void propagation_through_multiple_hops() { var repoTest = TestHelper.TestGitRepository; var cAlpha = repoTest.Commits.First( sc => sc.Message.StartsWith( "Real Dev in Alpha." ) ); // cReleased is "Merge branch 'gamma' into parallel-world" but there are two of them... // This is the head of parallel-world branch. var cReleased = repoTest.Commits.First( sc => sc.Sha == "fc9802013c23398978744de1618fb01638f7347e" ); var v1beta = ReleaseTagVersion.TryParse( "1.0.0-beta" ); var overrides = new TagsOverride().MutableAdd( cAlpha.Sha, "1.0.0-beta" ); // cReleased // | // | // cAlpha - v1.0.0-beta // This is "normal": cReleased has 1.0.0-beta in its parent. { RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingCommitSha = cReleased.Sha, OverriddenTags = overrides.Overrides } ); Assert.That( i.ReleaseTagErrorText, Is.Null ); Assert.That( i.PreviousRelease.ThisTag, Is.EqualTo( v1beta ) ); Assert.That( i.ValidReleaseTag, Is.Null ); CollectionAssert.AreEqual( v1beta.GetDirectSuccessors(), i.PossibleVersions ); CollectionAssert.AreEqual( v1beta.GetDirectSuccessors(), i.PossibleVersionsStrict ); } var cAlphaContinue = repoTest.Commits.First( sc => sc.Message.StartsWith( "Dev again in Alpha." ) ); // We set 2.0.0 on cReleased. Its content is the same as cAlpha (mege commits with no changes). // // cAlphaContinue // | // | cReleased - v2.0.0 // | / // |/ // cAlpha - v1.0.0-beta overrides.MutableAdd( cReleased.Sha, "2.0.0" ); { RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingCommitSha = cReleased.Sha, OverriddenTags = overrides.Overrides } ); Assert.That( i.ReleaseTagErrorText, Is.Null ); Assert.That( i.ValidReleaseTag.ToString(), Is.EqualTo( "v2.0.0" ) ); } // Subsequent developments of alpha branch now starts after 2.0.0, for instance 2.1.0-beta. overrides.MutableAdd( cAlphaContinue.Sha, "2.1.0-beta" ); { RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingCommitSha = cAlphaContinue.Sha, OverriddenTags = overrides.Overrides } ); var tagged = ReleaseTagVersion.TryParse( "2.1.0-beta" ); Assert.That( i.ReleaseTagErrorText, Is.Null ); Assert.That( i.ValidReleaseTag, Is.EqualTo( tagged ) ); CollectionAssert.AreEqual( new[] { ReleaseTagVersion.TryParse( "1.0.0-beta.0.1" ) } .Concat( ReleaseTagVersion.TryParse( "2.0.0" ).GetDirectSuccessors() ), i.PossibleVersionsStrict ); // In no strict mode, alpha branch can continue with any successors of // the 1.0.0-beta except the v2.0.0 of course. CollectionAssert.AreEqual( ReleaseTagVersion.TryParse( "1.0.0-beta" ).GetDirectSuccessors() .Where( v => v != ReleaseTagVersion.TryParse( "2.0.0" ) ) .Concat( ReleaseTagVersion.TryParse( "2.0.0" ).GetDirectSuccessors() ), i.PossibleVersions ); } }
public void StrictMode_content_based_decisions_saves_the_cherry_picks() { var repoTest = TestHelper.TestGitRepository; var cRoot = repoTest.Commits.Single( sc => sc.Message.StartsWith( "First in parallel world." ) ); var cChange = repoTest.Commits.Single( sc => sc.Message.StartsWith( "Change in parallel-world.txt content (1)." ) ); var cReset = repoTest.Commits.Single( sc => sc.Message.StartsWith( "Reset change in parallel-world.txt content (2)." ) ); var cPickReset = repoTest.Commits.Single( sc => sc.Message.StartsWith( "Cherry Pick - Reset change in parallel-world.txt content (2)." ) ); var cPickChange = repoTest.Commits.Single( sc => sc.Message.StartsWith( "Cherry Pick - Change in parallel-world.txt content (1)." ) ); var cPostReset = repoTest.Commits.Single( sc => sc.Sha == "3035a581af1302293739e5caf7dfbc009a71454f" ); // "Merge branch 'gamma' into parallel-world" (there are two of them); var cDevInGamma = repoTest.Commits.Single( sc => sc.Message.StartsWith( "Dev in Gamma." ) ); var cMergeAll = repoTest.Commits.Single( sc => sc.Message.StartsWith( "Merge branch 'parallel-world' into alpha" ) ); var v1 = ReleaseTagVersion.TryParse( "1.0.0" ); var v2 = ReleaseTagVersion.TryParse( "2.0.0" ); var overrides = new TagsOverride() .MutableAdd( cRoot.Sha, v1.ToString() ) .MutableAdd( cChange.Sha, v2.ToString() ); // cMergeAll => succ(v2.0.0) // / \ // / \ // | | // cDevInGamma | => fixes(v1.0.0)+succ(v2.0.0). // | | // cPickReset | => fixes(v1.0.0)+succ(v2.0.0) because the cherry pick makes cPickChange content v2.0.0 // | | // cPickChange | => fixes(v1.0.0). (Its content is actually v2.0.0) // | | // | cPostReset => succ(v2.0.0) // | | // | cReset => succ(v2.0.0) // | | // | cChange - v2.0.0 // | / // | / // | / // |/ // cRoot - v1.0.0 Action<SimpleCommit> v1Successors = commit => { RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingCommitSha = commit.Sha, OverriddenTags = overrides.Overrides } ); CollectionAssert.AreEqual( v1.GetDirectSuccessors().Where( t => t.ToString() != "v2.0.0" ), i.PossibleVersionsStrict ); }; Action<SimpleCommit> v1FixSuccessors = commit => { RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingCommitSha = commit.Sha, OverriddenTags = overrides.Overrides } ); CollectionAssert.AreEqual( v1.GetDirectSuccessors( true ).Where( t => t.ToString() != "v2.0.0" ), i.PossibleVersionsStrict ); }; Action<SimpleCommit> v1FixAndV2Successors = commit => { RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingCommitSha = commit.Sha, OverriddenTags = overrides.Overrides } ); CollectionAssert.AreEqual( v1.GetDirectSuccessors( true ).Where( t => t.ToString() != "v2.0.0" ).Concat( v2.GetDirectSuccessors() ), i.PossibleVersionsStrict ); }; Action<SimpleCommit> v2Successors = commit => { RepositoryInfo i = repoTest.GetRepositoryInfo( new RepositoryInfoOptions { StartingCommitSha = commit.Sha, PossibleVersionsMode = PossibleVersionsMode.Restricted, OverriddenTags = overrides.Overrides } ); CollectionAssert.AreEqual( v2.GetDirectSuccessors(), i.PossibleVersionsStrict ); }; v2Successors( cReset ); v1FixSuccessors( cPickChange ); v1FixAndV2Successors( cPickReset ); v2Successors( cPostReset ); v1FixAndV2Successors( cDevInGamma ); v2Successors( cMergeAll ); }
public void fumble_commit_plus_an_extra_content_with_a_big_release_number() { var repoTest = TestHelper.TestGitRepository; var cD = repoTest.Commits.First(sc => sc.Message.StartsWith("D-Commit.")); var cC = repoTest.Commits.First(sc => sc.Message.StartsWith("C-Commit.")); var cF = repoTest.Commits.First(sc => sc.Sha == "27a629754c6b9034f7ca580442b589a0241773c5"); var cB = repoTest.Commits.First(sc => sc.Message.StartsWith("B-Commit.")); var cM = repoTest.Commits.First(sc => sc.Message.StartsWith("Merge branch 'fumble-develop' into fumble-master")); var cFix = repoTest.Commits.First(sc => sc.Sha == "e6766d127f9a2df42567151222c6569601614626"); var cX = repoTest.Commits.First(sc => sc.Message.StartsWith("X-Commit.")); var cExtra = repoTest.Commits.First(sc => sc.Message.StartsWith("C-Commit (cherry pick).")); // cExtra + v10.0.0 - This has the same content (cherry pick) as cC (here in v4.4.0-alpha). // | // | // | // cFix | + This commit point has the same content as cM (the "master"). // | | => Without SingleMajor = 5, v10 wins. // | | // cM | | + v5.0.0 - Merge in "master" // | | /| // | | / | // | | / | // | |/ | // cB | + | v5.0.0-rc // | | | // | | | // cC | + | v4.4.0-alpha (but now its content is actually v10.0.0) // | | | // cF | | + Fumble Commit (commit in "master" that should have been done on "dev"). // \ | / // \ | / // \ | / // \|/ // cD + v4.3.2 var overrides = new TagsOverride() .MutableAdd(cD.Sha, "v4.3.2") .MutableAdd(cC.Sha, "v4.4.0-alpha") .MutableAdd(cB.Sha, "v5.0.0-rc") .MutableAdd(cM.Sha, "v5.0.0") .MutableAdd(cExtra.Sha, "v10.0.0"); var v5 = CSVersion.TryParse("v5.0.0"); var v5rc = CSVersion.TryParse("v5.0.0-rc"); var v5rc01 = CSVersion.TryParse("v5.0.0-rc.0.1"); var v5rc1 = CSVersion.TryParse("v5.0.0-rc.1"); var v10 = CSVersion.TryParse("v10.0.0"); { // On cFix, Without SingleMajor = 5, v10 wins. RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cFix.Sha }); CollectionAssert.AreEqual(v10.GetDirectSuccessors(), i.PossibleVersions); RepositoryInfo iLTS = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cFix.Sha, SingleMajor = 5 }); var allowed = v5.GetDirectSuccessors().Where(v => v.Major == 5); CollectionAssert.AreEqual(allowed, iLTS.PossibleVersions); } { // Without SingleMajor = 5, On B-Commit (just above v4.4.0-alpha) v10 wins. var v44a = CSVersion.TryParse("v4.4.0-alpha"); var v44a01 = CSVersion.TryParse("v4.4.0-alpha.0.1"); var v44a1 = CSVersion.TryParse("v4.4.0-alpha.1"); var v500 = CSVersion.TryParse("v5.0.0"); RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cB.Sha }); CollectionAssert.AreEqual(v10.GetDirectSuccessors(), i.PossibleVersions); RepositoryInfo iLTS = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cB.Sha, SingleMajor = 4 }); var allowed = v44a.GetDirectSuccessors().Where(v => v.Major == 4); CollectionAssert.AreEqual(allowed, iLTS.PossibleVersions); } { // On C-Extra: the v10.0.0 is actually not allowed since it is not a // successor of v4.3.2. // The possible versions here are the successors of v4.4.0-alpha (up to the // existing v5.0.0-rc) because its content is tagged with v4.4.0-alpha. var v432 = CSVersion.TryParse("v4.3.2"); var v44a = CSVersion.TryParse("v4.4.0-alpha"); RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cExtra.Sha }); Assert.That(i.ReleaseTagIsNotPossibleError); CollectionAssert.AreEqual(v44a.GetDirectSuccessors().Where(v => v < v5rc), i.PossibleVersions); // But the v10.0.0 tag exits, the versions above cExtra are CollectionAssert.AreEqual(v10.GetDirectSuccessors(), i.NextPossibleVersions); } }
public void fumble_commit_plus_an_extra_content_with_a_big_release_number() { var repoTest = TestHelper.TestGitRepository; var cD = repoTest.Commits.First(sc => sc.Message.StartsWith("D-Commit.")); var cC = repoTest.Commits.First(sc => sc.Message.StartsWith("C-Commit.")); var cF = repoTest.Commits.First(sc => sc.Sha == "27a629754c6b9034f7ca580442b589a0241773c5"); var cB = repoTest.Commits.First(sc => sc.Message.StartsWith("B-Commit.")); var cA = repoTest.Commits.First(sc => sc.Message.StartsWith("Merge branch 'fumble-develop' into fumble-master")); var cFix = repoTest.Commits.First(sc => sc.Sha == "e6766d127f9a2df42567151222c6569601614626"); var cX = repoTest.Commits.First(sc => sc.Message.StartsWith("X-Commit.")); var cExtra = repoTest.Commits.First(sc => sc.Message.StartsWith("C-Commit (cherry pick).")); var overrides = new TagsOverride() .MutableAdd(cD.Sha, "v4.3.2") .MutableAdd(cC.Sha, "v4.4.0-alpha") .MutableAdd(cB.Sha, "v5.0.0-rc") .MutableAdd(cA.Sha, "v5.0.0") .MutableAdd(cExtra.Sha, "v10.0.0"); var v5 = ReleaseTagVersion.TryParse("v5.0.0"); var v5rc = ReleaseTagVersion.TryParse("v5.0.0-rc"); var v5rc01 = ReleaseTagVersion.TryParse("v5.0.0-rc.0.1"); var v5rc1 = ReleaseTagVersion.TryParse("v5.0.0-rc.1"); var v10 = ReleaseTagVersion.TryParse("v10.0.0"); { // The injected v10 overrides everything except the possibilty to release the v5.0.0-rc.0.1. RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cFix.Sha }); Assert.That(i.PreviousRelease.ThisTag, Is.EqualTo(v5rc)); Assert.That(i.PreviousMaxRelease.ThisTag, Is.EqualTo(v10)); var possibleStrict = new List <ReleaseTagVersion>() { v5rc01 }; possibleStrict.AddRange(v10.GetDirectSuccessors()); CollectionAssert.AreEqual(possibleStrict, i.PossibleVersionsStrict); var possible = new List <ReleaseTagVersion>() { v5rc01, v5rc1 }; possible.AddRange(v10.GetDirectSuccessors()); CollectionAssert.AreEqual(possible, i.PossibleVersions); } { // On B-Commit: // Restricted Mode: it is the same, v4.4.0-alpha.0.1 and successors of v10. // AllSuccessors Mode: all successors of v4.4.0-alpha (except the v5.0.0) are allowed and successors of v10. var v44a = ReleaseTagVersion.TryParse("v4.4.0-alpha"); var v44a01 = ReleaseTagVersion.TryParse("v4.4.0-alpha.0.1"); var v44a1 = ReleaseTagVersion.TryParse("v4.4.0-alpha.1"); var v500 = ReleaseTagVersion.TryParse("v5.0.0"); RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cB.Sha }); Assert.That(i.PreviousRelease.ThisTag, Is.EqualTo(v44a)); Assert.That(i.PreviousMaxRelease.ThisTag, Is.EqualTo(v10)); var possibleStrict = new List <ReleaseTagVersion>() { v44a01 }; possibleStrict.AddRange(v10.GetDirectSuccessors()); CollectionAssert.AreEqual(possibleStrict, i.PossibleVersionsStrict); var possible = new List <ReleaseTagVersion>(); possible.AddRange(v44a.GetDirectSuccessors().Where(v => v != v500)); possible.AddRange(v10.GetDirectSuccessors()); CollectionAssert.AreEqual(possible, i.PossibleVersions); } }
public void fumble_commit_scenario() { var repoTest = TestHelper.TestGitRepository; var cD = repoTest.Commits.First(sc => sc.Message.StartsWith("D-Commit.")); var cC = repoTest.Commits.First(sc => sc.Message.StartsWith("C-Commit.")); var cF = repoTest.Commits.First(sc => sc.Sha == "27a629754c6b9034f7ca580442b589a0241773c5"); var cB = repoTest.Commits.First(sc => sc.Message.StartsWith("B-Commit.")); var cA = repoTest.Commits.First(sc => sc.Message.StartsWith("Merge branch 'fumble-develop' into fumble-master")); var cFix = repoTest.Commits.First(sc => sc.Sha == "e6766d127f9a2df42567151222c6569601614626"); var cX = repoTest.Commits.First(sc => sc.Message.StartsWith("X-Commit.")); var overrides = new TagsOverride() .MutableAdd(cD.Sha, "v4.3.2") .MutableAdd(cC.Sha, "v4.4.0-alpha") .MutableAdd(cB.Sha, "v5.0.0-rc") .MutableAdd(cA.Sha, "v5.0.0"); var v5 = CSVersion.TryParse("v5.0.0"); var v5rc = CSVersion.TryParse("v5.0.0-rc"); var v5rc01 = CSVersion.TryParse("v5.0.0-rc.0.1"); var v5rc1 = CSVersion.TryParse("v5.0.0-rc.1"); // cX + // | // cFix + This commit point has the same content as cM (the "master"). // | => Publishing any 5.X.X versions from this commit would be silly! // | BetterExistingVersion is here for that! // | // cM | + v5.0.0 - Merge in "master" // | /| // | / | // | / | // |/ | // cB + | v5.0.0-rc // | | // | | // cC + | v4.4.0-alpha // | | // cF | + Fumble Commit (commit in "master" that should have been done on "dev"). // | / // | / // | / // |/ // cD + v4.3.2 { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cFix.Sha }); // Above OR on the fix of the fumble commit, any successor of the 5.0.0 is possible // This iw where BetterExistingVersion must be checked! Assert.That(i.BetterExistingVersion.ThisTag, Is.EqualTo(v5)); CollectionAssert.AreEqual(v5.GetDirectSuccessors(), i.PossibleVersions); CollectionAssert.AreEqual(v5.GetDirectSuccessors(), i.NextPossibleVersions); } { // Above the fix of the fumble commit, any successor of the 5.0.0 is possible. RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cX.Sha }); CollectionAssert.AreEqual(v5.GetDirectSuccessors(), i.PossibleVersions); CollectionAssert.AreEqual(v5.GetDirectSuccessors(), i.NextPossibleVersions); } }
public void ignoring_legacy_versions_with_StartingVersionForCSemVer_option() { var repoTest = TestHelper.TestGitRepository; var c*K = repoTest.Commits.First(sc => sc.Message.StartsWith("Second b/b1")); var cKO1 = repoTest.Commits.First(sc => sc.Message.StartsWith("Second a/a1")); var cKO2 = repoTest.Commits.First(sc => sc.Message.StartsWith("First b/b1")); var cKO3 = repoTest.Commits.First(sc => sc.Message.StartsWith("First a/a2")); var overrides = new TagsOverride() .MutableAdd(c*K.Sha, "4.0.3-beta") .MutableAdd(cKO1.Sha, "0.0.0-alpha") .MutableAdd(cKO2.Sha, "1.1.0") .MutableAdd(cKO3.Sha, "2.0.2"); { RepositoryInfo i = repoTest.GetRepositoryInfo(c*K.Sha, overrides); Assert.That(i.ReleaseTagError, Is.Not.Null); } { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = c*K.Sha, OverriddenTags = overrides.Overrides, StartingVersionForCSemVer = "4.0.3-beta" }); Assert.That(i.ReleaseTagError, Is.Null); Assert.That(i.ValidReleaseTag.ToString(), Is.EqualTo("4.0.3-beta")); //Assert.That( i.CommitVersionInfo.PreviousCommit, Is.Null ); CollectionAssert.AreEqual(i.PossibleVersions.Select(t => t.ToString()), new[] { "4.0.3-beta" }); } { var cAbove = repoTest.Commits.First(sc => sc.Message.StartsWith("Second b/b2")); RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cAbove.Sha, OverriddenTags = overrides.Overrides, StartingVersionForCSemVer = "4.0.3-beta" }); Assert.That(i.ReleaseTagError, Is.Null); Assert.That(i.CommitInfo.BasicInfo.BestCommitBelow.ThisTag.ToString(), Is.EqualTo("4.0.3-beta")); Assert.That(i.ValidReleaseTag, Is.Null); CollectionAssert.Contains(i.PossibleVersions.Select(t => t.ToString()), "4.0.3-beta.0.1", "4.0.3-beta.1", "4.0.3-delta", "4.0.3", "4.1.0-rc", "4.1.0", "5.0.0"); } // Commit before the StartingVersionForCSemVer has no PossibleVersions. { var cBelow = repoTest.Commits.First(sc => sc.Message.StartsWith("On master again")); RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cBelow.Sha, OverriddenTags = overrides.Overrides, StartingVersionForCSemVer = "4.0.3-beta" }); Assert.That(i.ReleaseTagError, Is.Null); Assert.That(i.CommitInfo.BasicInfo, Is.Null); Assert.That(i.ValidReleaseTag, Is.Null); CollectionAssert.IsEmpty(i.PossibleVersions); } { var cBelow = repoTest.Commits.First(sc => sc.Message.StartsWith("Merge branch 'a' into b")); RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cBelow.Sha, OverriddenTags = overrides.Overrides, StartingVersionForCSemVer = "4.0.3-beta" }); Assert.That(i.ReleaseTagError, Is.Null); Assert.That(i.CommitInfo.BasicInfo, Is.Null); Assert.That(i.ValidReleaseTag, Is.Null); CollectionAssert.IsEmpty(i.PossibleVersions); } }
public void repository_with_the_very_first_version_only() { var repoTest = TestHelper.TestGitRepository; var tagged = repoTest.Commits.First(sc => sc.Message.StartsWith("Second b/b1")); var bb1Tag = CSVersion.VeryFirstVersion; var overrides = new TagsOverride().MutableAdd(tagged.Sha, bb1Tag.ToString()); Action <SimpleCommit> checkOK = sc => { var i = repoTest.GetRepositoryInfo(sc.Sha, overrides); Assert.That(i.ValidReleaseTag, Is.Null); CollectionAssert.AreEqual(bb1Tag.GetDirectSuccessors(), i.PossibleVersions); // Now tag the commit and checks that each tag is valid. foreach (var next in bb1Tag.GetDirectSuccessors()) { var iWithTag = repoTest.GetRepositoryInfo(sc.Sha, overrides.Add(sc.Sha, next.ToString())); Assert.That(iWithTag.ValidReleaseTag, Is.EqualTo(next)); } }; Action <SimpleCommit> checkKO = sc => { var i = repoTest.GetRepositoryInfo(sc.Sha, overrides); Assert.That(i.ValidReleaseTag, Is.Null); Assert.That(i.PossibleVersions, Is.Empty); // Now tag the commit and checks that each tag is invalid. foreach (var next in bb1Tag.GetDirectSuccessors()) { var iWithTag = repoTest.GetRepositoryInfo(sc.Sha, overrides.Add(sc.Sha, next.ToString())); Assert.That(iWithTag.ValidReleaseTag, Is.Null); Assert.That(iWithTag.Error, Is.Not.Null); } }; // The version on the commit point. { var i = repoTest.GetRepositoryInfo(tagged.Sha, overrides); Assert.That(i.FinalNuGetVersion.ToString(), Is.EqualTo("0.0.0-a")); CollectionAssert.AreEqual(CSVersion.FirstPossibleVersions, i.PossibleVersions); }; // Checking possible versions before: none. var before1 = repoTest.Commits.First(sc => sc.Message.StartsWith("Merge branch 'a' into b")); checkKO(before1); var before2 = repoTest.Commits.First(sc => sc.Message.StartsWith("Second a/a2")); checkKO(before2); var before3 = repoTest.Commits.First(sc => sc.Message.StartsWith("On master again")); checkKO(before3); // Checking possible versions after: all successors are allowed. var after1 = repoTest.Commits.First(sc => sc.Message.StartsWith("Second b/b2")); checkOK(after1); var after2 = repoTest.Commits.First(sc => sc.Message.StartsWith("Merge branch 'b' into c")); checkOK(after2); var after3 = repoTest.Commits.First(sc => sc.Message.StartsWith("Merge branches 'c', 'd' and 'e'")); checkOK(after3); }
public void CIBuildVersion_with_merged_tags() { var repoTest = TestHelper.TestGitRepository; var cRoot = repoTest.Commits.Single(sc => sc.Message.StartsWith("First in parallel world.")); var cDevInAlpha = repoTest.Commits.Single(sc => sc.Message.StartsWith("Dev in Alpha.")); var cDevInBeta = repoTest.Commits.Single(sc => sc.Message.StartsWith("Dev in Beta.")); var cDevInGamma = repoTest.Commits.Single(sc => sc.Message.StartsWith("Dev in Gamma.")); var overrides = new TagsOverride() .MutableAdd(cRoot.Sha, "v1.0.0") .MutableAdd(cDevInAlpha.Sha, "v2.0.0"); // cDevInBeta // | // | cDevInGamma // | / // |/ cDevInAlpha - v2.0.0 // | / // | / // | / // cRoot - v1.0.0 { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cDevInAlpha.Sha, OverriddenTags = overrides.Overrides }); Assert.That(i.ValidReleaseTag, Is.EqualTo(CSVersion.TryParse("v2.0.0"))); } overrides.MutableAdd(cDevInBeta.Sha, "v1.0.1-beta"); // cDevInBeta - v1.0.1-beta // | // | cDevInGamma // | / // |/ cDevInAlpha - v2.0.0 // | / // | / // cRoot - v1.0.0 { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cDevInBeta.Sha, OverriddenTags = overrides.Overrides }); Assert.That(i.ValidReleaseTag, Is.EqualTo(CSVersion.TryParse("v1.0.1-beta"))); } overrides.MutableAdd(cDevInGamma.Sha, "v1.0.1-alpha"); // cDevInBeta - v1.0.1-beta // | // | cDevInGamma - v1.0.1-alpha // | / // |/ cDevInAlpha - v2.0.0 // | / // | / // cRoot - v1.0.0 { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cDevInGamma.Sha, OverriddenTags = overrides.Overrides }); Assert.That(i.ValidReleaseTag, Is.EqualTo(CSVersion.TryParse("v1.0.1-alpha"))); } // On "gamma" branch, the head is 7 commits ahead of the v2.0.0 tag: this is the longest path. { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingBranchName = "gamma", OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = "gamma", CIVersionMode = CIBranchVersionMode.LastReleaseBased } } }); Assert.That(i.ValidReleaseTag, Is.Null); Assert.That(i.CIRelease.BuildVersion.NormalizedText, Is.EqualTo("2.0.1--ci.7.gamma")); } // Testing "gamma" branch in ZeroTimed mode. { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingBranchName = "gamma", OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = "gamma", CIVersionMode = CIBranchVersionMode.ZeroTimed } } }); Assert.That(i.CIRelease.BuildVersionNuGet.NormalizedTextWithBuildMetaData, Is.EqualTo("0.0.0--009y09h-gamma+v2.0.0")); Assert.That(i.CIRelease.BuildVersion.NormalizedTextWithBuildMetaData, Is.EqualTo("0.0.0--ci.2015-07-13T07-46-29-00.gamma+v2.0.0")); } // On "alpha" branch, the head is 6 commits ahead of the v2.0.0 tag (always the take the longest path). { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingBranchName = "alpha", OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = "alpha", VersionName = "ALPHAAAA", CIVersionMode = CIBranchVersionMode.LastReleaseBased } } }); Assert.That(i.ValidReleaseTag, Is.Null); Assert.That(i.CIRelease.BuildVersion.NormalizedText, Is.EqualTo("2.0.1--ci.6.ALPHAAAA")); } // Testing "alpha" branch in ZeroTimed mode. { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingBranchName = "alpha", OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = "alpha", VersionName = "ALPH", CIVersionMode = CIBranchVersionMode.ZeroTimed } } }); Assert.That(i.CIRelease.BuildVersionNuGet.NormalizedTextWithBuildMetaData, Is.EqualTo("0.0.0--009y6hm-ALPH+v2.0.0")); Assert.That(i.CIRelease.BuildVersion.NormalizedTextWithBuildMetaData, Is.EqualTo("0.0.0--ci.2015-07-13T10-00-58-00.ALPH+v2.0.0")); } // On "beta" branch, the head is 6 commits ahead of the v2.0.0 tag. { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingBranchName = "beta", OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = "beta", VersionName = "BBBBBB", CIVersionMode = CIBranchVersionMode.LastReleaseBased } } }); Assert.That(i.ValidReleaseTag, Is.Null); Assert.That(i.CIRelease.BuildVersion.NormalizedText, Is.EqualTo("2.0.1--ci.6.BBBBBB")); } // Testing ZeroTimed mode on "beta" branch. { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingBranchName = "beta", OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = "beta", VersionName = "beta", CIVersionMode = CIBranchVersionMode.ZeroTimed } } }); Assert.That(i.CIRelease.BuildVersionNuGet.NormalizedText, Is.EqualTo("0.0.0--009y087-beta")); Assert.That(i.CIRelease.BuildVersion.NormalizedTextWithBuildMetaData, Is.EqualTo("0.0.0--ci.2015-07-13T07-45-43-00.beta+v2.0.0")); } }
public void propagation_through_multiple_hops() { var repoTest = TestHelper.TestGitRepository; var cAlpha = repoTest.Commits.First(sc => sc.Message.StartsWith("Real Dev in Alpha.")); // cReleased is "Merge branch 'gamma' into parallel-world" but there are two of them... // This is the head of parallel-world branch. var cReleased = repoTest.Commits.First(sc => sc.Sha == "fc9802013c23398978744de1618fb01638f7347e"); var v1beta = CSVersion.TryParse("1.0.0-beta"); var overrides = new TagsOverride().MutableAdd(cAlpha.Sha, "1.0.0-beta"); // cReleased // | // | // cAlpha - v1.0.0-beta // This is "normal": cReleased has 1.0.0-beta in its parent. { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cReleased.Sha, OverriddenTags = overrides.Overrides }); Assert.That(i.ReleaseTagError, Is.Null); Assert.That(i.CommitInfo.BasicInfo.BestCommitBelow.ThisTag, Is.EqualTo(v1beta)); Assert.That(i.ValidReleaseTag, Is.Null); CollectionAssert.AreEqual(v1beta.GetDirectSuccessors(), i.PossibleVersions); } var cAlphaContinue = repoTest.Commits.First(sc => sc.Message.StartsWith("Dev again in Alpha.")); // We set 2.0.0 on cReleased. Its content is the same as cAlpha (mege commits with no changes). // // cAlphaContinue // | // | cReleased - v2.0.0 // | / // |/ // cAlpha - v1.0.0-beta overrides.MutableAdd(cReleased.Sha, "2.0.0"); { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cReleased.Sha, OverriddenTags = overrides.Overrides }); Assert.That(i.ReleaseTagError, Is.Null); Assert.That(i.ValidReleaseTag.ToString(), Is.EqualTo("2.0.0")); } // Subsequent developments of alpha branch now starts after 2.0.0, for instance 2.1.0-beta. overrides.MutableAdd(cAlphaContinue.Sha, "2.1.0-beta"); { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cAlphaContinue.Sha, OverriddenTags = overrides.Overrides }); var tagged = CSVersion.TryParse("2.1.0-beta"); Assert.That(i.ReleaseTagError, Is.Null); Assert.That(i.ValidReleaseTag, Is.EqualTo(tagged)); // alpha branch can continue with any successors v2.0.0. CollectionAssert.AreEqual(CSVersion.TryParse("2.0.0").GetDirectSuccessors(), i.PossibleVersions); } }