Skip to content

Commit a09ee77

Browse files
committed
cleanup
1 parent b722f72 commit a09ee77

File tree

5 files changed

+25
-31
lines changed

5 files changed

+25
-31
lines changed

src/GitVersionCore/Configuration/ConfigProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ public ConfigProvider(IFileSystem fileSystem, ILog log, IConfigFileLocator confi
2626

2727
public Config Provide(bool applyDefaults = true, Config overrideConfig = null)
2828
{
29-
var workingDirectory = options.Value.WorkingDirectory;
30-
var projectRootDirectory = options.Value.ProjectRootDirectory;
29+
var gitVersionOptions = options.Value;
30+
var workingDirectory = gitVersionOptions.WorkingDirectory;
31+
var projectRootDirectory = gitVersionOptions.ProjectRootDirectory;
3132

3233
var rootDirectory = configFileLocator.HasConfigFileAt(workingDirectory) ? workingDirectory : projectRootDirectory;
3334
return Provide(rootDirectory, applyDefaults, overrideConfig);

src/GitVersionCore/Core/GitPreparer.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.IO;
33
using System.Linq;
4-
using GitVersion.Extensions;
54
using GitVersion.Helpers;
65
using GitVersion.Logging;
76
using LibGit2Sharp;
@@ -58,11 +57,11 @@ public void PrepareInternal(bool normalizeGitDirectory, string currentBranch, bo
5857
Username = gitVersionOptions.Authentication?.Username,
5958
Password = gitVersionOptions.Authentication?.Password
6059
};
61-
if (!string.IsNullOrWhiteSpace(options.Value.RepositoryInfo.TargetUrl))
60+
if (!string.IsNullOrWhiteSpace(gitVersionOptions.RepositoryInfo.TargetUrl))
6261
{
63-
var tempRepositoryPath = CalculateTemporaryRepositoryPath(options.Value.RepositoryInfo.TargetUrl, gitVersionOptions.RepositoryInfo.DynamicRepositoryClonePath);
62+
var tempRepositoryPath = CalculateTemporaryRepositoryPath(gitVersionOptions.RepositoryInfo.TargetUrl, gitVersionOptions.RepositoryInfo.DynamicRepositoryClonePath);
6463

65-
gitVersionOptions.RepositoryInfo.DynamicGitRepositoryPath = CreateDynamicRepository(tempRepositoryPath, authentication, options.Value.RepositoryInfo.TargetUrl, currentBranch);
64+
gitVersionOptions.RepositoryInfo.DynamicGitRepositoryPath = CreateDynamicRepository(tempRepositoryPath, authentication, gitVersionOptions.RepositoryInfo.TargetUrl, currentBranch);
6665
}
6766
else
6867
{
@@ -73,7 +72,7 @@ public void PrepareInternal(bool normalizeGitDirectory, string currentBranch, bo
7372
CleanupDuplicateOrigin();
7473
}
7574

76-
NormalizeGitDirectory(authentication, currentBranch, options.Value.DotGitDirectory, options.Value.IsDynamicGitRepository());
75+
NormalizeGitDirectory(authentication, currentBranch, gitVersionOptions.DotGitDirectory, false);
7776
}
7877
}
7978
}

