Skip to content

Commit

Permalink
Added GitRootPath in the GitVersionOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed May 21, 2020
1 parent 488c06f commit be48ce3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/GitVersionCore/Core/GitPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
6 changes: 1 addition & 5 deletions src/GitVersionCore/Core/GitRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ public class GitRepository : IGitRepository
private IRepository repositoryInstance => repositoryLazy.Value;

public GitRepository(IOptions<GitVersionOptions> options)
: this(() =>
{
var isDynamicRepo = !string.IsNullOrWhiteSpace(options.Value.DynamicGitRepositoryPath);
return isDynamicRepo ? options.Value.DotGitDirectory : options.Value.ProjectRootDirectory;
})
: this(() => options.Value.GitRootPath)
{
}

Expand Down
8 changes: 8 additions & 0 deletions src/GitVersionCore/Extensions/GitVersionOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/GitVersionCore/Model/GitVersionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ public class GitVersionOptions
private Lazy<string> dotGitDirectory;
private Lazy<string> projectRootDirectory;
private Lazy<string> dynamicGitRepositoryPath;
private Lazy<string> gitRootPath;

public GitVersionOptions()
{
dotGitDirectory = new Lazy<string>(this.GetDotGitDirectory);
projectRootDirectory = new Lazy<string>(this.GetProjectRootDirectory);
dynamicGitRepositoryPath = new Lazy<string>(this.GetDynamicGitRepositoryPath);
gitRootPath = new Lazy<string>(this.GetGitRootPath);
}

public string WorkingDirectory { get; set; }

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ private List<string> 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)
Expand Down

0 comments on commit be48ce3

Please sign in to comment.