Skip to content

Fixed issues #863 and #870: invalid cache key computation and config file location #892

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

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f31647c
checking ambigous and obsolete config files at workingDirectory and r…
sergiorykov Jun 4, 2016
e26c557
select config file from working directory first and only then use pro…
sergiorykov Jun 4, 2016
c4d8a4d
added tests for verification config files + a bit of refactoring
sergiorykov Jun 4, 2016
eb83ac1
Merge branch 'master' into master
sergiorykov Jun 10, 2016
9853c79
code style
sergiorykov Jun 14, 2016
87771fe
Test ThrowsExceptionOnAmbigousConfigFileLocation verifies WarningExce…
sergiorykov Jun 14, 2016
7a2e309
* ConfigurationProvider.cs clean code
sergiorykov Jun 14, 2016
9d592ab
Revert "* ConfigurationProvider.cs clean code"
sergiorykov Jun 14, 2016
fa26078
* ConfigurationProvider.cs refactoring: extracted WarnAboutAmbigousCo…
sergiorykov Jun 14, 2016
ddaff32
* HelpWriter.cs fixed default config file name: GitVersion.yaml -> Gi…
sergiorykov Jun 14, 2016
02036f9
* GitVersionCache.cs refactoring: improved readibility
sergiorykov Jun 14, 2016
764ee79
fixed bug: /overrideconfig was ignored in caching results
sergiorykov Jun 14, 2016
ca604a1
Tests for parsing option /overrideconfig
sergiorykov Jun 14, 2016
0366f69
added test for applying /overrideconfig option from command line
sergiorykov Jun 14, 2016
0eb743f
fixed typo in warning exception messages: ambigous -> ambiguous
sergiorykov Jun 19, 2016
cfd90da
* ConfigurationProvider.cs reverted back rules formatting for Migrate…
sergiorykov Jun 19, 2016
f2db2a4
* docs\configuration.md added comment about generation GitVersion.yml
sergiorykov Jun 19, 2016
dbc988b
added overrideConfig to cache key
sergiorykov Jul 16, 2016
c9ce4d8
* ConfigurationProvider.cs refactored MigrateBranches - clean&readabl…
sergiorykov Jul 16, 2016
c2a7d2e
added /ovverideconfig option to command line docs
sergiorykov Jul 16, 2016
96e41c7
* docs\configuration.md corrected text about location of config file …
sergiorykov Jul 16, 2016
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
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);

var info = 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");
});

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,10 @@
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 +14,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
Loading