Skip to content

Commit 35c696a

Browse files
authored
Merge pull request #951 from JakeGinnivan/CacheKeysFixes
Cache keys fixes
2 parents 55212eb + 91b67b7 commit 35c696a

24 files changed

+569
-176
lines changed

docs/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ GitVersion 3.0 is mainly powered by configuration and no longer has branching st
44
## Configuration tool
55
If you run `GitVersion init` you will be launched into a configuration tool, it can help you configure GitVersion the way you want it.
66

7+
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.
8+
79
**Note:** GitVersion ships with internal default configuration which works with GitHubFlow and GitFlow, probably with others too.
810

911
The *develop* branch is set to `ContinuousDeployment` mode by default as we have found that is generally what is needed when using GitFlow.

docs/usage/command-line.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,14 @@ Will result in command line argument error
5454
### Example: When AssemblyInfo.cs and AssemblyVersionInfo.cs already exist
5555
`GitVersion.exe /updateassemblyinfo AssemblyInfo.cs AssemblyVersionInfo.cs`
5656

57-
Will iterate through each file and update known attributes (`AssemblyVersion`, `AssemblyFileVersion`, `AssemblyInformationalVersion`).
57+
Will iterate through each file and update known attributes (`AssemblyVersion`, `AssemblyFileVersion`, `AssemblyInformationalVersion`).
58+
59+
## Override config
60+
`/overrideconfig [key=value]` will override appropriate key from 'GitVersion.yml'.
61+
62+
At the moment only `tag-prefix` option is supported. Read more about [Configuration](/configuration/).
63+
64+
It will not change config file 'GitVersion.yml'.
65+
66+
### Example: How to override configuration option 'tag-prefix' to use prefix 'custom'
67+
`GitVersion.exe /output json /overrideconfig tag-prefix=custom`

src/GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1+
using GitVersion;
2+
using GitVersion.Helpers;
3+
using NUnit.Framework;
4+
using Shouldly;
15
using System;
6+
using System.ComponentModel;
27
using System.IO;
38
using System.Linq;
49
using System.Reflection;
510
using System.Runtime.CompilerServices;
6-
using GitVersion;
7-
using GitVersion.Helpers;
8-
using NUnit.Framework;
9-
using Shouldly;
1011
using YamlDotNet.Serialization;
1112

1213
[TestFixture]
1314
public class ConfigProviderTests
1415
{
16+
private const string DefaultRepoPath = "c:\\MyGitRepo";
17+
private const string DefaultWorkingPath = "c:\\MyGitRepo\\Working";
18+
1519
string repoPath;
20+
string workingPath;
1621
IFileSystem fileSystem;
1722

1823
[SetUp]
1924
public void Setup()
2025
{
2126
fileSystem = new TestFileSystem();
22-
repoPath = "c:\\MyGitRepo";
27+
repoPath = DefaultRepoPath;
28+
workingPath = DefaultWorkingPath;
2329
}
2430

2531
[Test]
@@ -112,7 +118,7 @@ public void CanProvideConfigForNewBranch()
112118
tag: bugfix";
113119
SetupConfigFileContent(text);
114120
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
115-
121+
116122
config.Branches["bug[/-]"].Tag.ShouldBe("bugfix");
117123
}
118124

@@ -145,10 +151,10 @@ public void NextVersionCanHavePatch()
145151

