Esempio n. 1
0
        public void ShouldFilterVersion()
        {
            var fakeIgnoreConfig = new TestIgnoreConfig(new ExcludeSourcesContainingExclude());

            var higherVersion = new BaseVersion("exclude", false, new SemanticVersion(2), GitToolsTestingExtensions.CreateMockCommit(), null);
            var lowerVersion  = new BaseVersion("dummy", false, new SemanticVersion(1), GitToolsTestingExtensions.CreateMockCommit(), null);

            var versionCalculator = GetBaseVersionCalculator(contextBuilder =>
            {
                contextBuilder
                .WithConfig(new Config {
                    Ignore = fakeIgnoreConfig
                })
                .OverrideServices(services =>
                {
                    services.RemoveAll <IVersionStrategy>();
                    services.AddSingleton <IVersionStrategy>(new TestVersionStrategy(higherVersion, lowerVersion));
                });
            });
            var baseVersion = versionCalculator.GetBaseVersion();

            baseVersion.Source.ShouldNotBe(higherVersion.Source);
            baseVersion.SemanticVersion.ShouldNotBe(higherVersion.SemanticVersion);
            baseVersion.Source.ShouldBe(lowerVersion.Source);
            baseVersion.SemanticVersion.ShouldBe(lowerVersion.SemanticVersion);
        }
        public static VersionField? DetermineIncrementedField(GitVersionContext context, BaseVersion baseVersion)
        {
            var commitMessageIncrement = FindCommitMessageIncrement(context, baseVersion);
            var defaultIncrement = context.Configuration.Increment.ToVersionField();

            // use the default branch config increment strategy if there are no commit message overrides
            if (commitMessageIncrement == null)
            {
                return baseVersion.ShouldIncrement ? defaultIncrement : (VersionField?)null;
            }

            // cap the commit message severity to minor for alpha versions
            if (baseVersion.SemanticVersion < new SemanticVersion(1) && commitMessageIncrement > VersionField.Minor)
            {
                commitMessageIncrement = VersionField.Minor;
            }

            // don't increment for less than the branch config increment, if the absence of commit messages would have
            // still resulted in an increment of configuration.Increment
            if (baseVersion.ShouldIncrement && commitMessageIncrement < defaultIncrement)
            {
                return defaultIncrement;
            }

            return commitMessageIncrement;
        }
        private static VersionField? FindCommitMessageIncrement(GitVersionContext context, BaseVersion baseVersion)
        {
            if (context.Configuration.CommitMessageIncrementing == CommitMessageIncrementMode.Disabled)
            {
                return null;
            }

            var commits = GetIntermediateCommits(context.Repository, baseVersion.BaseVersionSource, context.CurrentCommit);

            if (context.Configuration.CommitMessageIncrementing == CommitMessageIncrementMode.MergeMessageOnly)
            {
                commits = commits.Where(c => c.Parents.Count() > 1);
            }

            var majorRegex = CreateRegex(context.Configuration.MajorVersionBumpMessage ?? DefaultMajorPattern);
            var minorRegex = CreateRegex(context.Configuration.MinorVersionBumpMessage ?? DefaultMinorPattern);
            var patchRegex = CreateRegex(context.Configuration.PatchVersionBumpMessage ?? DefaultPatchPattern);

            var increments = commits
                .Select(c => FindIncrementFromMessage(c.Message, majorRegex, minorRegex, patchRegex))
                .Where(v => v != null)
                .Select(v => v.Value)
                .ToList();

            if (increments.Any())
            {
                return increments.Max();
            }

            return null;
        }
Esempio n. 4
0
        /// <summary>
        /// base callback when an attribute has been read
        /// </summary>
        /// <param name="element">element of the attribute</param>
        /// <param name="attributeName"></param>
        private void AttributesCallback(Element element)
        {
            if (element.Name == "Configuration")
            {
                if (element.Attributes.ContainsKey("version"))
                {
                    BaseVersion version = null;

                    switch (element.Attributes["version"])
                    {
                    case "1.1.0.0":
                        version = new Version_1_1_0_0(_configuration);
                        break;

                    case "1.2.0.0":
                        version = new Version_1_2_0_0(_configuration);
                        break;
                    }

                    if (version != null)
                    {
                        _elementReadCallback = version.ElementCallback;
                    }
                }
            }
        }
