public SemanticVersion FindVersion(GitVersionContext context)
        {
            var versionOnMasterFinder = new VersionOnMasterFinder();
            var tip = context.CurrentCommit;
            var versionFromMaster = versionOnMasterFinder.Execute(context, tip.When());

            var f = new CommitFilter
            {
                Since  = tip,
                Until  = context.Repository.FindBranch("master").Tip,
                SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Time
            };

            var c = context.Repository.Commits.QueryBy(f);
            var numberOfCommitsSinceRelease = c.Count();

            var semanticVersion = new SemanticVersion
            {
                Major         = versionFromMaster.Major,
                Minor         = versionFromMaster.Minor + 1,
                Patch         = 0,
                PreReleaseTag = context.Configuration.DevelopBranchTag + numberOfCommitsSinceRelease,
                BuildMetaData = new SemanticVersionBuildMetaData(numberOfCommitsSinceRelease, context.CurrentBranch.Name, tip.Sha, tip.When()),
            };

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

            return(semanticVersion);
        }
        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);
        }
        public SemanticVersion FindVersion(IRepository repository, Commit tip)
        {
            int major;
            int minor;
            int patch;

            foreach (var tag in repository.TagsByDate(tip))
            {
                if (ShortVersionParser.TryParse(tag.Name, out major, out minor, out patch))
                {
                    return(BuildVersion(repository, tip, major, minor, patch));
                }
            }

            var semanticVersion = new SemanticVersion();

            string versionString;

            if (MergeMessageParser.TryParse(tip, out versionString))
            {
                if (ShortVersionParser.TryParse(versionString, out major, out minor, out patch))
                {
                    semanticVersion = BuildVersion(repository, tip, major, minor, patch);
                }
            }

            semanticVersion.OverrideVersionManuallyIfNeeded(repository);

            if (semanticVersion == null || semanticVersion.IsEmpty())
            {
                throw new WarningException("The head of a support branch should always be a merge commit if you follow gitflow. Please create one or work around this by tagging the commit with SemVer compatible Id.");
            }

            return(semanticVersion);
        }