Skip to content

Commit

Permalink
Merge pull request #951 from JakeGinnivan/CacheKeysFixes
Browse files Browse the repository at this point in the history
Cache keys fixes
  • Loading branch information
JakeGinnivan authored Jul 17, 2016
2 parents 55212eb + 91b67b7 commit 35c696a
Show file tree
Hide file tree
Showing 24 changed files with 569 additions and 176 deletions.
2 changes: 2 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ GitVersion 3.0 is mainly powered by configuration and no longer has branching st
## Configuration tool
If you run `GitVersion init` you will be launched into a configuration tool, it can help you configure GitVersion the way you want it.

Once complete, the `init` command will create a `GitVersion.yml` file in the working directory. It can be the root repository directory or any subdirectory in case you have a single repository for more than one project or are restricted to commit into a subdirectory.

**Note:** GitVersion ships with internal default configuration which works with GitHubFlow and GitFlow, probably with others too.

The *develop* branch is set to `ContinuousDeployment` mode by default as we have found that is generally what is needed when using GitFlow.
Expand Down
12 changes: 11 additions & 1 deletion docs/usage/command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,14 @@ Will result in command line argument error
### Example: When AssemblyInfo.cs and AssemblyVersionInfo.cs already exist
`GitVersion.exe /updateassemblyinfo AssemblyInfo.cs AssemblyVersionInfo.cs`

Will iterate through each file and update known attributes (`AssemblyVersion`, `AssemblyFileVersion`, `AssemblyInformationalVersion`).
Will iterate through each file and update known attributes (`AssemblyVersion`, `AssemblyFileVersion`, `AssemblyInformationalVersion`).

## Override config
`/overrideconfig [key=value]` will override appropriate key from 'GitVersion.yml'.

At the moment only `tag-prefix` option is supported. Read more about [Configuration](/configuration/).

It will not change config file 'GitVersion.yml'.

### Example: How to override configuration option 'tag-prefix' to use prefix 'custom'
`GitVersion.exe /output json /overrideconfig tag-prefix=custom`
86 changes: 67 additions & 19 deletions src/GitVersionCore.Tests/ConfigProviderTests.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
using GitVersion;
using GitVersion.Helpers;
using NUnit.Framework;
using Shouldly;
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using GitVersion;
using GitVersion.Helpers;
using NUnit.Framework;
using Shouldly;
using YamlDotNet.Serialization;

[TestFixture]
public class ConfigProviderTests
{
private const string DefaultRepoPath = "c:\\MyGitRepo";
private const string DefaultWorkingPath = "c:\\MyGitRepo\\Working";

string repoPath;
string workingPath;
IFileSystem fileSystem;

[SetUp]
public void Setup()
{
fileSystem = new TestFileSystem();
repoPath = "c:\\MyGitRepo";
repoPath = DefaultRepoPath;
workingPath = DefaultWorkingPath;
}

[Test]
Expand Down Expand Up @@ -112,7 +118,7 @@ public void CanProvideConfigForNewBranch()
tag: bugfix";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(repoPath, fileSystem);

config.Branches["bug[/-]"].Tag.ShouldBe("bugfix");
}

Expand Down Expand Up @@ -145,10 +151,10 @@ public void NextVersionCanHavePatch()

config.NextVersion.ShouldBe("2.12.654651698");
}

[Test]
[Category("NoMono")]
[Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")]
[NUnit.Framework.Category("NoMono")]
[NUnit.Framework.Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")]
[MethodImpl(MethodImplOptions.NoInlining)]
public void CanWriteOutEffectiveConfiguration()
{
Expand Down Expand Up @@ -228,18 +234,52 @@ public void VerifyAliases()
propertiesMissingAlias.ShouldBeEmpty();
}

[Test]
public void WarnOnExistingGitVersionConfigYamlFile()
[TestCase(DefaultRepoPath)]
[TestCase(DefaultWorkingPath)]
public void WarnOnExistingGitVersionConfigYamlFile(string path)
{
SetupConfigFileContent(string.Empty, "GitVersionConfig.yaml");
SetupConfigFileContent(string.Empty, ConfigurationProvider.ObsoleteConfigFileName, path);

var s = string.Empty;
Action<string> action = info => { s = info; };
var logOutput = string.Empty;
Action<string> action = info => { logOutput = info; };
Logger.SetLoggers(action, action, action);

ConfigurationProvider.Provide(repoPath, fileSystem);
ConfigurationProvider.Verify(workingPath, repoPath, fileSystem);

s.Contains("'GitVersionConfig.yaml' is deprecated, use 'GitVersion.yml' instead.").ShouldBe(true);
var configFileDeprecatedWarning = string.Format("{0}' is deprecated, use '{1}' instead", ConfigurationProvider.ObsoleteConfigFileName, ConfigurationProvider.DefaultConfigFileName);
logOutput.Contains(configFileDeprecatedWarning).ShouldBe(true);
}

[TestCase(DefaultRepoPath)]
[TestCase(DefaultWorkingPath)]
public void WarnOnAmbiguousConfigFilesAtTheSameProjectRootDirectory(string path)
{
SetupConfigFileContent(string.Empty, ConfigurationProvider.ObsoleteConfigFileName, path);
SetupConfigFileContent(string.Empty, ConfigurationProvider.DefaultConfigFileName, path);

var logOutput = string.Empty;
Action<string> action = info => { logOutput = info; };
Logger.SetLoggers(action, action, action);

ConfigurationProvider.Verify(workingPath, repoPath, fileSystem);

var configFileDeprecatedWarning = string.Format("Ambiguous config files at '{0}'", path);
logOutput.Contains(configFileDeprecatedWarning).ShouldBe(true);
}

[TestCase(ConfigurationProvider.DefaultConfigFileName, ConfigurationProvider.DefaultConfigFileName)]
[TestCase(ConfigurationProvider.DefaultConfigFileName, ConfigurationProvider.ObsoleteConfigFileName)]
[TestCase(ConfigurationProvider.ObsoleteConfigFileName, ConfigurationProvider.DefaultConfigFileName)]
[TestCase(ConfigurationProvider.ObsoleteConfigFileName, ConfigurationProvider.ObsoleteConfigFileName)]
public void ThrowsExceptionOnAmbiguousConfigFileLocation(string repoConfigFile, string workingConfigFile)
{
var repositoryConfigFilePath = SetupConfigFileContent(string.Empty, repoConfigFile, repoPath);
var workingDirectoryConfigFilePath = SetupConfigFileContent(string.Empty, workingConfigFile, workingPath);

WarningException exception = Should.Throw<WarningException>(() => { ConfigurationProvider.Verify(workingPath, repoPath, fileSystem); });

var expecedMessage = string.Format("Ambiguous config file selection from '{0}' and '{1}'", workingDirectoryConfigFilePath, repositoryConfigFilePath);
exception.Message.ShouldBe(expecedMessage);
}

[Test]
Expand All @@ -256,8 +296,16 @@ public void NoWarnOnGitVersionYmlFile()
s.Length.ShouldBe(0);
}

void SetupConfigFileContent(string text, string fileName = "GitVersion.yml")
string SetupConfigFileContent(string text, string fileName = ConfigurationProvider.DefaultConfigFileName)
{
fileSystem.WriteAllText(Path.Combine(repoPath, fileName), text);
return SetupConfigFileContent(text, fileName, repoPath);
}

string SetupConfigFileContent(string text, string fileName, string path)
{
var fullPath = Path.Combine(path, fileName);
fileSystem.WriteAllText(fullPath, text);

return fullPath;
}
}
}
61 changes: 57 additions & 4 deletions src/GitVersionCore.Tests/ExecuteCoreTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.IO;
using System.Text;
using GitTools.Testing;
using GitTools.Testing;
using GitVersion;
using GitVersion.Helpers;
using NUnit.Framework;
using Shouldly;
using System;
using System.IO;
using System.Text;

