Skip to content

Commit 5d86d09

Browse files
committed
Merge pull request #341 from JakeGinnivan/VariableProviderModes
Configuration Updates
2 parents 6f6305c + b9b2a2b commit 5d86d09

File tree

64 files changed

+334
-284
lines changed

Some content is hidden

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

64 files changed

+334
-284
lines changed

GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,6 @@ public void CanReadDocument()
5151
config.Branches["develop"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
5252
}
5353

54-
[Test]
55-
public void CanInheritVersioningMode()
56-
{
57-
const string text = @"
58-
mode: ContinuousDelivery
59-
branches:
60-
develop:
61-
mode: ContinuousDeployment
62-
";
63-
SetupConfigFileContent(text);
64-
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
65-
config.Branches["develop"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
66-
config.Branches["develop"].Tag.ShouldBe("unstable");
67-
config.Branches["release[/-]"].VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery);
68-
}
69-
7054
[Test]
7155
public void CanReadOldDocument()
7256
{
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
namespace GitVersionCore.Tests
2+
{
3+
using GitVersion;
4+
using NUnit.Framework;
5+
using Shouldly;
6+
7+
public class GitVersionContextTests
8+
{
9+
[Test]
10+
[Theory]
11+
public void CanInheritVersioningMode(VersioningMode mode)
12+
{
13+
var config = new Config
14+
{
15+
VersioningMode = mode
16+
};
17+
18+
var mockBranch = new MockBranch("master") { new MockCommit { CommitterEx = SignatureBuilder.SignatureNow() } };
19+
var mockRepository = new MockRepository
20+
{
21+
Branches = new MockBranchCollection
22+
{
23+
mockBranch
24+
}
25+
};
26+
27+
var context = new GitVersionContext(mockRepository, mockBranch, config);
28+
context.Configuration.VersioningMode.ShouldBe(mode);
29+
}
30+
31+
[Test]
32+
public void UsesBranchSpecificConfigOverTopLevelDefaults()
33+
{
34+
var config = new Config
35+
{
36+
VersioningMode = VersioningMode.ContinuousDelivery
37+
};
38+
config.Branches["develop"].VersioningMode = VersioningMode.ContinuousDeployment;
39+
config.Branches["develop"].Tag = "alpha";
40+
var develop = new MockBranch("develop") { new MockCommit { CommitterEx = SignatureBuilder.SignatureNow() } };
41+
var mockRepository = new MockRepository
42+
{
43+
Branches = new MockBranchCollection
44+
{
45+
new MockBranch("master") { new MockCommit { CommitterEx = SignatureBuilder.SignatureNow() } },
46+
develop
47+
}
48+
};
49+
var context = new GitVersionContext(mockRepository, develop, config);
50+
context.Configuration.VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
51+
context.Configuration.Tag.ShouldBe("alpha");
52+
}
53+
}
54+
}

GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<Compile Include="Fixtures\RemoteRepositoryFixture.cs" />
7575
<Compile Include="GitDirFinderTests.cs" />
7676
<Compile Include="Fixtures\BaseGitFlowRepositoryFixture.cs" />
77+
<Compile Include="GitVersionContextTests.cs" />
7778
<Compile Include="IntegrationTests\RemoteRepositoryTests.cs" />
7879
<Compile Include="IntegrationTests\GitFlow\DevelopScenarios.cs" />
7980
<Compile Include="IntegrationTests\GitFlow\FeatureBranchTests.cs" />
@@ -91,6 +92,18 @@
9192
<Compile Include="InformationalVersionBuilderTests.cs" />
9293
<Compile Include="IntegrationTests\GitHubFlow\SupportBranchScenarios.cs" />
9394
<Compile Include="JsonVersionBuilderTests.cs" />
95+
<Compile Include="Mocks\MockBranch.cs" />
96+
<Compile Include="Mocks\MockBranchCollection.cs" />
97+
<Compile Include="Mocks\MockCommit.cs" />
98+
<Compile Include="Mocks\MockCommitLog.cs" />
99+
<Compile Include="Mocks\MockMergeCommit.cs" />
100+
<Compile Include="Mocks\MockReferenceCollection.cs" />
101+
<Compile Include="Mocks\MockReflogCollection.cs" />
102+
<Compile Include="Mocks\MockRepository.cs" />
103+
<Compile Include="Mocks\MockTag.cs" />
104+
<Compile Include="Mocks\MockTagAnnotation.cs" />
105+
<Compile Include="Mocks\MockTagCollection.cs" />
106+
<Compile Include="Mocks\SignatureBuilder.cs" />
94107
<Compile Include="ModuleInitializer.cs" />
95108
<Compile Include="Fixtures\EmptyRepositoryFixture.cs" />
96109
<Compile Include="Helpers\GitTestExtensions.cs" />
@@ -99,6 +112,7 @@
99112
<Compile Include="ApprovalTestsConfig.cs" />
100113
<Compile Include="Fixtures\RepositoryFixtureBase.cs" />
101114
<Compile Include="SemanticVersionTests.cs" />
115+
<Compile Include="TestEffectiveConfiguration.cs" />
102116
<Compile Include="TestFileSystem.cs" />
103117
<Compile Include="VariableProviderTests.cs" />
104118
</ItemGroup>

GitVersionCore.Tests/IntegrationTests/GitFlow/MetaDataByCommitScenarios.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using GitVersion;
3+
using GitVersionCore.Tests;
34
using LibGit2Sharp;
45
using NUnit.Framework;
56
using Shouldly;
@@ -157,7 +158,7 @@ static void EnsureBranchMatch(CommitCountingRepoFixture fixture, string branchNa
157158
var referenceCommitFinder = commitFinder ?? (r => r.FindBranch(branchName).Tip);
158159

159160
var commit = referenceCommitFinder(fixture.Repository);
160-
var releaseDate = LastMinorVersionFinder.Execute(fixture.Repository, new Config(), commit);
161+
var releaseDate = LastMinorVersionFinder.Execute(fixture.Repository, new TestEffectiveConfiguration(), commit);
161162
releaseDate.ShouldBe(commit.When());
162163
}
163164

GitVersionCore.Tests/JsonVersionBuilderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void Json()
1717
PreReleaseTag = "unstable4",
1818
BuildMetaData = new SemanticVersionBuildMetaData(5, "feature1", "commitSha",DateTimeOffset.Parse("2014-03-06 23:59:59Z"))
1919
};
20-
var variables = VariableProvider.GetVariablesFor(semanticVersion, new Config());
20+
var variables = VariableProvider.GetVariablesFor(semanticVersion, AssemblyVersioningScheme.MajorMinorPatch, VersioningMode.ContinuousDelivery);
2121
var json = JsonOutputFormatter.ToJson(variables);
2222
Approvals.Verify(json);
2323
}

