Exemplo n.º 1
0
        public void Execute(string[] arguments)
        {
            var topCommit = _git.GetTopCommitInfo();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine($"latest ({topCommit.Trim()})");
            Console.WriteLine();

            var allTags       = _git.GetTags();
            var allLatestTags = allTags
                                .OrderBy(x => x.Major)
                                .ThenBy(x => x.Minor)
                                .ThenBy(x => x.Patch)
                                .ThenBy(x => x.Version)
                                .GroupBy(x => x.Label)
                                .Select(x => x.Last())
                                .Select(x => (x, _git.GetCommitsBehind(x.ToString())))
                                .OrderBy(tuple => tuple.x.Label)
                                .ThenBy(tuple => tuple.Item2)
                                .Select(tuple => tuple.x)
                                .ToList();

            allLatestTags.Reverse();

            allLatestTags.ForEach(x =>
            {
                var tagInfo = _git.GetTagInfo(x.ToString());

                Console.ForegroundColor = tagInfo.StartsWith(topCommit)
                        ? ConsoleColor.Green
                        : ConsoleColor.DarkYellow;

                Console.WriteLine($"{x} ({tagInfo.Trim()})");
            });

            Console.ResetColor();
        }
Exemplo n.º 2
0
        public void Execute(string[] arguments)
        {
            string revision;
            string label = null;

            var newMajorVersion = arguments.Any(x =>
                                                x == "-X" ||
                                                x == "--next-major-version");

            if (_place == Place.Version)
            {
                label = arguments.FirstOrDefault(x =>
                                                 !x.Equals("--dry-run") &&
                                                 !x.Equals("-d") &&
                                                 !x.Equals("--next-major-version") &&
                                                 !x.Equals("-X"));

                revision = arguments.FirstOrDefault(x =>
                                                    !x.Equals(label) &&
                                                    !x.Equals("--dry-run") &&
                                                    !x.Equals("-d") &&
                                                    !x.Equals("--next-major-version") &&
                                                    !x.Equals("-X"));
            }
            else
            {
                revision = arguments.FirstOrDefault(x =>
                                                    !x.Equals("--dry-run") &&
                                                    !x.Equals("-d"));
            }

            if (_place == Place.Version && string.IsNullOrEmpty(label))
            {
                throw new Exception("No label given, cannot increment Version");
            }

            var allTags     = _git.GetTags();
            Tag revisionTag = null;

            if (!string.IsNullOrEmpty(revision))
            {
                revisionTag = allTags.SingleOrDefault(x =>
                                                      x.ToString().Equals(revision) ||
                                                      (x.Label?.Equals(revision, StringComparison.InvariantCultureIgnoreCase)).GetValueOrDefault(false));

                if (revisionTag == null)
                {
                    throw new Exception("Cannot find a commit with revision or label " + revision);
                }
            }

            var specificTags = string.IsNullOrEmpty(label)
                ? allTags.Where(x => string.IsNullOrEmpty(x.Label))
                : allTags.Where(x => x.Label.ToLowerInvariant().Equals(label) || string.IsNullOrEmpty(x.Label));

            var latestTag = specificTags
                            .OrderBy(x => x.Major)
                            .ThenBy(x => x.Minor)
                            .ThenBy(x => x.Patch)
                            .ThenBy(x => x.Version)
                            .LastOrDefault();

            var newTag = latestTag == null
                ? GetNewTag(label)
                : latestTag.Increment(_place, label, newMajorVersion);

            _git.NewTag(newTag.ToString(), revisionTag?.ToString());
            _git.Push();
            _git.PushTag(newTag.ToString());
        }