[TestFixture]
public class ExecuteCoreTests
Expand Down Expand Up @@ -60,6 +60,59 @@ public void CacheFileExistsOnDisk()
info.ShouldContain("Deserializing version variables from cache file", () => info);
}


[Test]
public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDynamicallyCalculatedWithoutSavingInCache()
{
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
CommitsSinceVersionSource: 19
CommitsSinceVersionSourcePadded: 0019
CommitDate: 2015-11-10
";

var versionAndBranchFinder = new ExecuteCore(fileSystem);

RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
{
fileSystem.WriteAllText(vv.FileName, versionCacheFileContent);
var gitPreparer = new GitPreparer(null, null, null, false, fixture.RepositoryPath);
var cacheDirectory = GitVersionCache.GetCacheDirectory(gitPreparer);
var cacheDirectoryTimestamp = fileSystem.GetLastDirectoryWrite(cacheDirectory);
vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null, new Config() { TagPrefix = "prefix" });
vv.AssemblySemVer.ShouldBe("0.1.0.0");
var cachedDirectoryTimestampAfter = fileSystem.GetLastDirectoryWrite(cacheDirectory);
cachedDirectoryTimestampAfter.ShouldBe(cacheDirectoryTimestamp, () => "Cache was updated when override config was set");
});

// TODO info.ShouldContain("Override config from command line", () => info);
}

[Test]
public void CacheFileIsMissing()
{
Expand Down
5 changes: 5 additions & 0 deletions src/GitVersionCore.Tests/TestFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,9 @@ public long GetLastDirectoryWrite(string path)
{
return 1;
}

public bool PathsEqual(string path, string otherPath)
{
return path == otherPath;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using GitVersion;
using GitVersion;
using GitVersion.VersionCalculation.BaseVersionCalculators;
using GitVersion.VersionFilters;
using LibGit2Sharp;
using NUnit.Framework;
using Shouldly;
using System;

namespace GitVersionCore.Tests.VersionFilters
{
Expand All @@ -14,7 +13,6 @@ public class MinDateVersionFilterTests
[Test]
public void VerifyNullGuard()
{
var commit = new MockCommit();
var dummy = DateTimeOffset.UtcNow.AddSeconds(1.0);
var sut = new MinDateVersionFilter(dummy);

Expand Down Expand Up @@ -51,8 +49,7 @@ public void WhenShaMismatchShouldNotExclude()
[Test]
public void ExcludeShouldAcceptVersionWithNullCommit()
{
Commit nullCommit = null;
var version = new BaseVersion("dummy", false, new SemanticVersion(1), nullCommit, string.Empty);
var version = new BaseVersion("dummy", false, new SemanticVersion(1), null, string.Empty);
var futureDate = DateTimeOffset.UtcNow.AddYears(1);
var sut = new MinDateVersionFilter(futureDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using GitVersion;
using GitVersion.VersionCalculation.BaseVersionCalculators;
using GitVersion.VersionFilters;
using LibGit2Sharp;
using NUnit.Framework;
using Shouldly;

Expand Down Expand Up @@ -54,8 +53,7 @@ public void WhenShaMismatchShouldNotExclude()
[Test]
public void ExcludeShouldAcceptVersionWithNullCommit()
{
Commit nullCommit = null;
var version = new BaseVersion("dummy", false, new SemanticVersion(1), nullCommit, string.Empty);
var version = new BaseVersion("dummy", false, new SemanticVersion(1), null, string.Empty);
var sut = new ShaVersionFilter(new[] { "mismatched" });

string reason;
Expand Down
Loading

0 comments on commit 35c696a

Please sign in to comment.