146152
config.NextVersion.ShouldBe("2.12.654651698");
147153
}
148-
154+
149155
[Test]
150-
[Category("NoMono")]
151-
[Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")]
156+
[NUnit.Framework.Category("NoMono")]
157+
[NUnit.Framework.Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")]
152158
[MethodImpl(MethodImplOptions.NoInlining)]
153159
public void CanWriteOutEffectiveConfiguration()
154160
{
@@ -228,18 +234,52 @@ public void VerifyAliases()
228234
propertiesMissingAlias.ShouldBeEmpty();
229235
}
230236

231-
[Test]
232-
public void WarnOnExistingGitVersionConfigYamlFile()
237+
[TestCase(DefaultRepoPath)]
238+
[TestCase(DefaultWorkingPath)]
239+
public void WarnOnExistingGitVersionConfigYamlFile(string path)
233240
{
234-
SetupConfigFileContent(string.Empty, "GitVersionConfig.yaml");
241+
SetupConfigFileContent(string.Empty, ConfigurationProvider.ObsoleteConfigFileName, path);
235242

236-
var s = string.Empty;
237-
Action<string> action = info => { s = info; };
243+
var logOutput = string.Empty;
244+
Action<string> action = info => { logOutput = info; };
238245
Logger.SetLoggers(action, action, action);
239246

240-
ConfigurationProvider.Provide(repoPath, fileSystem);
247+
ConfigurationProvider.Verify(workingPath, repoPath, fileSystem);
241248

242-
s.Contains("'GitVersionConfig.yaml' is deprecated, use 'GitVersion.yml' instead.").ShouldBe(true);
249+
var configFileDeprecatedWarning = string.Format("{0}' is deprecated, use '{1}' instead", ConfigurationProvider.ObsoleteConfigFileName, ConfigurationProvider.DefaultConfigFileName);
250+
logOutput.Contains(configFileDeprecatedWarning).ShouldBe(true);
251+
}
252+
253+
[TestCase(DefaultRepoPath)]
254+
[TestCase(DefaultWorkingPath)]
255+
public void WarnOnAmbiguousConfigFilesAtTheSameProjectRootDirectory(string path)
256+
{
257+
SetupConfigFileContent(string.Empty, ConfigurationProvider.ObsoleteConfigFileName, path);
258+
SetupConfigFileContent(string.Empty, ConfigurationProvider.DefaultConfigFileName, path);
259+
260+
var logOutput = string.Empty;
261+
Action<string> action = info => { logOutput = info; };
262+
Logger.SetLoggers(action, action, action);
263+
264+
ConfigurationProvider.Verify(workingPath, repoPath, fileSystem);
265+
266+
var configFileDeprecatedWarning = string.Format("Ambiguous config files at '{0}'", path);
267+
logOutput.Contains(configFileDeprecatedWarning).ShouldBe(true);
268+
}
269+
270+
[TestCase(ConfigurationProvider.DefaultConfigFileName, ConfigurationProvider.DefaultConfigFileName)]
271+
[TestCase(ConfigurationProvider.DefaultConfigFileName, ConfigurationProvider.ObsoleteConfigFileName)]
272+
[TestCase(ConfigurationProvider.ObsoleteConfigFileName, ConfigurationProvider.DefaultConfigFileName)]
273+
[TestCase(ConfigurationProvider.ObsoleteConfigFileName, ConfigurationProvider.ObsoleteConfigFileName)]
274+
public void ThrowsExceptionOnAmbiguousConfigFileLocation(string repoConfigFile, string workingConfigFile)
275+
{
276+
var repositoryConfigFilePath = SetupConfigFileContent(string.Empty, repoConfigFile, repoPath);
277+
var workingDirectoryConfigFilePath = SetupConfigFileContent(string.Empty, workingConfigFile, workingPath);
278+
279+
WarningException exception = Should.Throw<WarningException>(() => { ConfigurationProvider.Verify(workingPath, repoPath, fileSystem); });
280+
281+
var expecedMessage = string.Format("Ambiguous config file selection from '{0}' and '{1}'", workingDirectoryConfigFilePath, repositoryConfigFilePath);
282+
exception.Message.ShouldBe(expecedMessage);
243283
}
244284

245285
[Test]
@@ -256,8 +296,16 @@ public void NoWarnOnGitVersionYmlFile()
256296
s.Length.ShouldBe(0);
257297
}
258298

259-
void SetupConfigFileContent(string text, string fileName = "GitVersion.yml")
299+
string SetupConfigFileContent(string text, string fileName = ConfigurationProvider.DefaultConfigFileName)
260300
{
261-
fileSystem.WriteAllText(Path.Combine(repoPath, fileName), text);
301+
return SetupConfigFileContent(text, fileName, repoPath);
302+
}
303+
304+
string SetupConfigFileContent(string text, string fileName, string path)
305+
{
306+
var fullPath = Path.Combine(path, fileName);
307+
fileSystem.WriteAllText(fullPath, text);
308+
309+
return fullPath;
262310
}
263-
}
311+
}

src/GitVersionCore.Tests/ExecuteCoreTests.cs

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using System;
2-
using System.IO;
3-
using System.Text;
4-
using GitTools.Testing;
1+
using GitTools.Testing;
52
using GitVersion;
63
using GitVersion.Helpers;
74
using NUnit.Framework;
85
using Shouldly;
6+
using System;
7+
using System.IO;
8+
using System.Text;
99

1010
[TestFixture]
1111
public class ExecuteCoreTests
@@ -60,6 +60,59 @@ public void CacheFileExistsOnDisk()
6060
info.ShouldContain("Deserializing version variables from cache file", () => info);
6161
}
6262

