コード例 #1
0
        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.");
        }
コード例 #2
0
        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,
            });
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 static IEnumerable <ShortVersion> GetAllVersions(GitVersionContext context)
 {
     foreach (var commit in context.CurrentBranch.Commits)
     {
         ShortVersion version;
         if (MergeMessageParser.TryParse(commit, out version))
         {
             yield return(version);
         }
     }
 }
コード例 #5
0
        static bool IsMajorMinor(Commit commit, Dictionary <GitObject, Tag> allMajorMinorTags, Config configuration)
        {
            SemanticVersion version;

            if (MergeMessageParser.TryParse(commit, configuration, out version))
            {
                if (version.Patch == 0)
                {
                    return(true);
                }
            }
            return(allMajorMinorTags.ContainsKey(commit));
        }
コード例 #6
0
 SemanticVersion GetVersion(GitVersionContext context)
 {
     return(context.CurrentBranch.Commits.Where(c =>
     {
         string versionPart;
         SemanticVersion semanticVersion;
         return MergeMessageParser.TryParse(c, out versionPart) && SemanticVersion.TryParse(versionPart, out semanticVersion);
     })
            .Select(c =>
     {
         string versionPart;
         MergeMessageParser.TryParse(c, out versionPart);
         return SemanticVersion.Parse(versionPart);
     })
            .Max());
 }
コード例 #7
0
        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,
            });
        }
コード例 #8
0
        public SemanticVersion FindVersion(GitVersionContext context)
        {
            foreach (var tag in context.Repository.TagsByDate(context.CurrentCommit))
            {
                SemanticVersion shortVersion;
                if (SemanticVersion.TryParse(tag.Name, context.Configuration.TagPrefix, out shortVersion))
                {
                    return(BuildVersion(context.CurrentCommit, shortVersion));
                }
            }

            SemanticVersion versionFromTip;

            if (MergeMessageParser.TryParse(context.CurrentCommit, context.Configuration, out versionFromTip))
            {
                return(BuildVersion(context.CurrentCommit, 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.");
        }
コード例 #9
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.");
        }
コード例 #10
0
        public SemanticVersion FindVersion(IRepository repository, Commit tip, Config configuration)
        {
            foreach (var tag in repository.TagsByDate(tip))
            {
                SemanticVersion shortVersion;
                if (SemanticVersion.TryParse(tag.Name, configuration.TagPrefix, out shortVersion))
                {
                    return(BuildVersion(tip, shortVersion));
                }
            }

            SemanticVersion versionFromTip;

            if (MergeMessageParser.TryParse(tip, configuration, out versionFromTip))
            {
                var semanticVersion = BuildVersion(tip, versionFromTip);
                semanticVersion.OverrideVersionManuallyIfNeeded(repository, configuration);
                return(semanticVersion);
            }
            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.");
        }