Esempio n. 5
0
 protected Base(string name, string description, string imageUrl, BaseVersion version)
 {
     Name        = name;
     Description = description;
     Version     = version;
     ImageUrl    = imageUrl;
 }
Esempio n. 6
0
        public void ShouldFilterVersion()
        {
            var fakeIgnoreConfig = new TestIgnoreConfig(new ExcludeSourcesContainingExclude());
            var context          = new GitVersionContextBuilder().WithConfig(new Config
            {
                Ignore = fakeIgnoreConfig
            }).Build();
            var higherVersion = new BaseVersion(context, "exclude", false, new SemanticVersion(2), new MockCommit(), null);
            var lowerVersion  = new BaseVersion(context, "dummy", false, new SemanticVersion(1), new MockCommit(), null);

            var sp = ConfigureServices(services =>
            {
                services.RemoveAll <IVersionStrategy>();
                services.AddSingleton <IVersionStrategy>(new TestVersionStrategy(higherVersion, lowerVersion));
            });

            var versionCalculator = sp.GetService <IBaseVersionCalculator>();

            var baseVersion = versionCalculator.GetBaseVersion(context);

            baseVersion.Source.ShouldNotBe(higherVersion.Source);
            baseVersion.SemanticVersion.ShouldNotBe(higherVersion.SemanticVersion);
            baseVersion.Source.ShouldBe(lowerVersion.Source);
            baseVersion.SemanticVersion.ShouldBe(lowerVersion.SemanticVersion);
        }
Esempio n. 7
0
        public string ToString(int fieldCount)
        {
            if (fieldCount > 5 || fieldCount < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(fieldCount));
            }

            var sb = new StringBuilder();

            sb.Append(BaseVersion.ToString(Math.Min(fieldCount, 4)));

            if (fieldCount == 5)
            {
                if (PreReleaseVersion == 0)
                {
                    sb.Append(DevReleaseTag);
                }
                else
                {
                    sb.Append(PreReleaseTag);
                    sb.Append(Math.Max(PreReleaseVersion, 0));
                }
            }

            return(sb.ToString());
        }
Esempio n. 8
0
    public void ExcludeShouldAcceptVersionWithNullCommit()
    {
        var version = new BaseVersion("dummy", false, new SemanticVersion(1), null, string.Empty);
        var sut     = new ShaVersionFilter(new[] { "mismatched" });

        sut.Exclude(version, out var reason).ShouldBeFalse();
        reason.ShouldBeNull();
    }
Esempio n. 9
0
 void SetPackage(BaseVersion desiredVersion)
 {
     if (Model.Controller.Package == null)
     {
         return;
     }
     Model.Controller.Package.UpdateLocalDependency(desiredVersion);
 }
Esempio n. 10
0
        public void ExcludeShouldAcceptVersionWithNullCommit()
        {
            var version    = new BaseVersion("dummy", false, new SemanticVersion(1), null, string.Empty);
            var futureDate = DateTimeOffset.UtcNow.AddYears(1);
            var sut        = new MinDateVersionFilter(futureDate);

            sut.Exclude(version, out var reason).ShouldBeFalse();
            reason.ShouldBeNull();
        }
Esempio n. 11
0
        SpecificVersion GetActual(BaseVersion current)
        {
            if (current == _latestJoker)
            {
                return(GetLatestDependency());
            }

            return(current == _latestAnyJoker?GetLatestAnyDependency() : current.ToSpecificVersion());
        }
Esempio n. 12
0
    public void WhenShaMatchShouldExcludeWithReason()
    {
        var commit  = GitToolsTestingExtensions.CreateMockCommit();
        var version = new BaseVersion("dummy", false, new SemanticVersion(1), commit, string.Empty);
        var sut     = new ShaVersionFilter(new[] { commit.Sha });

        sut.Exclude(version, out var reason).ShouldBeTrue();
        reason.ShouldNotBeNullOrWhiteSpace();
    }
