public void CalculateVersionVariables_TwoBranchHasSameCommitHeadDetachedAndTagged_ReturnSemver() { // Setup using var fixture = new RemoteRepositoryFixture(); fixture.LocalRepositoryFixture.Repository.MakeACommit("Init commit"); fixture.LocalRepositoryFixture.Repository.CreateBranch("feature/1.0"); fixture.LocalRepositoryFixture.Checkout("feature/1.0"); var commit = fixture.LocalRepositoryFixture.Repository.MakeACommit("feat: a new commit"); fixture.LocalRepositoryFixture.Repository.CreateBranch("support/1.0"); fixture.LocalRepositoryFixture.ApplyTag("1.0.1"); fixture.LocalRepositoryFixture.Checkout(commit.Sha); using var worktreeFixture = new LocalRepositoryFixture(new Repository(fixture.LocalRepositoryFixture.RepositoryPath)); var gitVersionOptions = new GitVersionOptions { WorkingDirectory = worktreeFixture.RepositoryPath }; var environment = new TestEnvironment(); environment.SetEnvironmentVariable(AzurePipelines.EnvironmentVariableName, "true"); this.sp = GetServiceProvider(gitVersionOptions, environment: environment); var sut = sp.GetRequiredService <IGitVersionCalculateTool>(); // Execute var version = sut.CalculateVersionVariables(); // Verify version.SemVer.ShouldBe("1.0.1"); var commits = worktreeFixture.Repository.Head.Commits; version.Sha.ShouldBe(commits.First().Sha); }
public void CalculateVersionFromWorktreeHead() { // Setup using var fixture = new EmptyRepositoryFixture(); var repoDir = new DirectoryInfo(fixture.RepositoryPath); var worktreePath = Path.Combine(repoDir.Parent.FullName, $"{repoDir.Name}-v1"); fixture.Repository.MakeATaggedCommit("v1.0.0"); var branchV1 = fixture.Repository.CreateBranch("support/1.0"); fixture.Repository.MakeATaggedCommit("v2.0.0"); fixture.Repository.Worktrees.Add(branchV1.CanonicalName, "1.0", worktreePath, false); using var worktreeFixture = new LocalRepositoryFixture(new Repository(worktreePath)); var gitVersionOptions = new GitVersionOptions { WorkingDirectory = worktreeFixture.RepositoryPath }; var sut = GetGitVersionCalculator(gitVersionOptions); // Execute var version = sut.CalculateVersionVariables(); // Verify version.SemVer.ShouldBe("1.0.0"); var commits = worktreeFixture.Repository.Head.Commits; version.Sha.ShouldBe(commits.First().Sha); }
public void CalculateVersionVariables_TwoBranchHasSameCommitHeadDetachedAndNotTagged_ThrowException() { // Setup using var fixture = new RemoteRepositoryFixture(); fixture.LocalRepositoryFixture.Repository.MakeACommit("Init commit"); fixture.LocalRepositoryFixture.Repository.CreateBranch("feature/1.0"); fixture.LocalRepositoryFixture.Checkout("feature/1.0"); var commit = fixture.LocalRepositoryFixture.Repository.MakeACommit("feat: a new commit"); fixture.LocalRepositoryFixture.Repository.CreateBranch("support/1.0"); fixture.LocalRepositoryFixture.Checkout(commit.Sha); using var worktreeFixture = new LocalRepositoryFixture(new Repository(fixture.LocalRepositoryFixture.RepositoryPath)); var gitVersionOptions = new GitVersionOptions { WorkingDirectory = worktreeFixture.RepositoryPath }; var environment = new TestEnvironment(); environment.SetEnvironmentVariable(AzurePipelines.EnvironmentVariableName, "true"); this.sp = GetServiceProvider(gitVersionOptions, environment: environment); var sut = sp.GetRequiredService <IGitVersionCalculateTool>(); // Execute & Verify var exception = Assert.Throws <WarningException>(() => sut.CalculateVersionVariables()); exception?.Message.ShouldBe("Failed to try and guess branch to use. Move one of the branches along a commit to remove warning"); }
public void UseWorktreeRepositoryForVersion() { using var fixture = new EmptyRepositoryFixture(); var repoDir = new DirectoryInfo(fixture.RepositoryPath); var worktreePath = Path.Combine(repoDir.Parent.FullName, $"{repoDir.Name}-v1"); fixture.Repository.MakeATaggedCommit("v1.0.0"); var branchV1 = fixture.Repository.CreateBranch("support/1.0"); fixture.Repository.MakeATaggedCommit("v2.0.0"); fixture.AssertFullSemver("2.0.0"); fixture.Repository.Worktrees.Add(branchV1.CanonicalName, "1.0", worktreePath, false); using var worktreeFixture = new LocalRepositoryFixture(new Repository(worktreePath)); worktreeFixture.AssertFullSemver("1.0.0"); }
private void CreateLocalRepository() => LocalRepositoryFixture = CloneRepository();
void CreateLocalRepository() { LocalRepositoryFixture = CloneRepository(); }