Skip to content

Add nocache argument to bypass file cache #1020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/GitVersionCore.Tests/ExecuteCoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,50 @@ public void ConfigChangeInvalidatesCache()
});
}

[Test]
public void NoCacheBypassesCache()
{
const string versionCacheFileContent = @"
Major: 4
Minor: 10
Patch: 3
PreReleaseTag: test.19
PreReleaseTagWithDash: -test.19
PreReleaseLabel: test
PreReleaseNumber: 19
BuildMetaData:
BuildMetaDataPadded:
FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
MajorMinorPatch: 4.10.3
SemVer: 4.10.3-test.19
LegacySemVer: 4.10.3-test19
LegacySemVerPadded: 4.10.3-test0019
AssemblySemVer: 4.10.3.0
FullSemVer: 4.10.3-test.19
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
BranchName: feature/test
Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
NuGetVersionV2: 4.10.3-test0019
NuGetVersion: 4.10.3-test0019
NuGetPreReleaseTagV2: test0019
NuGetPreReleaseTag: test0019
CommitsSinceVersionSource: 19
CommitsSinceVersionSourcePadded: 0019
CommitDate: 2015-11-10
";

var versionAndBranchFinder = new ExecuteCore(fileSystem);

RepositoryScope(versionAndBranchFinder, (fixture, vv) => {
fileSystem.WriteAllText(vv.FileName, versionCacheFileContent);
vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null);
vv.AssemblySemVer.ShouldBe("4.10.3.0");

vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null, noCache: true);
vv.AssemblySemVer.ShouldBe("0.1.0.0");
});
}


[Test]
public void WorkingDirectoryWithoutGit()
Expand Down
19 changes: 11 additions & 8 deletions src/GitVersionCore/ExecuteCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ExecuteCore(IFileSystem fileSystem)
gitVersionCache = new GitVersionCache(fileSystem);
}

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

var cacheKey = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, overrideConfig);
var versionVariables = gitVersionCache.LoadVersionVariablesFromDiskCache(gitPreparer, cacheKey);
var versionVariables = noCache ? default(VersionVariables) : gitVersionCache.LoadVersionVariablesFromDiskCache(gitPreparer, cacheKey);
if (versionVariables == null)
{
versionVariables = ExecuteInternal(targetBranch, commitId, gitPreparer, buildServer, overrideConfig);

try
if (!noCache)
{
gitVersionCache.WriteVariablesToDiskCache(gitPreparer, cacheKey, versionVariables);
}
catch (AggregateException e)
{
Logger.WriteWarning(string.Format("One or more exceptions during cache write:{0}{1}", Environment.NewLine, e));
try
{
gitVersionCache.WriteVariablesToDiskCache(gitPreparer, cacheKey, versionVariables);
}
catch (AggregateException e)
{
Logger.WriteWarning(string.Format("One or more exceptions during cache write:{0}{1}", Environment.NewLine, e));
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/GitVersionExe.Tests/ArgumentParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,11 @@ public void boolean_argument_handling()
arguments.NoFetch.ShouldBe(true);
arguments.UpdateAssemblyInfo.ShouldBe(true);
}

[Test]
public void nocache_true_when_defined()
{
var arguments = ArgumentParser.ParseArguments("-nocache");
arguments.NoCache.ShouldBe(true);
}
}
6 changes: 6 additions & 0 deletions src/GitVersionExe/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
continue;
}

if (name.IsSwitch("nocache"))
{
arguments.NoCache = true;
continue;
}

var couldNotParseMessage = string.Format("Could not parse command line parameter '{0}'.", name);

// 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.
Expand Down
1 change: 1 addition & 0 deletions src/GitVersionExe/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public Arguments()

public bool ShowConfig;
public bool NoFetch;
public bool NoCache;

public void AddAssemblyInfoFileName(string fileName)
{
Expand Down
1 change: 1 addition & 0 deletions src/GitVersionExe/HelpWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ path The directory containing .git. If not defined current directory
/showconfig Outputs the effective GitVersion config (defaults + custom from GitVersion.yml) in yaml format
/overrideconfig Overrides GitVersion config values inline (semicolon-separated key value pairs e.g. /overrideconfig tag-prefix=Foo)
Currently supported config overrides: tag-prefix
/nocache Bypasses the cache, result will not be written to the cache.

# AssemblyInfo updating
/updateassemblyinfo
Expand Down
3 changes: 2 additions & 1 deletion src/GitVersionExe/SpecifiedArgumentRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ public static void Run(Arguments arguments, IFileSystem fileSystem)
var targetBranch = arguments.TargetBranch;
var commitId = arguments.CommitId;
var overrideConfig = arguments.HasOverrideConfig ? arguments.OverrideConfig : null;
var noCache = arguments.NoCache;

var executeCore = new ExecuteCore(fileSystem);
var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig);
var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig, noCache);

if (arguments.Output == OutputType.BuildServer)
{
Expand Down