Esempio n. 13
0
    public void WhenShaMismatchShouldNotExclude()
    {
        var commit  = GitToolsTestingExtensions.CreateMockCommit();
        var version = new BaseVersion("dummy", false, new SemanticVersion(1), commit, string.Empty);
        var sut     = new ShaVersionFilter(new[] { "mismatched" });

        sut.Exclude(version, out var reason).ShouldBeFalse();
        reason.ShouldBeNull();
    }
Esempio n. 14
0
        public void ExcludeShouldAcceptVersionWithNullCommit()
        {
            var version = new BaseVersion("dummy", new SemanticVersion(1), null);
            var sut     = new HashVersionFilter(new[] { "mismatched" });

            var result = sut.Exclude(version, out var reason);

            Assert.That(result, Is.False);
            Assert.That(reason, Is.Null);
        }
Esempio n. 15
0
        public void WhenShaMismatchShouldNotExclude()
        {
            var commit   = GitToolsTestingExtensions.CreateMockCommit();
            var version  = new BaseVersion("dummy", false, new SemanticVersion(1), commit, string.Empty);
            var pastDate = DateTimeOffset.UtcNow.AddYears(-1);
            var sut      = new MinDateVersionFilter(pastDate);

            sut.Exclude(version, out var reason).ShouldBeFalse();
            reason.ShouldBeNull();
        }
Esempio n. 16
0
        public void WhenShaMismatchShouldNotExclude()
        {
            var commit  = new MockCommit();
            var context = new GitVersionContextBuilder().Build();
            var version = new BaseVersion(context, "dummy", false, new SemanticVersion(1), commit, string.Empty);
            var sut     = new ShaVersionFilter(new[] { "mismatched" });

            sut.Exclude(version, out var reason).ShouldBeFalse();
            reason.ShouldBeNull();
        }
Esempio n. 17
0
        public void WhenShaMatchShouldExcludeWithReason()
        {
            var commit  = new MockCommit();
            var context = new GitVersionContextBuilder().Build();
            var version = new BaseVersion(context, "dummy", false, new SemanticVersion(1), commit, string.Empty);
            var sut     = new ShaVersionFilter(new[] { commit.Sha });

            sut.Exclude(version, out var reason).ShouldBeTrue();
            reason.ShouldNotBeNullOrWhiteSpace();
        }
Esempio n. 18
0
        public void WhenCommitShouldExcludeWithReason()
        {
            var commit     = GitToolsTestingExtensions.CreateMockCommit();
            var version    = new BaseVersion("dummy", false, new SemanticVersion(1), commit, string.Empty);
            var futureDate = DateTimeOffset.UtcNow.AddYears(1);
            var sut        = new MinDateVersionFilter(futureDate);

            sut.Exclude(version, out var reason).ShouldBeTrue();
            reason.ShouldNotBeNullOrWhiteSpace();
        }
Esempio n. 19
0
 private static SemanticVersion PerformIncrement(GitVersionContext context, BaseVersion baseVersion)
 {
     var semver = baseVersion.SemanticVersion;
     var increment = IncrementStrategyFinder.DetermineIncrementedField(context, baseVersion);
     if (increment != null)
     {
         semver = semver.IncrementVersion(increment.Value);
     }
     else Logger.WriteInfo("Skipping version increment");
     return semver;
 }
Esempio n. 20
0
        public void ExcludeShouldAcceptVersionWithNullCommit()
        {
            var version    = new BaseVersion("dummy", new SemanticVersion(1), null);
            var futureDate = DateTimeOffset.UtcNow.AddYears(1);
            var sut        = new MinDateVersionFilter(futureDate);

            var result = sut.Exclude(version, out var reason);

            Assert.That(result, Is.False);
            Assert.That(reason, Is.Null);
        }
