Skip to content

Configuration Updates #341

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 0 additions & 16 deletions GitVersionCore.Tests/ConfigProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,6 @@ public void CanReadDocument()
config.Branches["develop"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
}

[Test]
public void CanInheritVersioningMode()
{
const string text = @"
mode: ContinuousDelivery
branches:
develop:
mode: ContinuousDeployment
";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
config.Branches["develop"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
config.Branches["develop"].Tag.ShouldBe("unstable");
config.Branches["release[/-]"].VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery);
}

[Test]
public void CanReadOldDocument()
{
Expand Down
54 changes: 54 additions & 0 deletions GitVersionCore.Tests/GitVersionContextTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace GitVersionCore.Tests
{
using GitVersion;
using NUnit.Framework;
using Shouldly;

public class GitVersionContextTests
{
[Test]
[Theory]
public void CanInheritVersioningMode(VersioningMode mode)
{
var config = new Config
{
VersioningMode = mode
};

var mockBranch = new MockBranch("master") { new MockCommit { CommitterEx = SignatureBuilder.SignatureNow() } };
var mockRepository = new MockRepository
{
Branches = new MockBranchCollection
{
mockBranch
}
};

var context = new GitVersionContext(mockRepository, mockBranch, config);
context.Configuration.VersioningMode.ShouldBe(mode);
}

[Test]
public void UsesBranchSpecificConfigOverTopLevelDefaults()
{
var config = new Config
{
VersioningMode = VersioningMode.ContinuousDelivery
};
config.Branches["develop"].VersioningMode = VersioningMode.ContinuousDeployment;
config.Branches["develop"].Tag = "alpha";
var develop = new MockBranch("develop") { new MockCommit { CommitterEx = SignatureBuilder.SignatureNow() } };
var mockRepository = new MockRepository
{
Branches = new MockBranchCollection
{
new MockBranch("master") { new MockCommit { CommitterEx = SignatureBuilder.SignatureNow() } },
develop
}
};
var context = new GitVersionContext(mockRepository, develop, config);
context.Configuration.VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
context.Configuration.Tag.ShouldBe("alpha");
}
}
}
14 changes: 14 additions & 0 deletions GitVersionCore.Tests/GitVersionCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<Compile Include="Fixtures\RemoteRepositoryFixture.cs" />
<Compile Include="GitDirFinderTests.cs" />
<Compile Include="Fixtures\BaseGitFlowRepositoryFixture.cs" />
<Compile Include="GitVersionContextTests.cs" />
<Compile Include="IntegrationTests\RemoteRepositoryTests.cs" />
<Compile Include="IntegrationTests\GitFlow\DevelopScenarios.cs" />
<Compile Include="IntegrationTests\GitFlow\FeatureBranchTests.cs" />
Expand All @@ -91,6 +92,18 @@
<Compile Include="InformationalVersionBuilderTests.cs" />
<Compile Include="IntegrationTests\GitHubFlow\SupportBranchScenarios.cs" />
<Compile Include="JsonVersionBuilderTests.cs" />
<Compile Include="Mocks\MockBranch.cs" />
<Compile Include="Mocks\MockBranchCollection.cs" />
<Compile Include="Mocks\MockCommit.cs" />
<Compile Include="Mocks\MockCommitLog.cs" />
<Compile Include="Mocks\MockMergeCommit.cs" />
<Compile Include="Mocks\MockReferenceCollection.cs" />
<Compile Include="Mocks\MockReflogCollection.cs" />
<Compile Include="Mocks\MockRepository.cs" />
<Compile Include="Mocks\MockTag.cs" />
<Compile Include="Mocks\MockTagAnnotation.cs" />
<Compile Include="Mocks\MockTagCollection.cs" />
<Compile Include="Mocks\SignatureBuilder.cs" />
<Compile Include="ModuleInitializer.cs" />
<Compile Include="Fixtures\EmptyRepositoryFixture.cs" />
<Compile Include="Helpers\GitTestExtensions.cs" />
Expand All @@ -99,6 +112,7 @@
<Compile Include="ApprovalTestsConfig.cs" />
<Compile Include="Fixtures\RepositoryFixtureBase.cs" />
<Compile Include="SemanticVersionTests.cs" />
<Compile Include="TestEffectiveConfiguration.cs" />
<Compile Include="TestFileSystem.cs" />
<Compile Include="VariableProviderTests.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using GitVersion;
using GitVersionCore.Tests;
using LibGit2Sharp;
using NUnit.Framework;
using Shouldly;
Expand Down Expand Up @@ -157,7 +158,7 @@ static void EnsureBranchMatch(CommitCountingRepoFixture fixture, string branchNa
var referenceCommitFinder = commitFinder ?? (r => r.FindBranch(branchName).Tip);

var commit = referenceCommitFinder(fixture.Repository);
var releaseDate = LastMinorVersionFinder.Execute(fixture.Repository, new Config(), commit);
var releaseDate = LastMinorVersionFinder.Execute(fixture.Repository, new TestEffectiveConfiguration(), commit);
releaseDate.ShouldBe(commit.When());
}

Expand Down
2 changes: 1 addition & 1 deletion GitVersionCore.Tests/JsonVersionBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void Json()
PreReleaseTag = "unstable4",
BuildMetaData = new SemanticVersionBuildMetaData(5, "feature1", "commitSha",DateTimeOffset.Parse("2014-03-06 23:59:59Z"))
};
var variables = VariableProvider.GetVariablesFor(semanticVersion, new Config());
var variables = VariableProvider.GetVariablesFor(semanticVersion, AssemblyVersioningScheme.MajorMinorPatch, VersioningMode.ContinuousDelivery);
var json = JsonOutputFormatter.ToJson(variables);
Approvals.Verify(json);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public MockBranch(string name, string canonicalName)