GitVersionTask.Tests/Mocks/MockBranch.cs renamed to GitVersionCore.Tests/Mocks/MockBranch.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public MockBranch(string name, string canonicalName)
1818

1919
public MockBranch()
2020
{
21-
21+
2222
}
2323
MockCommitLog commits = new MockCommitLog();
2424
string name;
@@ -66,7 +66,7 @@ public bool Remove(Commit item)
6666
return commits.Remove(item);
6767
}
6868

69-
public int Count{get{return commits.Count;}}
69+
public int Count { get { return commits.Count; } }
7070

71-
public bool IsReadOnly { get{return false;} }
71+
public bool IsReadOnly { get { return false; } }
7272
}

GitVersionTask.Tests/Mocks/MockBranchCollection.cs renamed to GitVersionCore.Tests/Mocks/MockBranchCollection.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public override IEnumerator<Branch> GetEnumerator()
1313

1414
public override Branch this[string name]
1515
{
16-
get { return Branches.FirstOrDefault(x=>x.Name ==name); }
16+
get { return Branches.FirstOrDefault(x => x.Name == name); }
1717
}
1818

1919
public void Add(Branch item)
@@ -40,16 +40,17 @@ public override void Remove(Branch item)
4040
{
4141
Branches.Remove(item);
4242
}
43-
bool ICollection<Branch>.Remove(Branch item)
43+
bool ICollection<Branch>.Remove(Branch item)
4444
{
4545
return Branches.Remove(item);
4646
}
4747