src/GitVersionCore/Extensions/GitVersionOptionsExtensions.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,26 @@ namespace GitVersion.Extensions
55
{
66
public static class GitVersionOptionsExtensions
77
{
8-
public static bool IsDynamicGitRepository(this GitVersionOptions gitVersionOptions) => !string.IsNullOrWhiteSpace(gitVersionOptions.RepositoryInfo.DynamicGitRepositoryPath);
8+
private static bool IsDynamicGitRepository(GitVersionOptions gitVersionOptions) => !string.IsNullOrWhiteSpace(gitVersionOptions.RepositoryInfo.DynamicGitRepositoryPath);
99

1010
public static string GetDotGitDirectory(this GitVersionOptions gitVersionOptions)
1111
{
12-
var gitDirectory = gitVersionOptions.IsDynamicGitRepository() ? gitVersionOptions.RepositoryInfo.DynamicGitRepositoryPath : Repository.Discover(gitVersionOptions.WorkingDirectory);
12+
var dotGitDirectory = IsDynamicGitRepository(gitVersionOptions)
13+
? gitVersionOptions.RepositoryInfo.DynamicGitRepositoryPath
14+
: Repository.Discover(gitVersionOptions.WorkingDirectory);
1315

14-
gitDirectory = gitDirectory?.TrimEnd('/', '\\');
15-
if (string.IsNullOrEmpty(gitDirectory))
16-
throw new DirectoryNotFoundException("Can't find the .git directory in " + gitDirectory);
16+
dotGitDirectory = dotGitDirectory?.TrimEnd('/', '\\');
17+
if (string.IsNullOrEmpty(dotGitDirectory))
18+
throw new DirectoryNotFoundException($"Can't find the .git directory in {dotGitDirectory}");
1719

18-
return gitDirectory.Contains(Path.Combine(".git", "worktrees"))
19-
? Directory.GetParent(Directory.GetParent(gitDirectory).FullName).FullName
20-
: gitDirectory;
20+
return dotGitDirectory.Contains(Path.Combine(".git", "worktrees"))
21+
? Directory.GetParent(Directory.GetParent(dotGitDirectory).FullName).FullName
22+
: dotGitDirectory;
2123
}
2224

2325
public static string GetProjectRootDirectory(this GitVersionOptions gitVersionOptions)
2426
{
25-
if (gitVersionOptions.IsDynamicGitRepository())
27+
if (IsDynamicGitRepository(gitVersionOptions))
2628
{
2729
return gitVersionOptions.WorkingDirectory;
2830
}

src/GitVersionCore/Model/GitVersionOptions.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ public GitVersionOptions()
1414
{
1515
dotGitDirectory = new Lazy<string>(this.GetDotGitDirectory);
1616
projectRootDirectory = new Lazy<string>(this.GetProjectRootDirectory);
17-
18-
AssemblyInfo = new AssemblyInfo();
19-
Authentication = new AuthenticationInfo();
20-
ConfigInfo = new ConfigInfo();
21-
WixInfo = new WixInfo();
22-
RepositoryInfo = new RepositoryInfo();
23-
Settings = new Settings();
2417
}
2518

2619
private string workingDirectory;
@@ -33,12 +26,12 @@ public string WorkingDirectory
3326
public string DotGitDirectory => dotGitDirectory.Value;
3427
public string ProjectRootDirectory => projectRootDirectory.Value;
3528

36-
public AssemblyInfo AssemblyInfo { get; }
37-
public AuthenticationInfo Authentication { get; }
38-
public ConfigInfo ConfigInfo { get; }
39-
public RepositoryInfo RepositoryInfo { get; }
40-
public WixInfo WixInfo { get; }
41-
public Settings Settings { get; }
29+
public AssemblyInfo AssemblyInfo { get; } = new AssemblyInfo();
30+
public AuthenticationInfo Authentication { get; } = new AuthenticationInfo();
31+
public ConfigInfo ConfigInfo { get; } = new ConfigInfo();
32+
public RepositoryInfo RepositoryInfo { get; } = new RepositoryInfo();
33+
public WixInfo WixInfo { get; } = new WixInfo();
34+
public Settings Settings { get; } = new Settings();
4235

4336
public bool Init;
4437
public bool Diag;

src/GitVersionCore/VersionCalculation/Cache/GitVersionCache.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ void WriteCacheOperation()
5555
public string GetCacheDirectory()
5656
{
5757
var gitDir = options.Value.DotGitDirectory;
58-
var cacheDir = Path.Combine(gitDir, "gitversion_cache");
59-
return cacheDir;
58+
return Path.Combine(gitDir, "gitversion_cache");
6059
}
6160

6261
public VersionVariables LoadVersionVariablesFromDiskCache(GitVersionCacheKey key)

0 commit comments

Comments
 (0)