public void CanTakeVersionFromNameOfReleaseBranch(string branchName, string expectedBaseVersion) { using (var fixture = new EmptyRepositoryFixture()) { fixture.Repository.MakeACommit(); var branch = fixture.Repository.CreateBranch(branchName); var sut = new VersionInBranchNameBaseVersionStrategy(); var gitVersionContext = new GitVersionContext(fixture.Repository, branch, new Config().ApplyDefaults()); var baseVersion = sut.GetVersions(gitVersionContext).Single(); baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion); } }
public void ShouldNotTakeVersionFromNameOfNonReleaseBranch(string branchName) { using (var fixture = new EmptyRepositoryFixture()) { fixture.Repository.MakeACommit(); var branch = fixture.Repository.CreateBranch(branchName); var sut = new VersionInBranchNameBaseVersionStrategy(); var gitVersionContext = new GitVersionContext(fixture.Repository, branch, new Config().ApplyDefaults()); var baseVersions = sut.GetVersions(gitVersionContext); baseVersions.ShouldBeEmpty(); } }
IEnumerable <BaseVersion> GetReleaseVersion(GitVersionContext context, Branch releaseBranch) { var tagPrefixRegex = context.Configuration.GitTagPrefix; // Find the commit where the child branch was created. var baseSource = context.RepositoryMetadataProvider.FindMergeBase(releaseBranch, context.CurrentBranch); if (baseSource == context.CurrentCommit) { // Ignore the branch if it has no commits. return(new BaseVersion[0]); } return(releaseVersionStrategy .GetVersions(context, tagPrefixRegex, releaseBranch) .Select(b => new BaseVersion(context, b.Source, true, b.SemanticVersion, baseSource, b.BranchNameOverride))); }
public void CanTakeVersionFromNameOfRemoteReleaseBranch(string branchName, string expectedBaseVersion) { using (var fixture = new RemoteRepositoryFixture()) { var branch = fixture.Repository.CreateBranch(branchName); Commands.Checkout(fixture.Repository, branch); fixture.MakeACommit(); Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, new string[0], new FetchOptions(), null); fixture.LocalRepositoryFixture.Checkout($"origin/{branchName}"); var sut = new VersionInBranchNameBaseVersionStrategy(); var gitVersionContext = new GitVersionContext(fixture.Repository, branch, new Config().ApplyDefaults()); var baseVersion = sut.GetVersions(gitVersionContext).Single(); baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion); } }
public void CanTakeVersionFromNameOfConfiguredReleaseBranch(string branchName, string expectedBaseVersion) { using (var fixture = new EmptyRepositoryFixture()) { fixture.Repository.MakeACommit(); var branch = fixture.Repository.CreateBranch(branchName); var sut = new VersionInBranchNameBaseVersionStrategy(); var branchConfigs = new Dictionary <string, BranchConfig> { { "support", new BranchConfig { IsReleaseBranch = true } } }; var config = new Config { Branches = branchConfigs }.ApplyDefaults(); var gitVersionContext = new GitVersionContext(fixture.Repository, branch, config); var baseVersion = sut.GetVersions(gitVersionContext).Single(); baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion); } }