4848
public int Count
4949
{
50-
get {
50+
get
51+
{
5152
return Branches.Count;
5253
}
5354
}
54-
public bool IsReadOnly { get{return false;}}
55+
public bool IsReadOnly { get { return false; } }
5556
}

GitVersionTask.Tests/Mocks/MockCommit.cs renamed to GitVersionCore.Tests/Mocks/MockCommit.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
using LibGit2Sharp;
55

66
[DebuggerDisplay("{DebuggerDisplay}")]
7-
public class MockCommit:Commit
7+
public class MockCommit : Commit
88
{
99
public MockCommit(ObjectId id = null)
1010
{
11-
idEx = id ?? new ObjectId(Guid.NewGuid().ToString().Replace("-", "")+ "00000000");
11+
idEx = id ?? new ObjectId(Guid.NewGuid().ToString().Replace("-", "") + "00000000");
1212
MessageEx = "";
1313
ParentsEx = new List<Commit> { null };
1414
CommitterEx = new Signature("Joe", "[email protected]", DateTimeOffset.Now);
1515
}
1616

1717
public string MessageEx;
18-
public override string Message{get { return MessageEx; }}
18+
public override string Message { get { return MessageEx; } }
1919

2020
public Signature CommitterEx;
21-
public override Signature Committer{get { return CommitterEx; }}
21+
public override Signature Committer { get { return CommitterEx; } }
2222

2323
ObjectId idEx;
24-
public override ObjectId Id{get { return idEx; }}
24+
public override ObjectId Id { get { return idEx; } }
2525

2626
public override string Sha { get { return idEx.Sha; } }
2727

@@ -39,4 +39,4 @@ string DebuggerDisplay
3939
return MessageEx;
4040
}
4141
}
42-
}
42+
}

GitVersionTask.Tests/Mocks/MockCommitLog.cs renamed to GitVersionCore.Tests/Mocks/MockCommitLog.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using LibGit2Sharp;
44

5-
public class MockCommitLog:ICommitLog,ICollection<Commit>
5+
public class MockCommitLog : ICommitLog, ICollection<Commit>
66
{
77
public List<Commit> Commits = new List<Commit>();
88

@@ -26,7 +26,7 @@ public void Clear()
2626
{
2727
Commits.Clear();
2828
}
29-
29+
3030

3131
public bool Contains(Commit item)
3232
{
@@ -44,6 +44,8 @@ public bool Remove(Commit item)
4444
}
4545

4646
public int Count { get { return Commits.Count; } }
47-
public bool IsReadOnly {get { return false; }
47+
public bool IsReadOnly
48+
{
49+
get { return false; }
4850
}
4951
}

GitVersionTask.Tests/Mocks/MockMergeCommit.cs renamed to GitVersionCore.Tests/Mocks/MockMergeCommit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ public MockMergeCommit(ObjectId id = null) : base(id)
66
{
77
ParentsEx.Add(null);
88
}
9-
}
9+
}

GitVersionTask.Tests/Mocks/MockReferenceCollection.cs renamed to GitVersionCore.Tests/Mocks/MockReferenceCollection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ public class MockReferenceCollection : ReferenceCollection, ICollection<Commit>
88
public override ReflogCollection Log(string canonicalName)
99
{
1010
return new MockReflogCollection
11-
{
12-
Commits = Commits
13-
};
11+
{
12+
Commits = Commits
13+
};
1414
}
1515

1616
public List<Commit> Commits = new List<Commit>();

GitVersionTask.Tests/Mocks/MockRepository.cs renamed to GitVersionCore.Tests/Mocks/MockRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ public StashCollection Stashes
136136
{
137137
get { throw new NotImplementedException(); }
138138
}
139-
}
139+
}

GitVersionTask.Tests/Mocks/MockTag.cs renamed to GitVersionCore.Tests/Mocks/MockTag.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using LibGit2Sharp;
22

