Skip to content

[WIP] Branch specific configuration #338

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 78 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
62c532d
Added support for branch specific config
Dec 9, 2014
36c87a8
Implemented different versioning modes
Dec 10, 2014
ab38fd3
code cleanup
Dec 10, 2014
2c47502
changed branches
Dec 10, 2014
c2330e4
enhanced branches config
Dec 10, 2014
ded3425
Merge remote-tracking branch 'upstream/master' into BranchSpecificCon…
JakeGinnivan Jan 7, 2015
5da70ee
Fixed merge issue
JakeGinnivan Jan 7, 2015
ff3cbea
Merge remote-tracking branch 'upstream/master' into BranchSpecificCon…
JakeGinnivan Jan 8, 2015
67be1f6
Current branch configuration should be set by the context
JakeGinnivan Jan 7, 2015
3ecf6fa
Should match branch name only at start of line
JakeGinnivan Jan 7, 2015
3ad8b33
Fixed failing tests
JakeGinnivan Jan 8, 2015
3705f6f
Fixing tests which were affected by a git race condition. See https:/…
JakeGinnivan Jan 8, 2015
e7a5548
Found a workaround which is fixed now
JakeGinnivan Jan 8, 2015
e885ce7
Fixed issue found in review
JakeGinnivan Jan 8, 2015
9fd17dd
Merge pull request #339 from JakeGinnivan/ContextAssignsBranchConfigu…
JakeGinnivan Jan 8, 2015
a65a115
Throw error when user is using legacy configuration values
JakeGinnivan Jan 9, 2015
6f6305c
Merge pull request #342 from JakeGinnivan/legacyConfig
JakeGinnivan Jan 9, 2015
1d8a7f9
Initial refactoring around configuration, introducing EffectiveConfig…
JakeGinnivan Jan 8, 2015
74cd78f
Fixed failing tests
JakeGinnivan Jan 9, 2015
7a35a71
Created some tests around EffectiveConfig
JakeGinnivan Jan 9, 2015
b9b2a2b
Inspection error fix
JakeGinnivan Jan 9, 2015
5d86d09
Merge pull request #341 from JakeGinnivan/VariableProviderModes
JakeGinnivan Jan 9, 2015
3545141
Introduced VersionVariables rather than passing a Dictionary around
JakeGinnivan Jan 10, 2015
3d90664
Mode now changes the variables created and used by GitVersion
JakeGinnivan Jan 10, 2015
dc6f8b4
Changed the Continuous Deployment output to be more sensible
JakeGinnivan Jan 10, 2015
33c891a
Fixed a small issue with build metadata
JakeGinnivan Jan 10, 2015
95e744e
Merge pull request #343 from JakeGinnivan/VariableProviderUpdates
JakeGinnivan Jan 12, 2015
ea0e316
Deprecated NextVersion.txt
JakeGinnivan Jan 11, 2015
7b59651
Merge pull request #345 from JakeGinnivan/NoMoreNextVersionTxt
JakeGinnivan Jan 13, 2015
f85cd83
Starting on base version calculators
JakeGinnivan Jan 10, 2015
62b6f42
Added merge message base version strategy
JakeGinnivan Jan 10, 2015
b25220a
Adding LastTagBaseVersionStrategy
JakeGinnivan Jan 10, 2015
8ee25e8
Created NewNextVersionCalculator which is the new version calculation
JakeGinnivan Jan 10, 2015
a74bbf5
Added MetaDataCalculator in and fixed up some other shortcomings in t…
JakeGinnivan Jan 10, 2015
aa54a21
Uncomment line in GitVersionFinder to test new way of doing things. I…
JakeGinnivan Jan 10, 2015
7a0267f
Should not increment version when current commit is tagged
JakeGinnivan Jan 11, 2015
83d3862
Added missing base version finder
JakeGinnivan Jan 11, 2015
a952bb1
Allow inheriting of the parent branches increment strategy. Allows fe…
JakeGinnivan Jan 11, 2015
690399e
When branch configuration has 'Tag' set to 'useBranchName' it will us…
JakeGinnivan Jan 11, 2015
810d309
Fixed a few tests and the way inheriting increment strategy works
JakeGinnivan Jan 11, 2015
3e0be76
Base versions can specify whether the tag should be updated
JakeGinnivan Jan 11, 2015
2dbcc84
Fixing incorrect tests, when develop is branched from master it is st…
JakeGinnivan Jan 11, 2015
204d2bc
Fixed some exceptions which were causing tests to blow up and not get…
JakeGinnivan Jan 11, 2015
e999a62
Think the code is mostly there. It is now mainly fixing commit counti…
JakeGinnivan Jan 11, 2015
900ccf6
Fixed failing tests
JakeGinnivan Jan 12, 2015
8ab088f
Fixed build issue
JakeGinnivan Jan 14, 2015
b7c090d
Removed branch comparer
JakeGinnivan Jan 16, 2015
f7e30c4
Turned on new code
JakeGinnivan Jan 16, 2015
b924119
Merge pull request #346 from JakeGinnivan/ConfigBasedVersioningImprov…
JakeGinnivan Jan 16, 2015
14487a0
Merge remote-tracking branch 'upstream/master' into BranchSpecificCon…
JakeGinnivan Jan 18, 2015
5605c49
Fix typo
JakeGinnivan Jan 18, 2015
76dc8c1
Fixed obsolete compiler warnings for YamlAlias attribute
JakeGinnivan Jan 18, 2015
03e9df5
Replacing obsolete usage of repo.Index.Stage with repo.Stage
JakeGinnivan Jan 18, 2015
91a71f8
Fixing compiler errors with conflicting types due to namespace removal
JakeGinnivan Jan 18, 2015
e9382e1
Fixed develop tests
JakeGinnivan Jan 18, 2015
85f76fc
Merge pull request #354 from JakeGinnivan/TypoFix
gep13 Jan 18, 2015
86e5b1a
Fix feature branch related tests
JakeGinnivan Jan 18, 2015
917ef91
Fixing a lot of commit counting in tests
JakeGinnivan Jan 18, 2015
e0bf106
Adding better logging around the new version calculation
JakeGinnivan Jan 18, 2015
07085ab
Added failing PR test
JakeGinnivan Jan 19, 2015
be87141
Fixed config inheritance for pull requests
JakeGinnivan Jan 24, 2015
a611c65
Fixed PR's from a fork
JakeGinnivan Jan 24, 2015
2c2019f
Filter remote branches to fix PRs
JakeGinnivan Jan 25, 2015
349dce8
Merge pull request #353 from JakeGinnivan/BuildWarningFixes
JakeGinnivan Feb 11, 2015
7af3377
Merge pull request #355 from JakeGinnivan/FixingTests
JakeGinnivan Feb 11, 2015
0eea2aa
Removed x86 solution build config
JakeGinnivan Feb 11, 2015
959f90b
Moved BuildServers tests to Core test project
JakeGinnivan Feb 11, 2015
f78871e
Removed a whole bunch of unused code
JakeGinnivan Feb 11, 2015
a31b530
Inlined a class which is only used in one place now
JakeGinnivan Feb 11, 2015
d5a2545
Removed LastMinorVersionFinder and OriginalDate from the assembly inf…
JakeGinnivan Feb 11, 2015
2f7a666
Removed VersionOnMasterFinder which is no longer used
JakeGinnivan Feb 11, 2015
66592d4
Inlined RecentTagVersionExtractor into only class using it
JakeGinnivan Feb 11, 2015
fee6a2e
Removed more unneeded code
JakeGinnivan Feb 11, 2015
b7b189a
Fixed a few more tests and collapsed the GitFlow/GitHubFlow test fold…
JakeGinnivan Feb 11, 2015
65d0c0c
Fixed a bunch more tests
JakeGinnivan Feb 11, 2015
b4ec263
Added some logging
JakeGinnivan Feb 11, 2015
184c862
Merge pull request #362 from JakeGinnivan/Cleanup
JakeGinnivan Feb 11, 2015
7a57e59
Merge pull request #363 from JakeGinnivan/MoreTestFixes
JakeGinnivan Feb 13, 2015
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
5 changes: 5 additions & 0 deletions BREAKING CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
v3.0.0
- `AssemblyFileSemVer` variable removed, AssemblyVersioningScheme configuration value makes this variable obsolete
- `ClassicVersion` variable removed,
- `ClassicVersionWithTag` variable removed, as above
- MSBuild task arguments (AssemblyVersioningScheme, DevelopBranchTag, ReleaseBranchTag, TagPrefix, NextVersion) have been removed, use GitVersionConfig.yaml instead
20 changes: 4 additions & 16 deletions GitVersion.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
# Visual Studio 14
VisualStudioVersion = 14.0.22512.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersionExe", "GitVersionExe\GitVersionExe.csproj", "{C3578A7B-09A6-4444-9383-0DEAFA4958BD}"
EndProject
Expand All @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersionCore.Tests", "Git
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3EFFC5D6-88D0-49D9-BB53-E1B7EB49DD45}"
ProjectSection(SolutionItems) = preProject
BREAKING CHANGES.md = BREAKING CHANGES.md
GitVersionConfig.yaml = GitVersionConfig.yaml
LICENSE = LICENSE
README.md = README.md
EndProjectSection
Expand All @@ -24,47 +26,33 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C3578A7B-09A6-4444-9383-0DEAFA4958BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C3578A7B-09A6-4444-9383-0DEAFA4958BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3578A7B-09A6-4444-9383-0DEAFA4958BD}.Debug|x86.ActiveCfg = Debug|Any CPU
{C3578A7B-09A6-4444-9383-0DEAFA4958BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3578A7B-09A6-4444-9383-0DEAFA4958BD}.Release|Any CPU.Build.0 = Release|Any CPU
{C3578A7B-09A6-4444-9383-0DEAFA4958BD}.Release|x86.ActiveCfg = Release|Any CPU
{5A86453B-96FB-4B6E-A283-225BB9F753D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5A86453B-96FB-4B6E-A283-225BB9F753D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A86453B-96FB-4B6E-A283-225BB9F753D3}.Debug|x86.ActiveCfg = Debug|Any CPU
{5A86453B-96FB-4B6E-A283-225BB9F753D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A86453B-96FB-4B6E-A283-225BB9F753D3}.Release|Any CPU.Build.0 = Release|Any CPU
{5A86453B-96FB-4B6E-A283-225BB9F753D3}.Release|x86.ActiveCfg = Release|Any CPU
{F7AC0E71-3E9A-4F6D-B986-E004825A48E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7AC0E71-3E9A-4F6D-B986-E004825A48E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7AC0E71-3E9A-4F6D-B986-E004825A48E1}.Debug|x86.ActiveCfg = Debug|Any CPU
{F7AC0E71-3E9A-4F6D-B986-E004825A48E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7AC0E71-3E9A-4F6D-B986-E004825A48E1}.Release|Any CPU.Build.0 = Release|Any CPU
{F7AC0E71-3E9A-4F6D-B986-E004825A48E1}.Release|x86.ActiveCfg = Release|Any CPU
{BF905F84-382C-440D-92F5-C61108626D8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BF905F84-382C-440D-92F5-C61108626D8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF905F84-382C-440D-92F5-C61108626D8D}.Debug|x86.ActiveCfg = Debug|Any CPU
{BF905F84-382C-440D-92F5-C61108626D8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF905F84-382C-440D-92F5-C61108626D8D}.Release|Any CPU.Build.0 = Release|Any CPU
{BF905F84-382C-440D-92F5-C61108626D8D}.Release|x86.ActiveCfg = Release|Any CPU
{F9741A0D-B9D7-4557-9A1C-A7252C1071F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F9741A0D-B9D7-4557-9A1C-A7252C1071F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F9741A0D-B9D7-4557-9A1C-A7252C1071F5}.Debug|x86.ActiveCfg = Debug|Any CPU
{F9741A0D-B9D7-4557-9A1C-A7252C1071F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F9741A0D-B9D7-4557-9A1C-A7252C1071F5}.Release|Any CPU.Build.0 = Release|Any CPU
{F9741A0D-B9D7-4557-9A1C-A7252C1071F5}.Release|x86.ActiveCfg = Release|Any CPU
{75C2BE85-1DAF-4E34-8305-B17AFAA982A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75C2BE85-1DAF-4E34-8305-B17AFAA982A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75C2BE85-1DAF-4E34-8305-B17AFAA982A6}.Debug|x86.ActiveCfg = Debug|Any CPU
{75C2BE85-1DAF-4E34-8305-B17AFAA982A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75C2BE85-1DAF-4E34-8305-B17AFAA982A6}.Release|Any CPU.Build.0 = Release|Any CPU
{75C2BE85-1DAF-4E34-8305-B17AFAA982A6}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 2 additions & 0 deletions GitVersion.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleMistakenCallToGetType_002E2/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleNullReferenceException/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PrivateFieldCanBeConvertedToLocalVariable/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantArgumentName/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantArgumentNameForLiteralExpression/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantAssignment/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantBaseConstructorCall/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantBoolCompare/@EntryIndexedValue">ERROR</s:String>
Expand Down
4 changes: 2 additions & 2 deletions GitVersionConfig.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
assembly-versioning-scheme: MajorMinor
next-version: 2.0.0
assembly-versioning-scheme: MajorMinorPatch
next-version: 3.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public void BuildNumberIsFullSemVer()

