From be48ce3ac7f048c869fe80b8c8e648ebf4a7e360 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Thu, 21 May 2020 12:21:49 +0300 Subject: [PATCH] Added GitRootPath in the GitVersionOptions --- src/GitVersionCore/Core/GitPreparer.cs | 4 +--- src/GitVersionCore/Core/GitRepository.cs | 6 +----- .../Extensions/GitVersionOptionsExtensions.cs | 8 ++++++++ src/GitVersionCore/Model/GitVersionOptions.cs | 3 +++ .../VersionCalculation/Cache/GitVersionCacheKeyFactory.cs | 3 +-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/GitVersionCore/Core/GitPreparer.cs b/src/GitVersionCore/Core/GitPreparer.cs index cbe6a1eff8..fb8d1854f0 100644 --- a/src/GitVersionCore/Core/GitPreparer.cs +++ b/src/GitVersionCore/Core/GitPreparer.cs @@ -87,9 +87,7 @@ private string ResolveCurrentBranch() private void CleanupDuplicateOrigin() { var remoteToKeep = DefaultRemoteName; - - var isDynamicRepo = !string.IsNullOrWhiteSpace(options.Value.DynamicGitRepositoryPath); - using var repo = new Repository(isDynamicRepo ? options.Value.DotGitDirectory : options.Value.ProjectRootDirectory); + using var repo = new Repository(options.Value.GitRootPath); // check that we have a remote that matches defaultRemoteName if not take the first remote if (!repo.Network.Remotes.Any(remote => remote.Name.Equals(DefaultRemoteName, StringComparison.InvariantCultureIgnoreCase))) diff --git a/src/GitVersionCore/Core/GitRepository.cs b/src/GitVersionCore/Core/GitRepository.cs index 222d78ab7a..878033780c 100644 --- a/src/GitVersionCore/Core/GitRepository.cs +++ b/src/GitVersionCore/Core/GitRepository.cs @@ -11,11 +11,7 @@ public class GitRepository : IGitRepository private IRepository repositoryInstance => repositoryLazy.Value; public GitRepository(IOptions options) - : this(() => - { - var isDynamicRepo = !string.IsNullOrWhiteSpace(options.Value.DynamicGitRepositoryPath); - return isDynamicRepo ? options.Value.DotGitDirectory : options.Value.ProjectRootDirectory; - }) + : this(() => options.Value.GitRootPath) { } diff --git a/src/GitVersionCore/Extensions/GitVersionOptionsExtensions.cs b/src/GitVersionCore/Extensions/GitVersionOptionsExtensions.cs index c8e161898b..3be5854eef 100644 --- a/src/GitVersionCore/Extensions/GitVersionOptionsExtensions.cs +++ b/src/GitVersionCore/Extensions/GitVersionOptionsExtensions.cs @@ -38,6 +38,14 @@ public static string GetProjectRootDirectory(this GitVersionOptions gitVersionOp return repository.Info.WorkingDirectory; } + public static string GetGitRootPath(this GitVersionOptions options) + { + var isDynamicRepo = !string.IsNullOrWhiteSpace(options.DynamicGitRepositoryPath); + var rootDirectory = isDynamicRepo ? options.DotGitDirectory : options.ProjectRootDirectory; + + return rootDirectory; + } + public static string GetDynamicGitRepositoryPath(this GitVersionOptions gitVersionOptions) { if (string.IsNullOrWhiteSpace(gitVersionOptions.RepositoryInfo.TargetUrl)) return null; diff --git a/src/GitVersionCore/Model/GitVersionOptions.cs b/src/GitVersionCore/Model/GitVersionOptions.cs index 2463c839ee..856bb604fc 100644 --- a/src/GitVersionCore/Model/GitVersionOptions.cs +++ b/src/GitVersionCore/Model/GitVersionOptions.cs @@ -11,12 +11,14 @@ public class GitVersionOptions private Lazy dotGitDirectory; private Lazy projectRootDirectory; private Lazy dynamicGitRepositoryPath; + private Lazy gitRootPath; public GitVersionOptions() { dotGitDirectory = new Lazy(this.GetDotGitDirectory); projectRootDirectory = new Lazy(this.GetProjectRootDirectory); dynamicGitRepositoryPath = new Lazy(this.GetDynamicGitRepositoryPath); + gitRootPath = new Lazy(this.GetGitRootPath); } public string WorkingDirectory { get; set; } @@ -24,6 +26,7 @@ public GitVersionOptions() public string DotGitDirectory => dotGitDirectory.Value; public string ProjectRootDirectory => projectRootDirectory.Value; public string DynamicGitRepositoryPath => dynamicGitRepositoryPath.Value; + public string GitRootPath => gitRootPath.Value; public AssemblyInfoData AssemblyInfo { get; } = new AssemblyInfoData(); public AuthenticationInfo Authentication { get; } = new AuthenticationInfo(); diff --git a/src/GitVersionCore/VersionCalculation/Cache/GitVersionCacheKeyFactory.cs b/src/GitVersionCore/VersionCalculation/Cache/GitVersionCacheKeyFactory.cs index dc86bba3ce..2b05686e2e 100644 --- a/src/GitVersionCore/VersionCalculation/Cache/GitVersionCacheKeyFactory.cs +++ b/src/GitVersionCore/VersionCalculation/Cache/GitVersionCacheKeyFactory.cs @@ -141,8 +141,7 @@ private List CalculateDirectoryContents(string root) private string GetRepositorySnapshotHash() { - var isDynamicRepo = !string.IsNullOrWhiteSpace(options.Value.DynamicGitRepositoryPath); - using var repo = new Repository(isDynamicRepo ? options.Value.DotGitDirectory : options.Value.ProjectRootDirectory); + using var repo = new Repository(options.Value.GitRootPath); var head = repo.Head; if (head.Tip == null)