3-
public class MockTag:Tag
3+
public class MockTag : Tag
44
{
55

66
public string NameEx;

GitVersionTask.Tests/Mocks/MockTagAnnotation.cs renamed to GitVersionCore.Tests/Mocks/MockTagAnnotation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using LibGit2Sharp;
22

3-
public class MockTagAnnotation:TagAnnotation
3+
public class MockTagAnnotation : TagAnnotation
44
{
55

66
public Signature TaggerEx;

GitVersionTask.Tests/Mocks/MockTagCollection.cs renamed to GitVersionCore.Tests/Mocks/MockTagCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using LibGit2Sharp;
44

5-
public class MockTagCollection : TagCollection,ICollection<Tag>
5+
public class MockTagCollection : TagCollection, ICollection<Tag>
66
{
77

88
public List<Tag> Tags = new List<Tag>();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace GitVersionCore.Tests
2+
{
3+
using GitVersion;
4+
5+
public class TestEffectiveConfiguration : EffectiveConfiguration
6+
{
7+
public TestEffectiveConfiguration(
8+
AssemblyVersioningScheme assemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch,
9+
VersioningMode versioningMode = VersioningMode.ContinuousDelivery,
10+
string gitTagPrefix = "v",
11+
string tag = "",
12+
string nextVersion = null) :
13+
base(assemblyVersioningScheme, versioningMode, gitTagPrefix, tag, nextVersion)
14+
{
15+
}
16+
}
17+
}

GitVersionCore.Tests/VariableProviderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void DevelopBranchFormatsSemVerForCiFeed()
2222
semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");
2323

2424

25-
var vars = VariableProvider.GetVariablesFor(semVer, new Config());
25+
var vars = VariableProvider.GetVariablesFor(semVer, AssemblyVersioningScheme.MajorMinorPatch, VersioningMode.ContinuousDelivery);
2626

2727
vars[VariableProvider.SemVer].ShouldBe("1.2.3.5-unstable");
2828
}

GitVersionCore/BuildServers/BuildServerBase.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace GitVersion
22
{
33
using System;
4+
using System.Collections.Generic;
45

56
public abstract class BuildServerBase : IBuildServer
67
{
@@ -9,7 +10,7 @@ public abstract class BuildServerBase : IBuildServer
910
public abstract string GenerateSetVersionMessage(string versionToUseForBuildNumber);
1011
public abstract string[] GenerateSetParameterMessage(string name, string value);
1112

12-
public virtual void WriteIntegration(SemanticVersion semanticVersion, Action<string> writer)
13+
public virtual void WriteIntegration(SemanticVersion semanticVersion, Action<string> writer, Dictionary<string, string> variables)
1314
{
1415
if (semanticVersion == null)
1516
{
@@ -22,9 +23,10 @@ public virtual void WriteIntegration(SemanticVersion semanticVersion, Action<str
2223
}
2324

2425
writer(string.Format("Executing GenerateSetVersionMessage for '{0}'.", GetType().Name));
26+
// TODO This should come from variable provider
2527
writer(GenerateSetVersionMessage(semanticVersion.ToString("f")));
2628
writer(string.Format("Executing GenerateBuildLogOutput for '{0}'.", GetType().Name));
27-
foreach (var buildParameter in BuildOutputFormatter.GenerateBuildLogOutput(semanticVersion, this))
29+
foreach (var buildParameter in BuildOutputFormatter.GenerateBuildLogOutput(this, variables))
2830
{
2931
writer(buildParameter);
3032
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace GitVersion
22
{
33
using System;
4+
using System.Collections.Generic;
45

56
public interface IBuildServer
67
{
@@ -9,7 +10,7 @@ public interface IBuildServer
910
string GenerateSetVersionMessage(string versionToUseForBuildNumber);
1011
string[] GenerateSetParameterMessage(string name, string value);
1112

12-
void WriteIntegration(SemanticVersion semanticVersion, Action<string> writer);
13+
void WriteIntegration(SemanticVersion semanticVersion, Action<string> writer, Dictionary<string,string> variables);
1314
}
1415

1516
}

GitVersionCore/Configuration/BranchConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
public class BranchConfig
66
{
77
[YamlAlias("mode")]
8-
public VersioningMode VersioningMode { get; set; }
8+
public VersioningMode? VersioningMode { get; set; }
99

1010
[YamlAlias("tag")]
1111
public string Tag { get; set; }

0 commit comments

Comments
 (0)