Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/GitVersionCore.Tests/ExecuteCoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.IO;
using System.Text;
using LibGit2Sharp;

[TestFixture]
[Parallelizable(ParallelScope.None)]
Expand Down Expand Up @@ -266,6 +267,33 @@ public void WorkingDirectoryWithoutGit()
});
}

[Test]
[Category("NoMono")]
[Description("LibGit2Sharp fails when running under Mono")]
public void WorkingDirectoryWithWorktree()
{
var versionAndBranchFinder = new ExecuteCore(fileSystem);

RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
{
var worktreePath = Path.Combine(Directory.GetParent(fixture.RepositoryPath).FullName, Guid.NewGuid().ToString());
try
{
// create a branch and a new worktree for it
var repo = new Repository(fixture.RepositoryPath);
repo.Worktrees.Add("worktree", worktreePath, false);

var targetUrl = "https://github.com/GitTools/GitVersion.git";
var gitPreparer = new GitPreparer(targetUrl, null, new Authentication(), false, worktreePath);
gitPreparer.GetProjectRootDirectory().TrimEnd('/', '\\').ShouldBe(worktreePath);
}
finally
{
DirectoryHelper.DeleteDirectory(worktreePath);
}
});
}

[Test]
public void DynamicRepositoriesShouldNotErrorWithFailedToFindGitDirectory()
{
Expand Down
9 changes: 6 additions & 3 deletions src/GitVersionCore/GitPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,12 @@ public string GetProjectRootDirectory()
}

var dotGetGitDirectory = GetDotGitDirectory();
var result = Directory.GetParent(dotGetGitDirectory).FullName;
Logger.WriteInfo($"Returning Project Root from DotGitDirectory: {dotGetGitDirectory} - {result}");
return result;
using (var repo = new Repository(dotGetGitDirectory))
{
var result = repo.Info.WorkingDirectory;
Logger.WriteInfo($"Returning Project Root from DotGitDirectory: {dotGetGitDirectory} - {result}");
return result;
}
}

static string CreateDynamicRepository(string targetPath, AuthenticationInfo authentication, string repositoryUrl, string targetBranch, bool noFetch)
Expand Down