Esempio n. 21
0
            public bool Exclude(BaseVersion version, out string reason)
            {
                reason = null;

                if (version.Source.Contains("exclude"))
                {
                    reason = "was excluded";
                    return(true);
                }
                return(false);
            }
        public void WhenShaMismatchShouldNotExclude()
        {
            var commit   = new MockCommit(); //when = UtcNow
            var context  = new GitVersionContextBuilder().Build();
            var version  = new BaseVersion(context, "dummy", false, new SemanticVersion(1), commit, string.Empty);
            var pastDate = DateTimeOffset.UtcNow.AddYears(-1);
            var sut      = new MinDateVersionFilter(pastDate);

            sut.Exclude(version, out var reason).ShouldBeFalse();
            reason.ShouldBeNull();
        }
        public void WhenCommitShouldExcludeWithReason()
        {
            var context    = new GitVersionContextBuilder().Build();
            var commit     = new MockCommit(); //when = UtcNow
            var version    = new BaseVersion(context, "dummy", false, new SemanticVersion(1), commit, string.Empty);
            var futureDate = DateTimeOffset.UtcNow.AddYears(1);
            var sut        = new MinDateVersionFilter(futureDate);

            sut.Exclude(version, out var reason).ShouldBeTrue();
            reason.ShouldNotBeNullOrWhiteSpace();
        }
Esempio n. 24
0
        private void cmbBaseVersion_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox    cmbBaseVersion = (ComboBox)sender;
            BaseVersion selectedBase   = (BaseVersion)cmbBaseVersion.SelectedItem;

            string selection = Convert.ToString(selectedBase);

            txtUpgradeCenter.Text += "Selected Base Version: " + selection + Environment.NewLine;

            PullClientMSI(selection);
            PullServerMSI(selection);
        }
        public static IIncrementStrategy GetStrategy(IVersionContext context, BaseVersion baseVersion)
        {
            // todo: extend IIncrementStrategy creation logic
            var defaultIncrement = context.Configuration.Increment;

            if (baseVersion.ShouldIncrement)
            {
                return(new IncrementStrategy(defaultIncrement.ToVersionField()));
            }

            return(new IncrementStrategy(VersionField.None));
        }
Esempio n. 26
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (BaseVersion != 0L)
            {
                hash ^= BaseVersion.GetHashCode();
            }
            if (BaseDocLength != 0L)
            {
                hash ^= BaseDocLength.GetHashCode();
            }
            hash ^= diffs_.GetHashCode();
            return(hash);
        }
Esempio n. 27
0
    private SemanticVersion PerformIncrement(BaseVersion baseVersion)
    {
        var semver    = baseVersion.SemanticVersion;
        var increment = this.repositoryStore.DetermineIncrementedField(baseVersion, context);

        if (increment != null)
        {
            semver = semver.IncrementVersion(increment.Value);
        }
        else
        {
            this.log.Info("Skipping version increment");
        }
        return(semver);
    }
Esempio n. 28
0
        public bool Exclude(BaseVersion version, out string reason)
        {
            if (version == null) throw new ArgumentNullException(nameof(version));

            reason = null;

            if (version.BaseVersionSource != null &&
                shas.Any(sha => version.BaseVersionSource.Sha.StartsWith(sha, StringComparison.OrdinalIgnoreCase)))
            {
                reason = $"Sha {version.BaseVersionSource.Sha} was ignored due to commit having been excluded by configuration";
                return true;
            }

            return false;
        }
Esempio n. 29
0
        public void ShouldNotFilterVersion()
        {
            var fakeIgnoreConfig = new TestIgnoreConfig(new ExcludeSourcesContainingExclude());
            var context          = new GitVersionContextBuilder().WithConfig(new Config()
            {
                Ignore = fakeIgnoreConfig
            }).Build();
            var version = new BaseVersion(context, "dummy", false, new SemanticVersion(2), new MockCommit(), null);
            var sut     = new BaseVersionCalculator(log, new TestVersionStrategy(version));

            var baseVersion = sut.GetBaseVersion(context);

            baseVersion.Source.ShouldBe(version.Source);
            baseVersion.ShouldIncrement.ShouldBe(version.ShouldIncrement);
            baseVersion.SemanticVersion.ShouldBe(version.SemanticVersion);
        }
