Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Properly get project root directory
This returns the correct workdir when using worktrees where the git
repo resides inside of the main working tree. Partial fix for #1063.
  • Loading branch information
ermshiperete committed Sep 4, 2019
commit ddb7c6ec36196fc43bd24b0c0d0d092c96dd5caa
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