Skip to content

Commit 516f2e7

Browse files
committed
removed ReflectionIgnore attribute from GitVersionVariable
1 parent 065a34f commit 516f2e7

File tree

5 files changed

+36
-55
lines changed

5 files changed

+36
-55
lines changed

src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ public void CacheKeySameAfterReNormalizing()
2626
const string targetUrl = "https://github.com/GitTools/GitVersion.git";
2727
const string targetBranch = $"refs/head/{MainBranch}";
2828

29-
var gitVersionOptions = new GitVersionOptions
30-
{
31-
RepositoryInfo = { TargetUrl = targetUrl, TargetBranch = targetBranch },
32-
WorkingDirectory = fixture.RepositoryPath,
33-
Settings = { NoNormalize = false }
34-
};
29+
var gitVersionOptions = new GitVersionOptions { RepositoryInfo = { TargetUrl = targetUrl, TargetBranch = targetBranch }, WorkingDirectory = fixture.RepositoryPath, Settings = { NoNormalize = false } };
3530

3631
var environment = new TestEnvironment();
3732
environment.SetEnvironmentVariable(AzurePipelines.EnvironmentVariableName, "true");
@@ -55,11 +50,7 @@ public void GitPreparerShouldNotFailWhenTargetPathNotInitialized()
5550
{
5651
const string targetUrl = "https://github.com/GitTools/GitVersion.git";
5752

58-
var gitVersionOptions = new GitVersionOptions
59-
{
60-
RepositoryInfo = { TargetUrl = targetUrl },
61-
WorkingDirectory = string.Empty
62-
};
53+
var gitVersionOptions = new GitVersionOptions { RepositoryInfo = { TargetUrl = targetUrl }, WorkingDirectory = string.Empty };
6354
Should.NotThrow(() =>
6455
{
6556
this.sp = GetServiceProvider(gitVersionOptions);
@@ -82,11 +73,7 @@ public void CacheKeyForWorktree()
8273

8374
const string targetUrl = "https://github.com/GitTools/GitVersion.git";
8475

85-
var gitVersionOptions = new GitVersionOptions
86-
{
87-
RepositoryInfo = { TargetUrl = targetUrl, TargetBranch = MainBranch },
88-
WorkingDirectory = worktreePath
89-
};
76+
var gitVersionOptions = new GitVersionOptions { RepositoryInfo = { TargetUrl = targetUrl, TargetBranch = MainBranch }, WorkingDirectory = worktreePath };
9077

9178
this.sp = GetServiceProvider(gitVersionOptions);
9279

@@ -148,7 +135,11 @@ public void CacheFileExistsOnDisk()
148135
var versionVariables = gitVersionCalculator.CalculateVersionVariables();
149136
versionVariables.AssemblySemVer.ShouldBe("0.0.1.0");
150137

151-
this.fileSystem.WriteAllText(versionVariables.FileName, versionCacheFileContent);
138+
var cacheKeyFactory = this.sp.GetRequiredService<IGitVersionCacheKeyFactory>();
139+
var cacheKey = cacheKeyFactory.Create(null);
140+
var cacheFileName = this.gitVersionCache.GetCacheFileName(cacheKey);
141+
142+
this.fileSystem.WriteAllText(cacheFileName, versionCacheFileContent);
152143
versionVariables = gitVersionCalculator.CalculateVersionVariables();
153144
versionVariables.AssemblySemVer.ShouldBe("4.10.3.0");
154145

@@ -195,7 +186,10 @@ public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDyn
195186
var versionVariables = gitVersionCalculator.CalculateVersionVariables();
196187
versionVariables.AssemblySemVer.ShouldBe("0.0.1.0");
197188

198-
this.fileSystem.WriteAllText(versionVariables.FileName, versionCacheFileContent);
189+
var cacheKeyFactory = this.sp.GetRequiredService<IGitVersionCacheKeyFactory>();
190+
var cacheKey = cacheKeyFactory.Create(null);
191+
var cacheFileName = this.gitVersionCache.GetCacheFileName(cacheKey);
192+
this.fileSystem.WriteAllText(cacheFileName, versionCacheFileContent);
199193

200194
var cacheDirectory = this.gitVersionCache.GetCacheDirectory();
201195

@@ -204,11 +198,7 @@ public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDyn
204198
var configuration = GitFlowConfigurationBuilder.New.WithLabelPrefix("prefix").Build();
205199
var overrideConfiguration = new ConfigurationHelper(configuration).Dictionary;
206200

207-
gitVersionOptions = new GitVersionOptions
208-
{
209-
WorkingDirectory = fixture.RepositoryPath,
210-
ConfigurationInfo = { OverrideConfiguration = overrideConfiguration }
211-
};
201+
gitVersionOptions = new GitVersionOptions { WorkingDirectory = fixture.RepositoryPath, ConfigurationInfo = { OverrideConfiguration = overrideConfiguration } };
212202

213203
gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions);
214204
versionVariables = gitVersionCalculator.CalculateVersionVariables();
@@ -283,9 +273,12 @@ public void ConfigChangeInvalidatesCache(string configFileName)
283273
var versionVariables = gitVersionCalculator.CalculateVersionVariables();
284274

285275
versionVariables.AssemblySemVer.ShouldBe("0.0.1.0");
286-
versionVariables.FileName.ShouldNotBeNullOrEmpty();
287276

288-
this.fileSystem.WriteAllText(versionVariables.FileName, versionCacheFileContent);
277+
var cacheKeyFactory = this.sp.GetRequiredService<IGitVersionCacheKeyFactory>();
278+
var cacheKey = cacheKeyFactory.Create(null);
279+
var cacheFileName = this.gitVersionCache.GetCacheFileName(cacheKey);
280+
281+
this.fileSystem.WriteAllText(cacheFileName, versionCacheFileContent);
289282

290283
versionVariables = gitVersionCalculator.CalculateVersionVariables();
291284
versionVariables.AssemblySemVer.ShouldBe("4.10.3.0");
@@ -340,9 +333,12 @@ public void NoCacheBypassesCache()
340333
var versionVariables = gitVersionCalculator.CalculateVersionVariables();
341334

342335
versionVariables.AssemblySemVer.ShouldBe("0.0.1.0");
343-
versionVariables.FileName.ShouldNotBeNullOrEmpty();
344336

345-
this.fileSystem.WriteAllText(versionVariables.FileName, versionCacheFileContent);
337+
var cacheKeyFactory = this.sp.GetRequiredService<IGitVersionCacheKeyFactory>();
338+
var cacheKey = cacheKeyFactory.Create(null);
339+
var cacheFileName = this.gitVersionCache.GetCacheFileName(cacheKey);
340+
341+
this.fileSystem.WriteAllText(cacheFileName, versionCacheFileContent);
346342
versionVariables = gitVersionCalculator.CalculateVersionVariables();
347343
versionVariables.AssemblySemVer.ShouldBe("4.10.3.0");
348344

@@ -394,11 +390,7 @@ public void GetProjectRootDirectoryWorkingDirectoryWithWorktree()
394390

395391
const string targetUrl = "https://github.com/GitTools/GitVersion.git";
396392

397-
var gitVersionOptions = new GitVersionOptions
398-
{
399-
RepositoryInfo = { TargetUrl = targetUrl },
400-
WorkingDirectory = worktreePath
401-
};
393+
var gitVersionOptions = new GitVersionOptions { RepositoryInfo = { TargetUrl = targetUrl }, WorkingDirectory = worktreePath };
402394

403395
this.sp = GetServiceProvider(gitVersionOptions);
404396
var repositoryInfo = this.sp.GetRequiredService<IGitRepositoryInfo>();
@@ -416,11 +408,7 @@ public void GetProjectRootDirectoryNoWorktree()
416408
using var fixture = new EmptyRepositoryFixture();
417409
const string targetUrl = "https://github.com/GitTools/GitVersion.git";
418410

419-
var gitVersionOptions = new GitVersionOptions
420-
{
421-
RepositoryInfo = { TargetUrl = targetUrl },
422-
WorkingDirectory = fixture.RepositoryPath
423-
};
411+
var gitVersionOptions = new GitVersionOptions { RepositoryInfo = { TargetUrl = targetUrl }, WorkingDirectory = fixture.RepositoryPath };
424412

425413
this.sp = GetServiceProvider(gitVersionOptions);
426414
var repositoryInfo = this.sp.GetRequiredService<IGitRepositoryInfo>();
@@ -434,10 +422,7 @@ public void GetDotGitDirectoryNoWorktree()
434422
{
435423
using var fixture = new EmptyRepositoryFixture();
436424

437-
var gitVersionOptions = new GitVersionOptions
438-
{
439-
WorkingDirectory = fixture.RepositoryPath
440-
};
425+
var gitVersionOptions = new GitVersionOptions { WorkingDirectory = fixture.RepositoryPath };
441426

442427
this.sp = GetServiceProvider(gitVersionOptions);
443428
var repositoryInfo = this.sp.GetRequiredService<IGitRepositoryInfo>();
@@ -459,10 +444,7 @@ public void GetDotGitDirectoryWorktree()
459444
var repo = new Repository(fixture.RepositoryPath);
460445
repo.Worktrees.Add("worktree", worktreePath, false);
461446

462-
var gitVersionOptions = new GitVersionOptions
463-
{
464-
WorkingDirectory = worktreePath
465-
};
447+
var gitVersionOptions = new GitVersionOptions { WorkingDirectory = worktreePath };
466448

467449
this.sp = GetServiceProvider(gitVersionOptions);
468450
var repositoryInfo = this.sp.GetRequiredService<IGitRepositoryInfo>();

src/GitVersion.Core/OutputVariables/GitVersionVariables.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using static GitVersion.Extensions.ObjectExtensions;
2-
31
namespace GitVersion.OutputVariables;
42

53
public record GitVersionVariables(string Major,
@@ -86,9 +84,6 @@ public record GitVersionVariables(string Major,
8684
{ nameof(UncommittedChanges), UncommittedChanges }
8785
};
8886

89-
[ReflectionIgnore]
90-
public string? FileName { get; set; }
91-
9287
public IEnumerator<KeyValuePair<string, string?>> GetEnumerator() => Instance.GetEnumerator();
9388

9489
IEnumerator IEnumerable.GetEnumerator() => Instance.GetEnumerator();

src/GitVersion.Core/OutputVariables/VersionVariablesHelper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ private static GitVersionVariables FromFileInternal(string filePath, IFileSystem
6969
using var reader = new StreamReader(stream);
7070
var dictionary = new Deserializer().Deserialize<Dictionary<string, string>>(reader);
7171
var versionVariables = FromDictionary(dictionary);
72-
versionVariables.FileName = filePath;
7372
return versionVariables;
7473
}
7574

src/GitVersion.Core/VersionCalculation/Caching/GitVersionCache.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ public GitVersionCache(IFileSystem fileSystem, ILog log, IGitRepositoryInfo repo
2121

2222
public void WriteVariablesToDiskCache(GitVersionCacheKey cacheKey, GitVersionVariables variablesFromCache)
2323
{
24-
var cacheDir = PrepareCacheDirectory();
25-
var cacheFileName = GetCacheFileName(cacheKey, cacheDir);
26-
27-
variablesFromCache.FileName = cacheFileName;
24+
var cacheFileName = GetCacheFileName(cacheKey);
2825

2926
Dictionary<string, string?> dictionary;
3027
using (this.log.IndentLog("Creating dictionary"))
@@ -47,6 +44,13 @@ void WriteCacheOperation()
4744
retryOperation.Execute(WriteCacheOperation);
4845
}
4946

47+
public string GetCacheFileName(GitVersionCacheKey cacheKey)
48+
{
49+
var cacheDir = PrepareCacheDirectory();
50+
var cacheFileName = GetCacheFileName(cacheKey, cacheDir);
51+
return cacheFileName;
52+
}
53+
5054
public string GetCacheDirectory()
5155
{
5256
var gitDir = this.repositoryInfo.DotGitDirectory;

src/GitVersion.Core/VersionCalculation/Caching/IGitVersionCache.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ public interface IGitVersionCache
77
void WriteVariablesToDiskCache(GitVersionCacheKey cacheKey, GitVersionVariables variablesFromCache);
88
string GetCacheDirectory();
99
GitVersionVariables? LoadVersionVariablesFromDiskCache(GitVersionCacheKey key);
10+
string GetCacheFileName(GitVersionCacheKey cacheKey);
1011
}

0 commit comments

Comments
 (0)