63+
64+
[Test]
65+
public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDynamicallyCalculatedWithoutSavingInCache()
66+
{
67+
const string versionCacheFileContent = @"
68+
Major: 4
69+
Minor: 10
70+
Patch: 3
71+
PreReleaseTag: test.19
72+
PreReleaseTagWithDash: -test.19
73+
PreReleaseLabel: test
74+
PreReleaseNumber: 19
75+
BuildMetaData:
76+
BuildMetaDataPadded:
77+
FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
78+
MajorMinorPatch: 4.10.3
79+
SemVer: 4.10.3-test.19
80+
LegacySemVer: 4.10.3-test19
81+
LegacySemVerPadded: 4.10.3-test0019
82+
AssemblySemVer: 4.10.3.0
83+
FullSemVer: 4.10.3-test.19
84+
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
85+
BranchName: feature/test
86+
Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
87+
NuGetVersionV2: 4.10.3-test0019
88+
NuGetVersion: 4.10.3-test0019
89+
CommitsSinceVersionSource: 19
90+
CommitsSinceVersionSourcePadded: 0019
91+
CommitDate: 2015-11-10
92+
";
93+
94+
var versionAndBranchFinder = new ExecuteCore(fileSystem);
95+
96+
RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
97+
{
98+
fileSystem.WriteAllText(vv.FileName, versionCacheFileContent);
99+
100+
var gitPreparer = new GitPreparer(null, null, null, false, fixture.RepositoryPath);
101+
var cacheDirectory = GitVersionCache.GetCacheDirectory(gitPreparer);
102+
103+
var cacheDirectoryTimestamp = fileSystem.GetLastDirectoryWrite(cacheDirectory);
104+
105+
vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null, new Config() { TagPrefix = "prefix" });
106+
107+
vv.AssemblySemVer.ShouldBe("0.1.0.0");
108+
109+
var cachedDirectoryTimestampAfter = fileSystem.GetLastDirectoryWrite(cacheDirectory);
110+
cachedDirectoryTimestampAfter.ShouldBe(cacheDirectoryTimestamp, () => "Cache was updated when override config was set");
111+
});
112+
113+
// TODO info.ShouldContain("Override config from command line", () => info);
114+
}
115+
63116
[Test]
64117
public void CacheFileIsMissing()
65118
{

src/GitVersionCore.Tests/TestFileSystem.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,9 @@ public long GetLastDirectoryWrite(string path)
101101
{
102102
return 1;
103103
}
104+
105+
public bool PathsEqual(string path, string otherPath)
106+
{
107+
return path == otherPath;
108+
}
104109
}

src/GitVersionCore.Tests/VersionFilters/MinDateVersionFilterTests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
using System;
2-
using GitVersion;
1+
using GitVersion;
32
using GitVersion.VersionCalculation.BaseVersionCalculators;
43
using GitVersion.VersionFilters;
5-
using LibGit2Sharp;
64
using NUnit.Framework;
75
using Shouldly;
6+
using System;
87

98
namespace GitVersionCore.Tests.VersionFilters
109
{
@@ -14,7 +13,6 @@ public class MinDateVersionFilterTests
1413
[Test]
1514
public void VerifyNullGuard()
1615
{
17-
var commit = new MockCommit();
1816
var dummy = DateTimeOffset.UtcNow.AddSeconds(1.0);
1917
var sut = new MinDateVersionFilter(dummy);
2018

@@ -51,8 +49,7 @@ public void WhenShaMismatchShouldNotExclude()
5149
[Test]
5250
public void ExcludeShouldAcceptVersionWithNullCommit()
5351
{
54-
Commit nullCommit = null;
55-
var version = new BaseVersion("dummy", false, new SemanticVersion(1), nullCommit, string.Empty);
52+
var version = new BaseVersion("dummy", false, new SemanticVersion(1), null, string.Empty);
5653
var futureDate = DateTimeOffset.UtcNow.AddYears(1);
5754
var sut = new MinDateVersionFilter(futureDate);
5855

src/GitVersionCore.Tests/VersionFilters/ShaVersionFilterTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using GitVersion;
33
using GitVersion.VersionCalculation.BaseVersionCalculators;
44
using GitVersion.VersionFilters;
5-
using LibGit2Sharp;
65
using NUnit.Framework;
76
using Shouldly;
87

@@ -54,8 +53,7 @@ public void WhenShaMismatchShouldNotExclude()
5453
[Test]
5554
public void ExcludeShouldAcceptVersionWithNullCommit()
5655
{
57-
Commit nullCommit = null;
58-
var version = new BaseVersion("dummy", false, new SemanticVersion(1), nullCommit, string.Empty);
56+
var version = new BaseVersion("dummy", false, new SemanticVersion(1), null, string.Empty);
5957
var sut = new ShaVersionFilter(new[] { "mismatched" });
6058

6159
string reason;

0 commit comments

Comments
 (0)