Skip to content

Commit 488c06f

Browse files
ermshiperetearturcic
authored andcommitted
Fix calculation of version when using worktrees (#2165)
1 parent b0c8e69 commit 488c06f

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

src/GitVersionCore.Tests/Extensions/GitToolsTestingExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Co
2929

3030
var options = Options.Create(new GitVersionOptions
3131
{
32-
WorkingDirectory = repository.GetRepositoryDirectory(),
32+
WorkingDirectory = repository.Info.WorkingDirectory,
3333
ConfigInfo = { OverrideConfig = configuration },
3434
RepositoryInfo =
3535
{

src/GitVersionCore/Core/GitPreparer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ private void CleanupDuplicateOrigin()
8888
{
8989
var remoteToKeep = DefaultRemoteName;
9090

91-
using var repo = new Repository(options.Value.DotGitDirectory);
91+
var isDynamicRepo = !string.IsNullOrWhiteSpace(options.Value.DynamicGitRepositoryPath);
92+
using var repo = new Repository(isDynamicRepo ? options.Value.DotGitDirectory : options.Value.ProjectRootDirectory);
9293

9394
// check that we have a remote that matches defaultRemoteName if not take the first remote
9495
if (!repo.Network.Remotes.Any(remote => remote.Name.Equals(DefaultRemoteName, StringComparison.InvariantCultureIgnoreCase)))

src/GitVersionCore/Core/GitRepository.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ public class GitRepository : IGitRepository
1111
private IRepository repositoryInstance => repositoryLazy.Value;
1212

1313
public GitRepository(IOptions<GitVersionOptions> options)
14-
: this(() => options.Value.DotGitDirectory)
14+
: this(() =>
15+
{
16+
var isDynamicRepo = !string.IsNullOrWhiteSpace(options.Value.DynamicGitRepositoryPath);
17+
return isDynamicRepo ? options.Value.DotGitDirectory : options.Value.ProjectRootDirectory;
18+
})
1519
{
1620
}
1721

18-
public GitRepository(Func<string> getDotGitDirectory)
22+
public GitRepository(Func<string> getGitRootDirectory)
1923
{
20-
repositoryLazy = new Lazy<IRepository>(() => new Repository(getDotGitDirectory()));
24+
repositoryLazy = new Lazy<IRepository>(() => new Repository(getGitRootDirectory()));
2125
Commands = new GitRepositoryCommands(repositoryLazy);
2226
}
2327

src/GitVersionCore/VersionCalculation/Cache/GitVersionCacheKeyFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ private List<string> CalculateDirectoryContents(string root)
141141

142142
private string GetRepositorySnapshotHash()
143143
{
144-
using var repo = new Repository(options.Value.DotGitDirectory);
144+
var isDynamicRepo = !string.IsNullOrWhiteSpace(options.Value.DynamicGitRepositoryPath);
145+
using var repo = new Repository(isDynamicRepo ? options.Value.DotGitDirectory : options.Value.ProjectRootDirectory);
145146

146147
var head = repo.Head;
147148
if (head.Tip == null)

0 commit comments

Comments
 (0)