Skip to content

Commit 96060dc

Browse files
committed
Merge pull request #532 from JakeGinnivan/InitImprovements
Init improvements
2 parents 4a44d12 + 2c900df commit 96060dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+685
-237
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ We love contributions to get started contributing you might need:
33

44
- [Get started with git](http://rogerdudler.github.io/git-guide)
55
- [How to create a pull request](https://help.github.com/articles/using-pull-requests)
6-
- [An issue to work on](https://github.com/ParticularLabs/GitVersion/labels/up-for-grabs) - We are on [Up for grabs](http://up-for-grabs.net/), our up for grabs issues are tagged `up-for-grabs`
6+
- [An issue to work on](https://github.com/GitTools/GitVersion/labels/up-for-grabs) - We are on [Up for grabs](http://up-for-grabs.net/), our up for grabs issues are tagged `up-for-grabs`
77
- An understanding of our [architecture](#architecture) and how [we write tests](#writing-tests)
88

99
Once you know how to create a pull request and have an issue to work on, just post a comment saying you will work on it.
Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,48 @@
1-
assembly-versioning-scheme: MajorMinorPatch
2-
mode: ContinuousDelivery
3-
tag-prefix: '[vV]'
4-
continuous-delivery-fallback-tag: ci
5-
branches:
6-
master:
7-
tag:
8-
increment: Patch
9-
prevent-increment-of-merged-branch-version: true
10-
release[/-]:
11-
tag: beta
12-
feature[/-]:
13-
tag: useBranchName
14-
increment: Inherit
15-
hotfix[/-]:
16-
tag: beta
17-
support[/-]:
18-
tag:
19-
increment: Patch
20-
prevent-increment-of-merged-branch-version: true
21-
develop:
22-
mode: ContinuousDeployment
23-
tag: unstable
24-
increment: Minor
25-
track-merge-target: true
26-
(pull|pull\-requests|pr)[/-]:
27-
tag: PullRequest
28-
increment: Inherit
29-
tag-number-pattern: '[/-](?<number>\d+)[-/]'
1+
assembly-versioning-scheme: MajorMinorPatch
2+
mode: ContinuousDelivery
3+
tag-prefix: '[vV]'
4+
continuous-delivery-fallback-tag: ci
5+
branches:
6+
master:
7+
mode: ContinuousDelivery
8+
tag:
9+
increment: Patch
10+
prevent-increment-of-merged-branch-version: true
11+
track-merge-target: false
12+
release[/-]:
13+
mode: ContinuousDelivery
14+
tag: beta
15+
increment: Patch
16+
prevent-increment-of-merged-branch-version: true
17+
track-merge-target: false
18+
feature[/-]:
19+
mode: ContinuousDelivery
20+
tag: useBranchName
21+
increment: Inherit
22+
prevent-increment-of-merged-branch-version: false
23+
track-merge-target: false
24+
(pull|pull\-requests|pr)[/-]:
25+
mode: ContinuousDelivery
26+
tag: PullRequest
27+
increment: Inherit
28+
prevent-increment-of-merged-branch-version: false
29+
tag-number-pattern: '[/-](?<number>\d+)[-/]'
30+
track-merge-target: false
31+
hotfix[/-]:
32+
mode: ContinuousDelivery
33+
tag: beta
34+
increment: Patch
35+
prevent-increment-of-merged-branch-version: false
36+
track-merge-target: false
37+
support[/-]:
38+
mode: ContinuousDelivery
39+
tag:
40+
increment: Patch
41+
prevent-increment-of-merged-branch-version: true
42+
track-merge-target: false
43+
develop:
44+
mode: ContinuousDeployment
45+
tag: unstable
46+
increment: Minor
47+
prevent-increment-of-merged-branch-version: false
48+
track-merge-target: true

src/GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,24 @@ public void CanReadOldDocument()
6464
var error = Should.Throw<OldConfigurationException>(() => ConfigurationProvider.Provide(repoPath, fileSystem));
6565
error.Message.ShouldContainWithoutWhitespace(@"GitVersionConfig.yaml contains old configuration, please fix the following errors:
6666
assemblyVersioningScheme has been replaced by assembly-versioning-scheme
67-
develop-branch-tag has been replaced by branch specific configuration.See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration
68-
release-branch-tag has been replaced by branch specific configuration.See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration");
67+
develop-branch-tag has been replaced by branch specific configuration.See http://gitversion.readthedocs.org/en/latest/configuration/#branch-configuration
68+
release-branch-tag has been replaced by branch specific configuration.See http://gitversion.readthedocs.org/en/latest/configuration/#branch-configuration");
6969
}
7070

7171
[Test]
7272
public void OverwritesDefaultsWithProvidedConfig()
7373
{
74+
var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem);
7475
const string text = @"
7576
next-version: 2.0.0
7677
branches:
7778
develop:
7879
mode: ContinuousDeployment
7980
tag: dev";
8081
SetupConfigFileContent(text);
81-
var defaultConfig = new Config();
8282
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
8383

8484
config.NextVersion.ShouldBe("2.0.0");
85-
config.AssemblyVersioningScheme.ShouldBe(defaultConfig.AssemblyVersioningScheme);
8685
config.Branches["develop"].Increment.ShouldBe(defaultConfig.Branches["develop"].Increment);
8786
config.Branches["develop"].VersioningMode.ShouldBe(defaultConfig.Branches["develop"].VersioningMode);
8887
config.Branches["develop"].Tag.ShouldBe("dev");
@@ -120,7 +119,7 @@ public void CanReadDefaultDocument()
120119
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
121120
config.Branches["develop"].Tag.ShouldBe("unstable");
122121
config.Branches["release[/-]"].Tag.ShouldBe("beta");
123-
config.TagPrefix.ShouldBe(Config.DefaultTagPrefix);
122+
config.TagPrefix.ShouldBe(ConfigurationProvider.DefaultTagPrefix);
124123
config.NextVersion.ShouldBe(null);
125124
}
126125

src/GitVersionCore.Tests/Fixtures/RepositoryFixtureBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public abstract class RepositoryFixtureBase : IDisposable
1616

1717
protected RepositoryFixtureBase(Func<string, IRepository> repoBuilder, Config configuration)
1818
{
19+
ConfigurationProvider.ApplyDefaultsTo(configuration);
1920
diagramBuilder = new StringBuilder();
2021
diagramBuilder.AppendLine("@startuml");
2122
this.configuration = configuration;

src/GitVersionCore.Tests/GitVersionContextBuilder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public GitVersionContextBuilder AddBranch(string branchName)
5858

5959
public GitVersionContext Build()
6060
{
61-
return new GitVersionContext(repository ?? CreateRepository(), config ?? new Config());
61+
var configuration = config ?? new Config();
62+
ConfigurationProvider.ApplyDefaultsTo(configuration);
63+
return new GitVersionContext(repository ?? CreateRepository(), configuration);
6264
}
6365

6466
IRepository CreateRepository()

src/GitVersionCore.Tests/GitVersionContextTests.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public void CanInheritVersioningMode(VersioningMode mode)
1515
{
1616
VersioningMode = mode
1717
};
18+
ConfigurationProvider.ApplyDefaultsTo(config);
1819

1920
var mockBranch = new MockBranch("master") { new MockCommit { CommitterEx = SignatureBuilder.SignatureNow() } };
2021
var mockRepository = new MockRepository
@@ -34,10 +35,19 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults()
3435
{
3536
var config = new Config
3637
{
37-
VersioningMode = VersioningMode.ContinuousDelivery
38+
VersioningMode = VersioningMode.ContinuousDelivery,
39+
Branches =
40+
{
41+
{
42+
"develop", new BranchConfig
43+
{
44+
VersioningMode = VersioningMode.ContinuousDeployment,
45+
Tag = "alpha"
46+
}
47+
}
48+
}
3849
};
39-
config.Branches["develop"].VersioningMode = VersioningMode.ContinuousDeployment;
40-
config.Branches["develop"].Tag = "alpha";
50+
ConfigurationProvider.ApplyDefaultsTo(config);
4151
var develop = new MockBranch("develop") { new MockCommit { CommitterEx = SignatureBuilder.SignatureNow() } };
4252
var mockRepository = new MockRepository
4353
{
@@ -54,9 +64,14 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults()
5464
[Test]
5565
public void CanFindParentBranchForInheritingIncrementStrategy()
5666
{
57-
var config = new Config();
58-
config.Branches["develop"].Increment = IncrementStrategy.Major;
59-
config.Branches["feature[/-]"].Increment = IncrementStrategy.Inherit;
67+
var config = new Config
68+
{
69+
Branches =
70+
{
71+
{ "develop", new BranchConfig { Increment = IncrementStrategy.Major} },
72+
{ "feature[/-]", new BranchConfig { Increment = IncrementStrategy.Inherit} }
73+
}
74+
};
6075

6176
using (var repo = new EmptyRepositoryFixture(config))
6277
{

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@
5353
<SpecificVersion>False</SpecificVersion>
5454
<HintPath>..\packages\LibGit2Sharp.0.20.1.0\lib\net40\LibGit2Sharp.dll</HintPath>
5555
</Reference>
56+
<Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
57+
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll</HintPath>
58+
<Private>True</Private>
59+
</Reference>
60+
<Reference Include="Mono.Cecil.Mdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
61+
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll</HintPath>
62+
<Private>True</Private>
63+
</Reference>
64+
<Reference Include="Mono.Cecil.Pdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
65+
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll</HintPath>
66+
<Private>True</Private>
67+
</Reference>
68+
<Reference Include="Mono.Cecil.Rocks, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
69+
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
70+
<Private>True</Private>
71+
</Reference>
5672
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
5773
<SpecificVersion>False</SpecificVersion>
5874
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
@@ -68,6 +84,10 @@
6884
<Reference Include="System.Data.DataSetExtensions" />
6985
<Reference Include="System.Data" />
7086
<Reference Include="System.Xml" />
87+
<Reference Include="TestStack.ConventionTests, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
88+
<HintPath>..\packages\TestStack.ConventionTests.2.2.1\lib\net40\TestStack.ConventionTests.dll</HintPath>
89+
<Private>True</Private>
90+
</Reference>
7191
<Reference Include="YamlDotNet, Version=3.5.0.0, Culture=neutral, processorArchitecture=MSIL">
7292
<SpecificVersion>False</SpecificVersion>
7393
<HintPath>..\packages\YamlDotNet.3.5.1\lib\net35\YamlDotNet.dll</HintPath>
@@ -85,6 +105,9 @@
85105
<Compile Include="Fixtures\BaseGitFlowRepositoryFixture.cs" />
86106
<Compile Include="GitVersionContextTests.cs" />
87107
<Compile Include="Helpers\DirectoryHelper.cs" />
108+
<Compile Include="Init\InitScenarios.cs" />
109+
<Compile Include="Init\InitStepsDefaultResponsesDoNotThrow.cs" />
110+
<Compile Include="Init\TestConsole.cs" />
88111
<Compile Include="IntegrationTests\OtherScenarios.cs" />
89112
<Compile Include="IntegrationTests\PullRequestScenarios.cs" />
90113
<Compile Include="IntegrationTests\RemoteRepositoryScenarios.cs" />
@@ -124,6 +147,7 @@
124147
<Compile Include="SemanticVersionTests.cs" />
125148
<Compile Include="TestEffectiveConfiguration.cs" />
126149
<Compile Include="TestFileSystem.cs" />
150+
<Compile Include="TestStream.cs" />
127151
<Compile Include="VariableProviderTests.cs" />
128152
<Compile Include="VersionCalculation\BaseVersionCalculatorTests.cs" />
129153
<Compile Include="VersionCalculation\NextVersionCalculatorTests.cs" />
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
next-version: 2.0.0
2+
branches: {}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace GitVersionCore.Tests.Init
2+
{
3+
using ApprovalTests;
4+
using GitVersion;
5+
using GitVersion.Configuration.Init;
6+
using GitVersion.Configuration.Init.Wizard;
7+
using NUnit.Framework;
8+
using TestStack.ConventionTests;
9+
using TestStack.ConventionTests.ConventionData;
10+
11+
[TestFixture]
12+
public class InitScenarios
13+
{
14+
[Test]
15+
public void CanSetNextVersion()
16+
{
17+
var testFileSystem = new TestFileSystem();
18+
var testConsole = new TestConsole("3", "2.0.0", "0");
19+
ConfigurationProvider.Init("c:\\proj", testFileSystem, testConsole);
20+
21+
Approvals.Verify(testFileSystem.ReadAllText("c:\\proj\\GitVersionConfig.yaml"));
22+
}
23+
24+
[Test]
25+
public void DefaultResponsesDoNotThrow()
26+
{
27+
var steps = Types.InAssemblyOf<EditConfigStep>(t => t.IsSubclassOf(typeof(ConfigInitWizardStep)) && t.IsConcreteClass());
28+
Convention.Is(new InitStepsDefaultResponsesDoNotThrow(), steps);
29+
}
30+
}
31+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace GitVersionCore.Tests.Init
2+
{
3+
using System;
4+
using System.Linq;
5+
using System.Reflection;
6+
using GitVersion.Configuration.Init.Wizard;
7+
using TestStack.ConventionTests;
8+
using TestStack.ConventionTests.ConventionData;
9+
10+
public class InitStepsDefaultResponsesDoNotThrow : IConvention<Types>
11+
{
12+
public void Execute(Types data, IConventionResultContext result)
13+
{
14+
var resultProperty = typeof(ConfigInitWizardStep).GetProperty("DefaultResult", BindingFlags.NonPublic | BindingFlags.Instance);
15+
result
16+
.Is("Init steps default response should not throw",
17+
data.TypesToVerify.Where(t =>
18+
{
19+
var constructorInfo = t.GetConstructors().Single();
20+
var ctorArguments = constructorInfo.GetParameters().Select(p => p.ParameterType.IsValueType ? Activator.CreateInstance(p.ParameterType) : null).ToArray();
21+
var instance = Activator.CreateInstance(t, ctorArguments);
22+
try
23+
{
24+
resultProperty.GetValue(instance);
25+
}
26+
catch (Exception)
27+
{
28+
return true;
29+
}
30+
return false;
31+
}));
32+
}
33+
34+
public string ConventionReason { get { return "So things do not blow up"; } }
35+
}
36+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
namespace GitVersionCore.Tests.Init
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using GitVersion;
6+
7+
public class TestConsole : IConsole
8+
{
9+
readonly Queue<string> responses;
10+
11+
public TestConsole(params string[] responses)
12+
{
13+
this.responses = new Queue<string>(responses);
14+
}
15+
16+
public void WriteLine(string msg)
17+
{
18+
Logger.WriteInfo(msg + Environment.NewLine);
19+
}
20+
21+
public void WriteLine()
22+
{
23+
Logger.WriteInfo(Environment.NewLine);
24+
}
25+
26+
public void Write(string msg)
27+
{
28+
Logger.WriteInfo(msg);
29+
}
30+
31+
public string ReadLine()
32+
{
33+
return responses.Dequeue();
34+
}
35+
36+
public IDisposable UseColor(ConsoleColor consoleColor)
37+
{
38+
return new NoOpDisposable();
39+
}
40+
41+
class NoOpDisposable : IDisposable
42+
{
43+
public void Dispose() { }
44+
}
45+
}
46+
}

src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ public void WhenDevelopBranchedFromTaggedCommitOnMasterVersionDoesNotChange()
5555
[Test]
5656
public void CanChangeDevelopTagViaConfig()
5757
{
58-
var config = new Config();
59-
config.Branches["develop"].Tag = "alpha";
58+
var config = new Config
59+
{
60+
Branches =
61+
{
62+
{ "develop", new BranchConfig { Tag = "alpha" } }
63+
}
64+
};
6065
using (var fixture = new EmptyRepositoryFixture(config))
6166
{
6267
fixture.Repository.MakeATaggedCommit("1.0.0");
@@ -100,8 +105,13 @@ public void MergingReleaseBranchBackIntoDevelopWithMergingToMaster_DoesBumpDevel
100105
[Test]
101106
public void CanHandleContinuousDelivery()
102107
{
103-
var config = new Config();
104-
config.Branches["develop"].VersioningMode = VersioningMode.ContinuousDelivery;
108+
var config = new Config
109+
{
110+
Branches =
111+
{
112+
{ "develop", new BranchConfig { VersioningMode = VersioningMode.ContinuousDelivery} }
113+
}
114+
};
105115
using (var fixture = new EmptyRepositoryFixture(config))
106116
{
107117
fixture.Repository.MakeATaggedCommit("1.0.0");

0 commit comments

Comments
 (0)