Skip to content

Commit 3fb114b

Browse files
author
Guillaume Rouchon
committed
Add nocache argument to bypass file cache
1 parent 5dce5c1 commit 3fb114b

File tree

7 files changed

+72
-9
lines changed

7 files changed

+72
-9
lines changed

src/GitVersionCore.Tests/ExecuteCoreTests.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,50 @@ public void ConfigChangeInvalidatesCache()
192192
});
193193
}
194194

195+
[Test]
196+
public void NoCacheBypassesCache()
197+
{
198+
const string versionCacheFileContent = @"
199+
Major: 4
200+
Minor: 10
201+
Patch: 3
202+
PreReleaseTag: test.19
203+
PreReleaseTagWithDash: -test.19
204+
PreReleaseLabel: test
205+
PreReleaseNumber: 19
206+
BuildMetaData:
207+
BuildMetaDataPadded:
208+
FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
209+
MajorMinorPatch: 4.10.3
210+
SemVer: 4.10.3-test.19
211+
LegacySemVer: 4.10.3-test19
212+
LegacySemVerPadded: 4.10.3-test0019
213+
AssemblySemVer: 4.10.3.0
214+
FullSemVer: 4.10.3-test.19
215+
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
216+
BranchName: feature/test
217+
Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
218+
NuGetVersionV2: 4.10.3-test0019
219+
NuGetVersion: 4.10.3-test0019
220+
NuGetPreReleaseTagV2: test0019
221+
NuGetPreReleaseTag: test0019
222+
CommitsSinceVersionSource: 19
223+
CommitsSinceVersionSourcePadded: 0019
224+
CommitDate: 2015-11-10
225+
";
226+
227+
var versionAndBranchFinder = new ExecuteCore(fileSystem);
228+
229+
RepositoryScope(versionAndBranchFinder, (fixture, vv) => {
230+
fileSystem.WriteAllText(vv.FileName, versionCacheFileContent);
231+
vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null);
232+
vv.AssemblySemVer.ShouldBe("4.10.3.0");
233+
234+
vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null, noCache: true);
235+
vv.AssemblySemVer.ShouldBe("0.1.0.0");
236+
});
237+
}
238+
195239

196240
[Test]
197241
public void WorkingDirectoryWithoutGit()

src/GitVersionCore/ExecuteCore.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public ExecuteCore(IFileSystem fileSystem)
1919
gitVersionCache = new GitVersionCache(fileSystem);
2020
}
2121

22-
public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId, Config overrideConfig = null)
22+
public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId, Config overrideConfig = null, bool noCache = false)
2323
{
2424
// Normalise if we are running on build server
2525
var applicableBuildServers = BuildServerList.GetApplicableBuildServers();
@@ -51,18 +51,21 @@ public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicReposi
5151
}
5252

5353
var cacheKey = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, overrideConfig);
54-
var versionVariables = gitVersionCache.LoadVersionVariablesFromDiskCache(gitPreparer, cacheKey);
54+
var versionVariables = noCache ? default(VersionVariables) : gitVersionCache.LoadVersionVariablesFromDiskCache(gitPreparer, cacheKey);
5555
if (versionVariables == null)
5656
{
5757
versionVariables = ExecuteInternal(targetBranch, commitId, gitPreparer, buildServer, overrideConfig);
5858

59-
try
59+
if (!noCache)
6060
{
61-
gitVersionCache.WriteVariablesToDiskCache(gitPreparer, cacheKey, versionVariables);
62-
}
63-
catch (AggregateException e)
64-
{
65-
Logger.WriteWarning(string.Format("One or more exceptions during cache write:{0}{1}", Environment.NewLine, e));
61+
try
62+
{
63+
gitVersionCache.WriteVariablesToDiskCache(gitPreparer, cacheKey, versionVariables);
64+
}
65+
catch (AggregateException e)
66+
{
67+
Logger.WriteWarning(string.Format("One or more exceptions during cache write:{0}{1}", Environment.NewLine, e));
68+
}
6669
}
6770
}
6871

src/GitVersionExe.Tests/ArgumentParserTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,11 @@ public void boolean_argument_handling()
331331
arguments.NoFetch.ShouldBe(true);
332332
arguments.UpdateAssemblyInfo.ShouldBe(true);
333333
}
334+
335+
[Test]
336+
public void nocache_true_when_defined()
337+
{
338+
var arguments = ArgumentParser.ParseArguments("-nocache");
339+
arguments.NoCache.ShouldBe(true);
340+
}
334341
}

src/GitVersionExe/ArgumentParser.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
306306
continue;
307307
}
308308

309+
if (name.IsSwitch("nocache"))
310+
{
311+
arguments.NoCache = true;
312+
continue;
313+
}
314+
309315
var couldNotParseMessage = string.Format("Could not parse command line parameter '{0}'.", name);
310316

311317
// If we've reached through all argument switches without a match, we can relatively safely assume that the first argument isn't a switch, but the target path.

src/GitVersionExe/Arguments.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public Arguments()
4343

4444
public bool ShowConfig;
4545
public bool NoFetch;
46+
public bool NoCache;
4647

4748
public void AddAssemblyInfoFileName(string fileName)
4849
{

src/GitVersionExe/HelpWriter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ path The directory containing .git. If not defined current directory
2727
/showconfig Outputs the effective GitVersion config (defaults + custom from GitVersion.yml) in yaml format
2828
/overrideconfig Overrides GitVersion config values inline (semicolon-separated key value pairs e.g. /overrideconfig tag-prefix=Foo)
2929
Currently supported config overrides: tag-prefix
30+
/nocache Bypasses the cache, result will not be written to the cache.
3031
3132
# AssemblyInfo updating
3233
/updateassemblyinfo

src/GitVersionExe/SpecifiedArgumentRunner.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ public static void Run(Arguments arguments, IFileSystem fileSystem)
2424
var targetBranch = arguments.TargetBranch;
2525
var commitId = arguments.CommitId;
2626
var overrideConfig = arguments.HasOverrideConfig ? arguments.OverrideConfig : null;
27+
var noCache = arguments.NoCache;
2728

2829
var executeCore = new ExecuteCore(fileSystem);
29-
var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig);
30+
var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig, noCache);
3031

3132
if (arguments.Output == OutputType.BuildServer)
3233
{

0 commit comments

Comments
 (0)