public VersionPoint Execute(GitVersionContext context, DateTimeOffset olderThan)
        {
            var masterBranch = context.Repository.FindBranch("master");

            foreach (var commit in masterBranch.CommitsPriorToThan(olderThan))
            {
                foreach (var tag in context.Repository.TagsByDate(commit))
                {
                    ShortVersion shortVersion;
                    if (ShortVersionParser.TryParseMajorMinor(tag.Name, out shortVersion))
                    {
                        return(new VersionPoint
                        {
                            Major = shortVersion.Major,
                            Minor = shortVersion.Minor,
                        });
                    }
                }

                ShortVersion shortVersionFromMergeMessage;
                if (MergeMessageParser.TryParse(commit, out shortVersionFromMergeMessage))
                {
                    return(new VersionPoint
                    {
                        Major = shortVersionFromMergeMessage.Major,
                        Minor = shortVersionFromMergeMessage.Minor,
                    });
                }
            }
            return(new VersionPoint
            {
                Major = 0,
                Minor = 1,
            });
        }
        static bool IsStableRelease(string tagName)
        {
            int major;
            int minor;

            return(ShortVersionParser.TryParseMajorMinor(tagName, out major, out minor));
        }
        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));
                }
            }

            string versionString;

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

            throw new WarningException("The head of master 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.");
        }
Esempio n. 4
0
        public SemanticVersion FindVersion(GitVersionContext context)
        {
            var versionString = GetSuffix(context.CurrentBranch);
            var shortVersion  = ShortVersionParser.Parse(versionString);

            EnsureVersionIsValid(shortVersion, context.CurrentBranch);
            var semanticVersionPreReleaseTag = "beta.1";

            var nbHotfixCommits = BranchCommitDifferenceFinder.NumberOfCommitsInBranchNotKnownFromBaseBranch(context.Repository, context.CurrentBranch, BranchType.Release, "develop");

            var tagVersion = RecentTagVersionExtractor.RetrieveMostRecentOptionalTagVersion(context.Repository, shortVersion, context.CurrentBranch.Commits.Take(nbHotfixCommits + 1));

            if (tagVersion != null)
            {
                semanticVersionPreReleaseTag = tagVersion;
            }
            return(new SemanticVersion
            {
                Major = shortVersion.Major,
                Minor = shortVersion.Minor,
                Patch = shortVersion.Patch,
                PreReleaseTag = semanticVersionPreReleaseTag,
                BuildMetaData = new SemanticVersionBuildMetaData(nbHotfixCommits, context.CurrentBranch.Name, context.CurrentCommit.Sha, context.CurrentCommit.When())
            });
        }
        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);
        }
        public static bool TryParse(Commit mergeCommit, out ShortVersion shortVersion)
        {
            string versionPart;

            if (Inner(mergeCommit, out versionPart))
            {
                return(ShortVersionParser.TryParse(versionPart, out shortVersion));
            }
            shortVersion = null;
            return(false);
        }
        static VersionPoint BuildFrom(Tag stableTag, Commit commit)
        {
            int major;
            int minor;

            var hasParsed = ShortVersionParser.TryParseMajorMinor(stableTag.Name, out major, out minor);

            Debug.Assert(hasParsed);

            return(new VersionPoint
            {
                Major = major,
                Minor = minor,
                CommitSha = commit.Id.Sha,
            });
        }
        static DateTimeOffset GetTimeStampFromTag(IRepository repository, Commit targetCommit)
        {
            var allMajorMinorTags = repository.Tags
                                    .Where(x => ShortVersionParser.IsMajorMinor(x.Name))
                                    .ToDictionary(x => x.PeeledTarget(), x => x);
            var olderThan = targetCommit.When();

            foreach (var commit in repository.Head.Commits.Where(x => x.When() <= olderThan))
            {
                if (IsMajorMinor(commit, allMajorMinorTags))
                {
                    return(commit.When());
                }
            }
            return(DateTimeOffset.MinValue);
        }
        public VersionPoint Execute(GitVersionContext context, DateTimeOffset olderThan)
        {
            var masterBranch = context.Repository.FindBranch("master");

            foreach (var commit in masterBranch.CommitsPriorToThan(olderThan))
            {
                foreach (var tag in context.Repository.TagsByDate(commit))
                {
                    int major;
                    int minor;
                    if (ShortVersionParser.TryParseMajorMinor(tag.Name, out major, out minor))
                    {
                        return(new VersionPoint
                        {
                            Major = major,
                            Minor = minor,
                            Timestamp = commit.When(),
                            CommitSha = commit.Sha,
                        });
                    }
                }
                string versionString;
                if (MergeMessageParser.TryParse(commit, out versionString))
                {
                    int major;
                    int minor;
                    if (ShortVersionParser.TryParseMajorMinor(versionString, out major, out minor))
                    {
                        return(new VersionPoint
                        {
                            Major = major,
                            Minor = minor,
                            Timestamp = commit.When(),
                            CommitSha = commit.Sha,
                        });
                    }
                }
            }
            return(new VersionPoint
            {
                Major = 0,
                Minor = 1,
                Timestamp = DateTimeOffset.MinValue,
                CommitSha = null,
            });
        }
