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; }
/// <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; } } } }
protected Base(string name, string description, string imageUrl, BaseVersion version) { Name = name; Description = description; Version = version; ImageUrl = imageUrl; }
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); }
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()); }
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(); }
void SetPackage(BaseVersion desiredVersion) { if (Model.Controller.Package == null) { return; } Model.Controller.Package.UpdateLocalDependency(desiredVersion); }
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(); }
SpecificVersion GetActual(BaseVersion current) { if (current == _latestJoker) { return(GetLatestDependency()); } return(current == _latestAnyJoker?GetLatestAnyDependency() : current.ToSpecificVersion()); }
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(); }
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(); }
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); }
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(); }
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(); }
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(); }
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(); }
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; }
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); }
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(); }
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)); }
public override int GetHashCode() { int hash = 1; if (BaseVersion != 0L) { hash ^= BaseVersion.GetHashCode(); } if (BaseDocLength != 0L) { hash ^= BaseDocLength.GetHashCode(); } hash ^= diffs_.GetHashCode(); return(hash); }
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); }
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; }
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); }
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); }
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); }
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); }
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); }
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); }
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++; } } }
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; } }
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; } }
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); }