Skip to content

Commit b0c8e69

Browse files
chusemanarturcic
authored andcommitted
Add a failing worktree version calculation test
1 parent 56f020e commit b0c8e69

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/GitVersionCore.Tests/Core/GitVersionExecutorTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
34
using System.Text;
45
using GitTools.Testing;
56
using GitVersion;
@@ -512,6 +513,37 @@ public void GetDotGitDirectoryWorktree()
512513
}
513514
}
514515

516+
[Test]
517+
[Category("NoMono")]
518+
[Description("LibGit2Sharp fails when running under Mono")]
519+
public void CalculateVersionFromWorktreeHead()
520+
{
521+
// Setup
522+
using var fixture = new EmptyRepositoryFixture();
523+
var repoDir = new DirectoryInfo(fixture.RepositoryPath);
524+
var worktreePath = Path.Combine(repoDir.Parent.FullName, $"{repoDir.Name}-v1");
525+
526+
fixture.Repository.MakeATaggedCommit("v1.0.0");
527+
var branchV1 = fixture.Repository.CreateBranch("support/1.0");
528+
529+
fixture.Repository.MakeATaggedCommit("v2.0.0");
530+
531+
fixture.Repository.Worktrees.Add(branchV1.CanonicalName, "1.0", worktreePath, false);
532+
using var worktreeFixture = new LocalRepositoryFixture(new Repository(worktreePath));
533+
534+
var gitVersionOptions = new GitVersionOptions { WorkingDirectory = worktreeFixture.RepositoryPath };
535+
536+
var sut = GetGitVersionCalculator(gitVersionOptions);
537+
538+
// Execute
539+
var version = sut.CalculateVersionVariables();
540+
541+
// Verify
542+
version.SemVer.ShouldBe("1.0.0");
543+
var commits = worktreeFixture.Repository.Head.Commits;
544+
version.Sha.ShouldBe(commits.First().Sha);
545+
}
546+
515547
private IGitVersionTool GetGitVersionCalculator(GitVersionOptions gitVersionOptions, ILog logger = null, IRepository repository = null, IFileSystem fs = null)
516548
{
517549
sp = GetServiceProvider(gitVersionOptions, logger, repository, fs);

0 commit comments

Comments
 (0)