Exemple #1
0
        public bool FindVersion(GitVersionContext context, SemanticVersion defaultNextVersion, out SemanticVersion semanticVersion)
        {
            var versionInBranch = GetVersionInBranch(context);

            if (versionInBranch == null)
            {
                if (!context.CurrentBranch.IsMaster())
                {
                    defaultNextVersion.PreReleaseTag = context.CurrentBranch.Name.Split('/').Last();
                }
                semanticVersion = null;

                return(false);
            }

            var applicableTagsInDescendingOrder = context.Repository.SemVerTagsRelatedToVersion(context.Configuration, versionInBranch.Item2).OrderByDescending(tag => SemanticVersion.Parse(tag.Name, context.Configuration.TagPrefix)).ToList();
            var nbHotfixCommits = BranchCommitDifferenceFinder.NumberOfCommitsSinceLastTagOrBranchPoint(context, applicableTagsInDescendingOrder, BranchType.Unknown, "master");
            var semanticVersionPreReleaseTag = RecentTagVersionExtractor.RetrieveMostRecentOptionalTagVersion(context, applicableTagsInDescendingOrder) ?? CreateDefaultPreReleaseTag(context, versionInBranch.Item1);


            if (semanticVersionPreReleaseTag.Name == "release")
            {
                semanticVersionPreReleaseTag.Name = context.Configuration.ReleaseBranchTag;
            }

            semanticVersion = new SemanticVersion
            {
                Major         = versionInBranch.Item2.Major,
                Minor         = versionInBranch.Item2.Minor,
                Patch         = versionInBranch.Item2.Patch,
                PreReleaseTag = semanticVersionPreReleaseTag,
                BuildMetaData = new SemanticVersionBuildMetaData(nbHotfixCommits, context.CurrentBranch.Name, context.CurrentCommit.Sha, context.CurrentCommit.When())
            };
            return(true);
        }
        public SemanticVersion FindVersion(GitVersionContext context)
        {
            var versionString = GetSuffix(context.CurrentBranch);
            var shortVersion  = SemanticVersion.Parse(versionString, context.Configuration.TagPrefix);

            EnsureVersionIsValid(shortVersion, context.CurrentBranch);

            var applicableTagsInDescendingOrder          = context.Repository.SemVerTagsRelatedToVersion(context.Configuration, shortVersion).OrderByDescending(tag => SemanticVersion.Parse(tag.Name, context.Configuration.TagPrefix)).ToList();
            var numberOfCommitsSinceLastTagOrBranchPoint = BranchCommitDifferenceFinder.NumberOfCommitsSinceLastTagOrBranchPoint(context, applicableTagsInDescendingOrder, BranchType.Release, "develop");
            var semanticVersionPreReleaseTag             = RecentTagVersionExtractor.RetrieveMostRecentOptionalTagVersion(context, applicableTagsInDescendingOrder) ?? context.Configuration.ReleaseBranchTag + ".1";

            return(new SemanticVersion
            {
                Major = shortVersion.Major,
                Minor = shortVersion.Minor,
                Patch = shortVersion.Patch,
                PreReleaseTag = semanticVersionPreReleaseTag,
                BuildMetaData = new SemanticVersionBuildMetaData(numberOfCommitsSinceLastTagOrBranchPoint, context.CurrentBranch.Name, context.CurrentCommit.Sha, context.CurrentCommit.When())
            });
        }