public MockBranch()
{

}
MockCommitLog commits = new MockCommitLog();
string name;
Expand Down Expand Up @@ -66,7 +66,7 @@ public bool Remove(Commit item)
return commits.Remove(item);
}

public int Count{get{return commits.Count;}}
public int Count { get { return commits.Count; } }

public bool IsReadOnly { get{return false;} }
public bool IsReadOnly { get { return false; } }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override IEnumerator<Branch> GetEnumerator()

public override Branch this[string name]
{
get { return Branches.FirstOrDefault(x=>x.Name ==name); }
get { return Branches.FirstOrDefault(x => x.Name == name); }
}

public void Add(Branch item)
Expand All @@ -40,16 +40,17 @@ public override void Remove(Branch item)
{
Branches.Remove(item);
}
bool ICollection<Branch>.Remove(Branch item)
bool ICollection<Branch>.Remove(Branch item)
{
return Branches.Remove(item);
}

public int Count
{
get {
get
{
return Branches.Count;
}
}
public bool IsReadOnly { get{return false;}}
public bool IsReadOnly { get { return false; } }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
using LibGit2Sharp;

[DebuggerDisplay("{DebuggerDisplay}")]
public class MockCommit:Commit
public class MockCommit : Commit
{
public MockCommit(ObjectId id = null)
{
idEx = id ?? new ObjectId(Guid.NewGuid().ToString().Replace("-", "")+ "00000000");
idEx = id ?? new ObjectId(Guid.NewGuid().ToString().Replace("-", "") + "00000000");
MessageEx = "";
ParentsEx = new List<Commit> { null };
CommitterEx = new Signature("Joe", "[email protected]", DateTimeOffset.Now);
}

public string MessageEx;
public override string Message{get { return MessageEx; }}
public override string Message { get { return MessageEx; } }

public Signature CommitterEx;
public override Signature Committer{get { return CommitterEx; }}
public override Signature Committer { get { return CommitterEx; } }

ObjectId idEx;
public override ObjectId Id{get { return idEx; }}
public override ObjectId Id { get { return idEx; } }

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

Expand All @@ -39,4 +39,4 @@ string DebuggerDisplay
return MessageEx;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using LibGit2Sharp;

public class MockCommitLog:ICommitLog,ICollection<Commit>
public class MockCommitLog : ICommitLog, ICollection<Commit>
{
public List<Commit> Commits = new List<Commit>();

Expand All @@ -26,7 +26,7 @@ public void Clear()
{
Commits.Clear();
}


public bool Contains(Commit item)
{
Expand All @@ -44,6 +44,8 @@ public bool Remove(Commit item)
}

public int Count { get { return Commits.Count; } }
public bool IsReadOnly {get { return false; }
public bool IsReadOnly
{
get { return false; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public MockMergeCommit(ObjectId id = null) : base(id)
{
ParentsEx.Add(null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public class MockReferenceCollection : ReferenceCollection, ICollection<Commit>
public override ReflogCollection Log(string canonicalName)
{
return new MockReflogCollection
{
Commits = Commits
};
{
Commits = Commits
};
}

public List<Commit> Commits = new List<Commit>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ public StashCollection Stashes
{
get { throw new NotImplementedException(); }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LibGit2Sharp;

public class MockTag:Tag
public class MockTag : Tag
{

public string NameEx;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LibGit2Sharp;

public class MockTagAnnotation:TagAnnotation
public class MockTagAnnotation : TagAnnotation
{

public Signature TaggerEx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using LibGit2Sharp;

public class MockTagCollection : TagCollection,ICollection<Tag>
public class MockTagCollection : TagCollection, ICollection<Tag>
{

public List<Tag> Tags = new List<Tag>();
Expand Down
17 changes: 17 additions & 0 deletions GitVersionCore.Tests/TestEffectiveConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace GitVersionCore.Tests
{
using GitVersion;

public class TestEffectiveConfiguration : EffectiveConfiguration
{
public TestEffectiveConfiguration(
AssemblyVersioningScheme assemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch,
VersioningMode versioningMode = VersioningMode.ContinuousDelivery,
string gitTagPrefix = "v",
string tag = "",
string nextVersion = null) :
base(assemblyVersioningScheme, versioningMode, gitTagPrefix, tag, nextVersion)
{
}
}
}
2 changes: 1 addition & 1 deletion GitVersionCore.Tests/VariableProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void DevelopBranchFormatsSemVerForCiFeed()
semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");


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

vars[VariableProvider.SemVer].ShouldBe("1.2.3.5-unstable");
}
Expand Down
6 changes: 4 additions & 2 deletions GitVersionCore/BuildServers/BuildServerBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace GitVersion
{
using System;
using System.Collections.Generic;

public abstract class BuildServerBase : IBuildServer
{
Expand All @@ -9,7 +10,7 @@ public abstract class BuildServerBase : IBuildServer
public abstract string GenerateSetVersionMessage(string versionToUseForBuildNumber);
public abstract string[] GenerateSetParameterMessage(string name, string value);

public virtual void WriteIntegration(SemanticVersion semanticVersion, Action<string> writer)
public virtual void WriteIntegration(SemanticVersion semanticVersion, Action<string> writer, Dictionary<string, string> variables)
{
if (semanticVersion == null)
{
Expand All @@ -22,9 +23,10 @@ public virtual void WriteIntegration(SemanticVersion semanticVersion, Action<str
}

writer(string.Format("Executing GenerateSetVersionMessage for '{0}'.", GetType().Name));
// TODO This should come from variable provider
writer(GenerateSetVersionMessage(semanticVersion.ToString("f")));
writer(string.Format("Executing GenerateBuildLogOutput for '{0}'.", GetType().Name));
foreach (var buildParameter in BuildOutputFormatter.GenerateBuildLogOutput(semanticVersion, this))
foreach (var buildParameter in BuildOutputFormatter.GenerateBuildLogOutput(this, variables))
{
writer(buildParameter);
}
Expand Down
3 changes: 2 additions & 1 deletion GitVersionCore/BuildServers/IBuildServer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace GitVersion
{
using System;
using System.Collections.Generic;

public interface IBuildServer
{
Expand All @@ -9,7 +10,7 @@ public interface IBuildServer
string GenerateSetVersionMessage(string versionToUseForBuildNumber);
string[] GenerateSetParameterMessage(string name, string value);

void WriteIntegration(SemanticVersion semanticVersion, Action<string> writer);
void WriteIntegration(SemanticVersion semanticVersion, Action<string> writer, Dictionary<string,string> variables);
}

}
2 changes: 1 addition & 1 deletion GitVersionCore/Configuration/BranchConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class BranchConfig
{
[YamlAlias("mode")]
public VersioningMode VersioningMode { get; set; }
public VersioningMode? VersioningMode { get; set; }

[YamlAlias("tag")]
public string Tag { get; set; }
Expand Down
Loading