Esempio n. 30
0
        public void WhenHashMatchShouldExcludeWithReason()
        {
            var commitMock = _fixture.Create <Mock <ICommit> >();

            commitMock.Setup(c => c.Hash)
            .ReturnsUsingFixture(_fixture);

            var commit  = commitMock.Object;
            var version = new BaseVersion("dummy", new SemanticVersion(1), commit);
            var sut     = new HashVersionFilter(new[] { commit.Hash });

            var result = sut.Exclude(version, out var reason);

            Assert.That(result, Is.True);
            Assert.That(reason, Is.Not.Empty);
        }
Esempio n. 31
0
        public void WhenHashMismatchShouldNotExclude()
        {
            var commitMock = _fixture.Create <Mock <ICommit> >();

            commitMock.Setup(c => c.Hash)
            .ReturnsUsingFixture(_fixture);

            var commit  = commitMock.Object;
            var version = new BaseVersion("dummy", new SemanticVersion(1), commit);
            var sut     = new HashVersionFilter(new[] { "mismatched" });

            var result = sut.Exclude(version, out var reason);

            Assert.That(result, Is.False);
            Assert.That(reason, Is.Null);
        }
Esempio n. 32
0
        private static VersionField? FindCommitMessageIncrement(GitVersionContext context, BaseVersion baseVersion)
        {
            if (context.Configuration.CommitMessageIncrementing == CommitMessageIncrementMode.Disabled)
            {
                return null;
            }
            
            var commits = GetIntermediateCommits(context.Repository, baseVersion.BaseVersionSource, context.CurrentCommit);

            if (context.Configuration.CommitMessageIncrementing == CommitMessageIncrementMode.MergeMessageOnly)
            {
                commits = commits.Where(c => c.Parents.Count() > 1);
            }

            return GetIncrementForCommits(context, commits);
        }
Esempio n. 33
0
        public void WhenShaMismatchShouldNotExclude()
        {
            var commitMock = _fixture.Create <Mock <ICommit> >();

            commitMock.Setup(c => c.When)
            .Returns(DateTime.UtcNow);

            var commit   = commitMock.Object;
            var version  = new BaseVersion("dummy", new SemanticVersion(1), commit);
            var pastDate = DateTimeOffset.UtcNow.AddYears(-1);
            var sut      = new MinDateVersionFilter(pastDate);

            var result = sut.Exclude(version, out var reason);

            Assert.That(result, Is.False);
            Assert.That(reason, Is.Null);
        }
Esempio n. 34
0
    private bool IncludeVersion(BaseVersion version)
    {
        if (context.Configuration == null)
        {
            return(false);
        }

        foreach (var filter in context.Configuration.VersionFilters)
        {
            if (filter.Exclude(version, out var reason))
            {
                this.log.Info(reason);
                return(false);
            }
        }
        return(true);
    }
Esempio n. 35
0
 static void IncrementVersion(GitVersionContext context, BaseVersion baseVersion)
 {
     if (!baseVersion.SemanticVersion.PreReleaseTag.HasTag())
     {
         switch (context.Configuration.Increment)
         {
             case IncrementStrategy.None:
                 Logger.WriteInfo("Skipping version increment");
                 break;
             case IncrementStrategy.Major:
                 Logger.WriteInfo("Incrementing Major Version");
                 baseVersion.SemanticVersion.Major++;
                 baseVersion.SemanticVersion.Minor = 0;
                 baseVersion.SemanticVersion.Patch = 0;
                 break;
             case IncrementStrategy.Minor:
                 baseVersion.SemanticVersion.Minor++;
                 baseVersion.SemanticVersion.Patch = 0;
                 Logger.WriteInfo("Incrementing Minor Version");
                 break;
             case IncrementStrategy.Patch:
                 baseVersion.SemanticVersion.Patch++;
                 Logger.WriteInfo("Incrementing Patch Version");
                 break;
             default:
                 throw new ArgumentOutOfRangeException();
         }
     }
     else
     {
         if (baseVersion.SemanticVersion.PreReleaseTag.Number != null)
         {
             baseVersion.SemanticVersion.PreReleaseTag.Number = baseVersion.SemanticVersion.PreReleaseTag.Number;
             baseVersion.SemanticVersion.PreReleaseTag.Number++;
         }
     }
 }
