protected SemanticVersion FindVersion(
            GitVersionContext context,
            BranchType branchType)
        {
            var ancestor = FindCommonAncestorWithDevelop(context.Repository, context.CurrentBranch, branchType);

            if (!IsThereAnyCommitOnTheBranch(context.Repository, context.CurrentBranch))
            {
                var developVersionFinder = new DevelopVersionFinder();
                return developVersionFinder.FindVersion(context);
            }

            var versionOnMasterFinder = new VersionOnMasterFinder();
            var versionFromMaster = versionOnMasterFinder.Execute(context, context.CurrentBranch.Tip.Committer.When);

            var numberOfCommitsOnBranchSinceCommit = NumberOfCommitsOnBranchSinceCommit(context, ancestor);
            var sha = context.CurrentBranch.Tip.Sha;
            var releaseDate = ReleaseDateFinder.Execute(context.Repository, sha, 0);
            var semanticVersion = new SemanticVersion
            {
                Major = versionFromMaster.Major,
                Minor = versionFromMaster.Minor + 1,
                Patch = 0,
                PreReleaseTag = "unstable0",
                BuildMetaData = new SemanticVersionBuildMetaData(
                    numberOfCommitsOnBranchSinceCommit,
                    context.CurrentBranch.Name, releaseDate)
            };

            return semanticVersion;
        }
Exemplo n.º 2
0
 public void Commit_on_develop_and_previous_commit_on_master_is_a_hotfix()
 {
     var commitOnDevelop = new MockCommit
                           {
                               CommitterEx = 1.Seconds().Ago().ToSignature()
                           };
     var finder = new DevelopVersionFinder();
     var mockBranch = new MockBranch("develop")
     {
         commitOnDevelop
     };
     var version = finder.FindVersion(new GitVersionContext
     {
         Repository = new MockRepository
         {
             Branches = new MockBranchCollection
             {
                 new MockBranch("master")
                 {
                     new MockMergeCommit
                     {
                         MessageEx = "hotfix-0.1.1",
                         CommitterEx = 2.Seconds().Ago().ToSignature()
                     }
                 },
                 mockBranch
             },
         },
         CurrentBranch = mockBranch
     });
     Assert.AreEqual(2, version.Minor, "Minor should be master.Minor+1");
     ObjectApprover.VerifyWithJson(version, Scrubbers.GuidAndDateScrubber);
 }
        protected SemanticVersion FindVersion(
            GitVersionContext context,
            BranchType branchType)
        {
            var ancestor = FindCommonAncestorWithDevelop(context.Repository, context.CurrentBranch, branchType);

            if (!IsThereAnyCommitOnTheBranch(context.Repository, context.CurrentBranch))
            {
                var developVersionFinder = new DevelopVersionFinder();
                return developVersionFinder.FindVersion(context);
            }

            var versionOnMasterFinder = new VersionOnMasterFinder();
            var versionFromMaster = versionOnMasterFinder.Execute(context, context.CurrentCommit.When());

            var numberOfCommitsOnBranchSinceCommit = NumberOfCommitsOnBranchSinceCommit(context, ancestor);
            var preReleaseTag = context.CurrentBranch.Name
                .TrimStart(branchType.ToString() + '-')
                .TrimStart(branchType.ToString() + '/');
            var semanticVersion = new SemanticVersion
            {
                Major = versionFromMaster.Major,
                Minor = versionFromMaster.Minor + 1,
                Patch = 0,
                PreReleaseTag = preReleaseTag,
                BuildMetaData = new SemanticVersionBuildMetaData(
                    numberOfCommitsOnBranchSinceCommit,
                    context.CurrentBranch.Name, context.CurrentCommit.Sha, context.CurrentCommit.When())
            };

            semanticVersion.OverrideVersionManuallyIfNeeded(context.Repository, context.Configuration);

            return semanticVersion;
        }
Exemplo n.º 4
0
    public void Commit_on_develop_and_previous_commit_on_master_has_a_tag()
    {
        var commitOnDevelop = new MockCommit
                              {
                                  CommitterEx = 1.Seconds().Ago().ToSignature()
                              };
        var commitOnMaster = new MockCommit
                             {
                                 CommitterEx = 2.Seconds().Ago().ToSignature()
                             };
        var finder = new DevelopVersionFinder();
        var develop = new MockBranch("develop")
        {
            commitOnDevelop
        };
        var context = new GitVersionContext
        {
            Repository = new MockRepository
            {
                Branches = new MockBranchCollection
                {
                    new MockBranch("master")
                    {
                        commitOnMaster
                    },
                    develop
                },
                Tags = new MockTagCollection
                {
                    new MockTag
                    {
                        TargetEx = commitOnMaster,
                        NameEx = "0.1.0"
                    }
                }
            },
            CurrentBranch = develop
        };

        var version = finder.FindVersion(context);
        Assert.AreEqual(2, version.Minor, "Minor should be master.Minor+1");
        ObjectApprover.VerifyWithJson(version, Scrubbers.GuidAndDateScrubber);
    }
Exemplo n.º 5
0
        protected SemanticVersion FindVersion(
            GitVersionContext context,
            BranchType branchType)
        {
            var ancestor = FindCommonAncestorWithDevelop(context.Repository, context.CurrentBranch, branchType);

            if (!IsThereAnyCommitOnTheBranch(context.Repository, context.CurrentBranch))
            {
                var developVersionFinder = new DevelopVersionFinder();
                return(developVersionFinder.FindVersion(context));
            }

            var versionOnMasterFinder = new VersionOnMasterFinder();
            var versionFromMaster     = versionOnMasterFinder.Execute(context, context.CurrentCommit.Committer.When);

            var numberOfCommitsOnBranchSinceCommit = NumberOfCommitsOnBranchSinceCommit(context, ancestor);
            var sha           = context.CurrentCommit.Sha;
            var releaseDate   = ReleaseDateFinder.Execute(context.Repository, sha, 0);
            var preReleaseTag = context.CurrentBranch.Name
                                .TrimStart(branchType.ToString() + '-')
                                .TrimStart(branchType.ToString() + '/');
            var semanticVersion = new SemanticVersion
            {
                Major         = versionFromMaster.Major,
                Minor         = versionFromMaster.Minor + 1,
                Patch         = 0,
                PreReleaseTag = preReleaseTag,
                BuildMetaData = new SemanticVersionBuildMetaData(
                    numberOfCommitsOnBranchSinceCommit,
                    context.CurrentBranch.Name, releaseDate)
            };

            semanticVersion.OverrideVersionManuallyIfNeeded(context.Repository);

            return(semanticVersion);
        }