semanticVersion.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");
semanticVersion.BuildMetaData.Sha = "commitSha";
new BuildServer().WriteIntegration(semanticVersion, writes.Add);
var variables = VariableProvider.GetVariablesFor(semanticVersion, AssemblyVersioningScheme.MajorMinorPatch, VersioningMode.ContinuousDelivery);
new BuildServer().WriteIntegration(writes.Add, variables);

writes[1].ShouldBe("1.2.3-beta.1+5");
}
Expand Down
44 changes: 33 additions & 11 deletions GitVersionCore.Tests/ConfigProviderTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -25,28 +26,44 @@ public void CanReadDocument()
{
const string text = @"
assembly-versioning-scheme: MajorMinor
develop-branch-tag: alpha
release-branch-tag: rc
next-version: 2.0.0
tag-prefix: '[vV|version-]'
mode: ContinuousDelivery
branches:
develop:
mode: ContinuousDeployment
tag: dev
release[/-]:
mode: ContinuousDeployment
tag: rc
";
SetupConfigFileContent(text);

var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
config.DevelopBranchTag.ShouldBe("alpha");
config.ReleaseBranchTag.ShouldBe("rc");
config.NextVersion.ShouldBe("2.0.0");
config.TagPrefix.ShouldBe("[vV|version-]");
config.VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery);
config.Branches["develop"].Tag.ShouldBe("dev");
config.Branches["release[/-]"].Tag.ShouldBe("rc");
config.Branches["release[/-]"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
config.Branches["develop"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
}

[Test]
public void CanReadOldDocument()
{
const string text = @"assemblyVersioningScheme: MajorMinor";
const string text = @"
assemblyVersioningScheme: MajorMinor
develop-branch-tag: alpha
release-branch-tag: rc
";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
var error = Should.Throw<OldConfigurationException>(() => ConfigurationProvider.Provide(gitDirectory, fileSystem));
error.Message.ShouldContainWithoutWhitespace(@"GitVersionConfig.yaml contains old configuration, please fix the following errors:
assemblyVersioningScheme has been replaced by assembly-versioning-scheme
develop-branch-tag has been replaced by branch specific configuration.See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration
release-branch-tag has been replaced by branch specific configuration.See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration");
}

[Test]
Expand All @@ -56,8 +73,8 @@ public void CanReadDefaultDocument()
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
config.DevelopBranchTag.ShouldBe("unstable");
config.ReleaseBranchTag.ShouldBe("beta");
config.Branches["develop"].Tag.ShouldBe("unstable");
config.Branches["release[/-]"].Tag.ShouldBe("beta");
config.TagPrefix.ShouldBe("[vV]");
config.NextVersion.ShouldBe(null);
}
Expand All @@ -66,7 +83,9 @@ public void CanReadDefaultDocument()
public void VerifyInit()
{
var config = typeof(Config);
var aliases = config.GetProperties().Select(p => ((YamlAliasAttribute) p.GetCustomAttribute(typeof(YamlAliasAttribute))).Alias);
var aliases = config.GetProperties()
.Where(p => p.GetCustomAttribute<ObsoleteAttribute>() == null)
.Select(p => ((YamlMemberAttribute) p.GetCustomAttribute(typeof(YamlMemberAttribute))).Alias);
var writer = new StringWriter();

ConfigReader.WriteSample(writer);
Expand All @@ -82,7 +101,10 @@ public void VerifyInit()
public void VerifyAliases()
{
var config = typeof(Config);
var propertiesMissingAlias = config.GetProperties().Where(p => p.GetCustomAttribute(typeof(YamlAliasAttribute)) == null).Select(p => p.Name);
var propertiesMissingAlias = config.GetProperties()
.Where(p => p.GetCustomAttribute<ObsoleteAttribute>() == null)
.Where(p => p.GetCustomAttribute(typeof(YamlMemberAttribute)) == null)
.Select(p => p.Name);

propertiesMissingAlias.ShouldBeEmpty();
}
Expand Down
16 changes: 15 additions & 1 deletion GitVersionCore.Tests/Fixtures/BaseGitFlowRepositoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@
using GitVersion;
using LibGit2Sharp;

/// <summary>
/// Creates a repo with a develop branch off master which is a single commit ahead of master
/// </summary>
public class BaseGitFlowRepositoryFixture : EmptyRepositoryFixture
{
/// <summary>
/// Creates a repo with a develop branch off master which is a single commit ahead of master
///
/// Master will be tagged with the initial version before branching develop
/// </summary>
public BaseGitFlowRepositoryFixture(string initialVersion) : base(new Config())
{
SetupRepo(r => r.MakeATaggedCommit(initialVersion));
}

/// <summary>
/// Creates a repo with a develop branch off master which is a single commit ahead of master
///
/// The initial setup actions will be performed before branching develop
/// </summary>
public BaseGitFlowRepositoryFixture(Action<IRepository> initialMasterAction) : base(new Config())
{
SetupRepo(initialMasterAction);
Expand All @@ -19,10 +32,11 @@ void SetupRepo(Action<IRepository> initialMasterAction)
{
var randomFile = Path.Combine(Repository.Info.WorkingDirectory, Guid.NewGuid().ToString());
File.WriteAllText(randomFile, string.Empty);
Repository.Index.Stage(randomFile);
Repository.Stage(randomFile);

initialMasterAction(Repository);

Repository.CreateBranch("develop").Checkout();
Repository.MakeACommit();
}
}
21 changes: 19 additions & 2 deletions GitVersionCore.Tests/Fixtures/EmptyRepositoryFixture.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Diagnostics;
using System.Text;
using GitVersion;
using GitVersion.Helpers;
using LibGit2Sharp;

public class EmptyRepositoryFixture : RepositoryFixtureBase
Expand All @@ -9,10 +11,25 @@ public EmptyRepositoryFixture(Config configuration) :
{
}

public void DumpGraph()
{
var output = new StringBuilder();

ProcessHelper.Run(
o => output.AppendLine(o),
e => output.AppendLineFormat("ERROR: {0}", e),
null,
"git",
@"log --graph --abbrev-commit --decorate --date=relative --all",
RepositoryPath);

Trace.Write(output.ToString());
}

static IRepository CreateNewRepository(string path)
{
LibGit2Sharp.Repository.Init(path);
Console.WriteLine("Created git repository at '{0}'", path);
Trace.WriteLine("Created git repository at '{0}'", path);

return new Repository(path);
}
Expand Down
80 changes: 80 additions & 0 deletions GitVersionCore.Tests/GitVersionContextBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
namespace GitVersionCore.Tests
{
using GitVersion;
using LibGit2Sharp;

public class GitVersionContextBuilder
{
IRepository repository;
Config config;

public GitVersionContextBuilder WithRepository(IRepository repository)
{
this.repository = repository;
return this;
}

public GitVersionContextBuilder WithConfig(Config config)
{
this.config = config;
return this;
}

public GitVersionContextBuilder WithTaggedMaster()
{
repository = CreateRepository();
var target = repository.Head.Tip;
((MockTagCollection)repository.Tags).Add(new MockTag ("1.0.0", target));
return this;
}

public GitVersionContextBuilder AddCommit()
{
((MockBranch)repository.Head).Add(new MockCommit());
return this;
}

public GitVersionContextBuilder WithDevelopBranch()
{
return WithBranch("develop");
}

public GitVersionContextBuilder WithBranch(string branchName)
{
repository = CreateRepository();
return AddBranch(branchName);
}

public GitVersionContextBuilder AddBranch(string branchName)
{
var mockBranch = new MockBranch(branchName)
{
new MockCommit()
};
((MockBranchCollection)repository.Branches).Add(mockBranch);
((MockRepository)repository).Head = mockBranch;
return this;
}

public GitVersionContext Build()
{
return new GitVersionContext(repository ?? CreateRepository(), config ?? new Config());
}

IRepository CreateRepository()
{
var mockBranch = new MockBranch("master") { new MockCommit { CommitterEx = SignatureBuilder.SignatureNow() } };
var mockRepository = new MockRepository
{
Branches = new MockBranchCollection
{
mockBranch
},
Tags = new MockTagCollection(),
Head = mockBranch
};

return mockRepository;
}
}
}
Loading