Esempio n. 36
0
 static SpecificVersion GetLatest(BaseVersion package, IEnumerable<string> packages) {
     return new SpecificVersion(package.Name, Dependency.FindLatestPreferNonBranched(packages));
 }
        private SemanticVersion FindMainlineModeVersion(BaseVersion baseVersion, GitVersionContext context)
        {
            if (baseVersion.SemanticVersion.PreReleaseTag.HasTag())
            {
                throw new NotSupportedException("Mainline development mode doesn't yet support pre-release tags on master");
            }

            using (Logger.IndentLog("Using mainline development mode to calculate current version"))
            {
                var mainlineVersion = baseVersion.SemanticVersion;

                var commitLog = context.Repository.Commits.QueryBy(new CommitFilter
                {
                    IncludeReachableFrom = context.CurrentBranch,
                    ExcludeReachableFrom = baseVersion.BaseVersionSource,
                    SortBy = CommitSortStrategies.Reverse
                }).Where(c => c.Sha != baseVersion.BaseVersionSource.Sha).ToList();
                var directCommits = new List<Commit>();

                foreach (var commit in commitLog)
                {
                    directCommits.Add(commit);
                    if (commit.Parents.Count() > 1)
                    {
                        // Merge commit, process all merged commits as a batch
                        var mergeCommit = commit;
                        var mergedHead = GetMergedHead(mergeCommit);
                        var findMergeBase = context.Repository.ObjectDatabase.FindMergeBase(mergeCommit.Parents.First(), mergedHead);
                        var findMessageIncrement = FindMessageIncrement(context, mergeCommit, mergedHead, findMergeBase, directCommits);

                        // If this collection is not empty there has been some direct commits against master
                        // Treat each commit as it's own 'release', we need to do this before we increment the branch
                        mainlineVersion = IncrementForEachCommit(context, directCommits, mainlineVersion);
                        directCommits.Clear();

                        // Finally increment for the branch
                        mainlineVersion = mainlineVersion.IncrementVersion(findMessageIncrement);
                        Logger.WriteInfo(string.Format("Merge commit {0} incremented base versions {1}, now {2}",
                            mergeCommit.Sha, findMessageIncrement, mainlineVersion));
                    }
                }

                if (context.CurrentBranch.FriendlyName != "master")
                {
                    var mergedHead = context.CurrentCommit;
                    var findMergeBase = context.Repository.ObjectDatabase.FindMergeBase(context.CurrentCommit, context.Repository.FindBranch("master").Tip);
                    Logger.WriteInfo(string.Format("Current branch ({0}) was branch from {1}", context.CurrentBranch.FriendlyName, findMergeBase));

                    var branchIncrement = FindMessageIncrement(context, findMergeBase, mergedHead, findMergeBase, directCommits);
                    mainlineVersion = IncrementForEachCommit(context, directCommits, mainlineVersion);
                    Logger.WriteInfo(string.Format("Performing {0} increment for current branch ", branchIncrement));
                    mainlineVersion = mainlineVersion.IncrementVersion(branchIncrement);
                }
                else
                {
                    // If we are on master, make sure no commits get left behind
                    mainlineVersion = IncrementForEachCommit(context, directCommits, mainlineVersion);
                }

                return mainlineVersion;
            }
        }