Esempio n. 10
0
        public SemanticVersion FindVersion(IRepository repository, Commit tip)
        {
            foreach (var tag in repository.TagsByDate(tip))
            {
                ShortVersion shortVersion;
                if (ShortVersionParser.TryParse(tag.Name, out shortVersion))
                {
                    return(BuildVersion(tip, shortVersion));
                }
            }

            ShortVersion versionFromTip;

            if (MergeMessageParser.TryParse(tip, out versionFromTip))
            {
                return(BuildVersion(tip, versionFromTip));
            }
            throw new WarningException("The head of master 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.");
        }
Esempio n. 11
0
        public SemanticVersion FindVersion(GitVersionContext context)
        {
            var versionString = GetSuffix(context.CurrentBranch);
            var shortVersion  = ShortVersionParser.Parse(versionString);

            EnsureVersionIsValid(shortVersion, context.CurrentBranch);

            var nbHotfixCommits = BranchCommitDifferenceFinder.NumberOfCommitsInBranchNotKnownFromBaseBranch(context.Repository, context.CurrentBranch, BranchType.Hotfix, "master");

            var semanticVersionPreReleaseTag = GetSemanticVersionPreReleaseTag(context, shortVersion, nbHotfixCommits);

            return(new SemanticVersion
            {
                Major = shortVersion.Major,
                Minor = shortVersion.Minor,
                Patch = shortVersion.Patch,
                PreReleaseTag = semanticVersionPreReleaseTag,
                BuildMetaData = new SemanticVersionBuildMetaData(nbHotfixCommits, context.CurrentBranch.Name, context.CurrentCommit.Sha, context.CurrentCommit.When())
            });
        }
        public bool FindVersion(GitVersionContext context, out SemanticVersion semanticVersion)
        {
            var versionString = GetUnknownBranchSuffix(context.CurrentBranch);

            if (!versionString.Contains("."))
            {
                semanticVersion = null;
                return(false);
            }
            var shortVersion = ShortVersionParser.Parse(versionString);

            SemanticVersionPreReleaseTag semanticVersionPreReleaseTag = context.CurrentBranch.Name.Replace("-" + versionString, string.Empty) + ".1";

            var nbHotfixCommits = BranchCommitDifferenceFinder.NumberOfCommitsInBranchNotKnownFromBaseBranch(context.Repository, context.CurrentBranch, BranchType.Unknown, "master");

            var tagVersion = RecentTagVersionExtractor.RetrieveMostRecentOptionalTagVersion(context.Repository, shortVersion, context.CurrentBranch.Commits.Take(nbHotfixCommits + 1));

            if (tagVersion != null)
            {
                semanticVersionPreReleaseTag = tagVersion;
            }

            if (semanticVersionPreReleaseTag.Name == "release")
            {
                semanticVersionPreReleaseTag.Name = "beta";
            }

            semanticVersion = new SemanticVersion
            {
                Major         = shortVersion.Major,
                Minor         = shortVersion.Minor,
                Patch         = shortVersion.Patch,
                PreReleaseTag = semanticVersionPreReleaseTag,
                BuildMetaData = new SemanticVersionBuildMetaData(nbHotfixCommits, context.CurrentBranch.Name, context.CurrentCommit.Sha, context.CurrentCommit.When())
            };
            return(true);
        }
        static bool IsStableRelease(string tagName)
        {
            ShortVersion shortVersion;

            return(ShortVersionParser.TryParseMajorMinor(tagName, out shortVersion));
        }