Skip to content

Commit be48ce3

Browse files
committed
Added GitRootPath in the GitVersionOptions
1 parent 488c06f commit be48ce3

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

src/GitVersionCore/Core/GitPreparer.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ private string ResolveCurrentBranch()
8787
private void CleanupDuplicateOrigin()
8888
{
8989
var remoteToKeep = DefaultRemoteName;
90-
91-
var isDynamicRepo = !string.IsNullOrWhiteSpace(options.Value.DynamicGitRepositoryPath);
92-
using var repo = new Repository(isDynamicRepo ? options.Value.DotGitDirectory : options.Value.ProjectRootDirectory);
90+
using var repo = new Repository(options.Value.GitRootPath);
9391

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

src/GitVersionCore/Core/GitRepository.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ public class GitRepository : IGitRepository
1111
private IRepository repositoryInstance => repositoryLazy.Value;
1212

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

src/GitVersionCore/Extensions/GitVersionOptionsExtensions.cs

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public static string GetProjectRootDirectory(this GitVersionOptions gitVersionOp
3838
return repository.Info.WorkingDirectory;
3939
}
4040

41+
public static string GetGitRootPath(this GitVersionOptions options)
42+
{
43+
var isDynamicRepo = !string.IsNullOrWhiteSpace(options.DynamicGitRepositoryPath);
44+
var rootDirectory = isDynamicRepo ? options.DotGitDirectory : options.ProjectRootDirectory;
45+
46+
return rootDirectory;
47+
}
48+
4149
public static string GetDynamicGitRepositoryPath(this GitVersionOptions gitVersionOptions)
4250
{
4351
if (string.IsNullOrWhiteSpace(gitVersionOptions.RepositoryInfo.TargetUrl)) return null;

src/GitVersionCore/Model/GitVersionOptions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,22 @@ public class GitVersionOptions
1111
private Lazy<string> dotGitDirectory;
1212
private Lazy<string> projectRootDirectory;
1313
private Lazy<string> dynamicGitRepositoryPath;
14+
private Lazy<string> gitRootPath;
1415

1516
public GitVersionOptions()
1617
{
1718
dotGitDirectory = new Lazy<string>(this.GetDotGitDirectory);
1819
projectRootDirectory = new Lazy<string>(this.GetProjectRootDirectory);
1920
dynamicGitRepositoryPath = new Lazy<string>(this.GetDynamicGitRepositoryPath);
21+
gitRootPath = new Lazy<string>(this.GetGitRootPath);
2022
}
2123

2224
public string WorkingDirectory { get; set; }
2325

2426
public string DotGitDirectory => dotGitDirectory.Value;
2527
public string ProjectRootDirectory => projectRootDirectory.Value;
2628
public string DynamicGitRepositoryPath => dynamicGitRepositoryPath.Value;
29+
public string GitRootPath => gitRootPath.Value;
2730

2831
public AssemblyInfoData AssemblyInfo { get; } = new AssemblyInfoData();
2932
public AuthenticationInfo Authentication { get; } = new AuthenticationInfo();

src/GitVersionCore/VersionCalculation/Cache/GitVersionCacheKeyFactory.cs

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

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

147146
var head = repo.Head;
148147
if (head.Tip == null)

0 commit comments

Comments
 (0)