Esempio n. 38
0
        SemanticVersion FindMainlineModeVersion(BaseVersion baseVersion, GitVersionContext context)
        {
            if (baseVersion.SemanticVersion.PreReleaseTag.HasTag())
            {
                throw new NotSupportedException("Mainline development mode doesn't yet support pre-release tags on master");
            }

            using (Logger.IndentLog("Using mainline development mode to calculate current version"))
            {
                var mainlineVersion = baseVersion.SemanticVersion;

                // Forward merge / PR
                //          * feature/foo
                //         / |
                // master *  *
                // 
                var commitLog = context.Repository.Commits.QueryBy(new CommitFilter
                {
                    IncludeReachableFrom = context.CurrentBranch,
                    ExcludeReachableFrom = baseVersion.BaseVersionSource,
                    SortBy = CommitSortStrategies.Reverse
                }).Where(c => c.Sha != baseVersion.BaseVersionSource.Sha).ToList();
                var directCommits = new List<Commit>();

                // Scans commit log in reverse, aggregating merge commits
                foreach (var commit in commitLog)
                {
                    directCommits.Add(commit);
                    if (commit.Parents.Count() > 1)
                    {
                        mainlineVersion = AggregateMergeCommitIncrement(context, commit, directCommits, mainlineVersion);
                    }
                }

                if (context.CurrentBranch.FriendlyName != "master")
                {
                    var mergedHead = context.CurrentCommit;
                    var mainlineTip = GetMainlineTip(context);
                    var findMergeBase = context.Repository.ObjectDatabase.FindMergeBase(context.CurrentCommit, mainlineTip);
                    Logger.WriteInfo(string.Format("Current branch ({0}) was branch from {1}", context.CurrentBranch.FriendlyName, findMergeBase));

                    var branchIncrement = FindMessageIncrement(context, null, mergedHead, findMergeBase, directCommits);
                    // This will increment for any direct commits on master
                    mainlineVersion = IncrementForEachCommit(context, directCommits, mainlineVersion);
                    mainlineVersion.BuildMetaData = metaDataCalculator.Create(findMergeBase, context);
                    // Only increment if head is not a merge commit, ensures PR's and forward merges end up correct.
                    if (mergedHead.Parents.Count()  == 1)
                    {
                        Logger.WriteInfo(string.Format("Performing {0} increment for current branch ", branchIncrement));
                        mainlineVersion = mainlineVersion.IncrementVersion(branchIncrement);
                    }
                }
                else
                {
                    // If we are on master, make sure no commits get left behind
                    mainlineVersion = IncrementForEachCommit(context, directCommits, mainlineVersion);
                    mainlineVersion.BuildMetaData = metaDataCalculator.Create(baseVersion.BaseVersionSource, context);
                }

                return mainlineVersion;
            }
        }
Esempio n. 39
0
        void UpdatePreReleaseTag(GitVersionContext context, BaseVersion baseVersion)
        {
            var tagToUse = context.Configuration.Tag;
            if (tagToUse == "useBranchName")
            {
                Logger.WriteInfo("Using branch name to calculate version tag");
                var name = baseVersion.BranchNameOverride ?? context.CurrentBranch.Name;
                tagToUse = name.RegexReplace(context.Configuration.BranchPrefixToTrim, string.Empty, RegexOptions.IgnoreCase);
            }
            int? number = null;
            if (!string.IsNullOrEmpty(context.Configuration.TagNumberPattern))
            {
                var match = Regex.Match(context.CurrentBranch.CanonicalName, context.Configuration.TagNumberPattern);
                var numberGroup = match.Groups["number"];
                if (numberGroup.Success)
                {
                    number = int.Parse(numberGroup.Value);
                }
            }

            var lastTag = highestTagBaseVersionStrategy.GetVersion(context);
            if (number == null &&
                lastTag != null &&
                MajorMinorPatchEqual(lastTag.SemanticVersion, baseVersion.SemanticVersion) &&
                lastTag.SemanticVersion.PreReleaseTag.HasTag())
            {
                number = lastTag.SemanticVersion.PreReleaseTag.Number + 1;
            }

            if (number == null)
            {
                number = 1;
            }

            baseVersion.SemanticVersion.PreReleaseTag = new SemanticVersionPreReleaseTag(tagToUse, number);
        }