Skip to content

Review and comment fixes #371

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
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
14 changes: 14 additions & 0 deletions GitVersionCore.Tests/ConfigProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ public void OverwritesDefaultsWithProvidedConfig()
config.Branches["develop"].Tag.ShouldBe("dev");
}

[Test]
public void CanProvideConfigForNewBranch()
{
const string text = @"
next-version: 2.0.0
branches:
bug[/-]:
tag: bugfix";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);

config.Branches["bug[/-]"].Tag.ShouldBe("bugfix");
}

[Test]
[MethodImpl(MethodImplOptions.NoInlining)]
public void CanWriteOutEffectiveConfiguration()
Expand Down
1 change: 1 addition & 0 deletions GitVersionCore.Tests/GitVersionCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<Compile Include="IntegrationTests\HotfixBranchScenarios.cs" />
<Compile Include="IntegrationTests\ReleaseBranchScenarios.cs" />
<Compile Include="IntegrationTests\SwitchingToGitFlowScenarios.cs" />
<Compile Include="IntegrationTests\VersionBumpingScenarios.cs" />
<Compile Include="IntegrationTests\UncycloScenarios.cs" />
<Compile Include="IntegrationTests\OtherBranchScenarios.cs" />
<Compile Include="Helpers\Constants.cs" />
Expand Down
22 changes: 4 additions & 18 deletions GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,7 @@ public void CanChangeDevelopTagViaConfig()
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("develop").Checkout();
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.1.0-alpha.1+1");
}
}

[Test]
public void CanClearDevelopTagViaConfig()
{
var config = new Config();
config.Branches["develop"].Tag = "";
using (var fixture = new EmptyRepositoryFixture(config))
{
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("develop").Checkout();
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.1.0+1");
fixture.AssertFullSemver("1.1.0-alpha.1");
}
}

Expand All @@ -52,7 +38,7 @@ public void WhenDevelopBranchedFromMaster_MinorIsIncreased()
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("develop").Checkout();
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.1.0-unstable.1+1");
fixture.AssertFullSemver("1.1.0-unstable.1");
}
}

Expand All @@ -71,7 +57,7 @@ public void MergingReleaseBranchBackIntoDevelopWithMergingToMaster_DoesBumpDevel

fixture.Repository.Checkout("develop");
fixture.Repository.MergeNoFF("release-2.0.0", Constants.SignatureNow());
fixture.AssertFullSemver("2.1.0-unstable.1+0");
fixture.AssertFullSemver("2.1.0-unstable.0");
}
}

Expand Down Expand Up @@ -100,7 +86,7 @@ public void WhenDevelopBranchedFromMasterDetachedHead_MinorIsIncreased()
var commit = fixture.Repository.Head.Tip;
fixture.Repository.MakeACommit();
fixture.Repository.Checkout(commit);
fixture.AssertFullSemver("1.1.0-unstable.1+1");
fixture.AssertFullSemver("1.1.0-unstable.1");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public void PatchLatestReleaseExample()

// Verify develop version
fixture.Repository.Checkout("develop");
fixture.AssertFullSemver("1.3.0-unstable.1+1");
fixture.AssertFullSemver("1.3.0-unstable.1");

fixture.Repository.MergeNoFF("hotfix-1.2.1", Constants.SignatureNow());
fixture.AssertFullSemver("1.3.0-unstable.1+0");
fixture.AssertFullSemver("1.3.0-unstable.0");
}
}

Expand Down Expand Up @@ -84,9 +84,9 @@ public void PatchOlderReleaseExample()

// Verify develop version
fixture.Repository.Checkout("develop");
fixture.AssertFullSemver("2.1.0-unstable.1+1");
fixture.AssertFullSemver("2.1.0-unstable.1");
fixture.Repository.MergeNoFF("support-1.1", Constants.SignatureNow());
fixture.AssertFullSemver("2.1.0-unstable.1+7");
fixture.AssertFullSemver("2.1.0-unstable.7");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void WhenReleaseBranchIsMergedIntoDevelopHighestVersionIsTakenWithIt()
fixture.Repository.Checkout("develop");
fixture.Repository.MergeNoFF("release-1.0.0", Constants.SignatureNow());

fixture.AssertFullSemver("2.1.0-unstable.1+5");
fixture.AssertFullSemver("2.1.0-unstable.5");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void WhenDevelopBranchedFromMasterWithLegacyVersionTags_DevelopCanUseReac
fixture.Repository.MakeATaggedCommit("1.0.0.0");
fixture.Repository.MakeCommits(2);
fixture.Repository.CreateBranch("develop").Checkout();
fixture.AssertFullSemver("1.1.0-unstable.1+2");
fixture.AssertFullSemver("1.1.0-unstable.2");
}
}
}
21 changes: 21 additions & 0 deletions GitVersionCore.Tests/IntegrationTests/VersionBumpingScenarios.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using GitVersion;
using NUnit.Framework;

[TestFixture]
public class VersionBumpingScenarios
{
[Test]
public void AppliedPrereleaseTagCausesBump()
{
var configuration = new Config();
configuration.Branches["master"].Tag = "pre";
using (var fixture = new EmptyRepositoryFixture(configuration))
{
fixture.Repository.MakeACommit();
fixture.Repository.MakeATaggedCommit("1.0.0-pre.1");
fixture.Repository.MakeACommit();

fixture.AssertFullSemver("1.0.0-pre.2+1");
}
}
}
8 changes: 4 additions & 4 deletions GitVersionCore.Tests/IntegrationTests/UncycloScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void MinorReleaseExample()
// Branch to develop
fixture.Repository.CreateBranch("develop").Checkout();
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.3.0-unstable.1+1");
fixture.AssertFullSemver("1.3.0-unstable.1");

// Open Pull Request
fixture.Repository.CreateBranch("pull/2/merge").Checkout();
Expand All @@ -56,7 +56,7 @@ public void MinorReleaseExample()
// Merge into develop
fixture.Repository.Checkout("develop");
fixture.Repository.MergeNoFF("pull/2/merge", Constants.SignatureNow());
fixture.AssertFullSemver("1.3.0-unstable.1+3");
fixture.AssertFullSemver("1.3.0-unstable.3");

// Create release branch
fixture.Repository.CreateBranch("release-1.3.0").Checkout();
Expand All @@ -65,7 +65,7 @@ public void MinorReleaseExample()
// Make another commit on develop
fixture.Repository.Checkout("develop");
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.3.0-unstable.1+4");
fixture.AssertFullSemver("1.3.0-unstable.4");

// Make a commit to release-1.3.0
fixture.Repository.Checkout("release-1.3.0");
Expand All @@ -89,7 +89,7 @@ public void MinorReleaseExample()
// Verify develop version
fixture.Repository.Checkout("develop");
fixture.Repository.MergeNoFF("release-1.3.0", Constants.SignatureNow());
fixture.AssertFullSemver("1.4.0-unstable.1+0");
fixture.AssertFullSemver("1.4.0-unstable.0");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"LegacySemVer":"1.2.3-unstable5",
"LegacySemVerPadded":"1.2.3-unstable0005",
"AssemblySemVer":"1.2.3.0",
"FullSemVer":"1.2.3-unstable.5+4",
"InformationalVersion":"1.2.3-unstable.5+4.Branch.develop.Sha.commitSha",
"FullSemVer":"1.2.3-unstable.5",
"InformationalVersion":"1.2.3-unstable.5+Branch.develop.Sha.commitSha",
"BranchName":"develop",
"Sha":"commitSha",
"NuGetVersionV2":"1.2.3-unstable0005",
Expand Down
20 changes: 4 additions & 16 deletions GitVersionCore/BranchConfigurationCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(
BranchConfig branchConfiguration, Config config)
{
Logger.WriteInfo("Attempting to inherit branch configuration from parent branch");
var excludedBranches = new Branch[0];
var excludedBranches = new [] { currentBranch };
// Check if we are a merge commit. If so likely we are a pull request
var parentCount = currentCommit.Parents.Count();
if (parentCount == 2)
Expand Down Expand Up @@ -68,15 +68,12 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(
List<Branch> possibleParents;
if (branchPoint.Sha == currentCommit.Sha)
{
possibleParents = ListBranchesContaininingCommit(repository, currentCommit.Sha, excludedBranches).Except(new[]
{
currentBranch
}).ToList();
possibleParents = currentCommit.GetBranchesContainingCommit(repository, true).Except(excludedBranches).ToList();
}
else
{
var branches = ListBranchesContaininingCommit(repository, branchPoint.Sha, excludedBranches).ToList();
var currentTipBranches = ListBranchesContaininingCommit(repository, currentCommit.Sha, excludedBranches).ToList();
var branches = branchPoint.GetBranchesContainingCommit(repository, true).Except(excludedBranches).ToList();
var currentTipBranches = currentCommit.GetBranchesContainingCommit(repository, true).Except(excludedBranches).ToList();
possibleParents = branches
.Except(currentTipBranches)
.ToList();
Expand Down Expand Up @@ -119,14 +116,5 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(
Increment = GetBranchConfiguration(currentCommit, repository, onlyEvaluateTrackedBranches, config, repository.Branches[branchName]).Value.Increment
});
}

static IEnumerable<Branch> ListBranchesContaininingCommit(IRepository repo, string commitSha, Branch[] excludedBranches)
{
return from branch in repo.Branches.Except(excludedBranches)
where !branch.IsRemote
let commits = repo.Commits.QueryBy(new CommitFilter { Since = branch }).Where(c => c.Sha == commitSha)
where commits.Any()
select branch;
}
}
}
8 changes: 7 additions & 1 deletion GitVersionCore/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ public Dictionary<string, BranchConfig> Branches
}
set
{
value.ToList().ForEach(_ => branches[_.Key] = MergeObjects(branches[_.Key], _.Value));
value.ToList().ForEach(_ =>
{
if (!branches.ContainsKey(_.Key))
branches.Add(_.Key, new BranchConfig());

branches[_.Key] = MergeObjects(branches[_.Key], _.Value);
});
}
}

Expand Down
4 changes: 2 additions & 2 deletions GitVersionCore/Configuration/ConfigSerialiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public static void WriteSample(TextWriter writer)
writer.WriteLine("# mode: ContinuousDelivery | ContinuousDeployment");
writer.WriteLine("# continuous-delivery-fallback-tag: ci");
writer.WriteLine("#branches:");
writer.WriteLine("# release[/-]*:\n mode: ContinuousDelivery | ContinuousDeployment\n tag: rc");
writer.WriteLine("# develop:\n mode: ContinuousDelivery | ContinuousDeployment\n tag: alpha");
writer.WriteLine("# release[/-]:\n mode: ContinuousDelivery | ContinuousDeployment\n tag: rc");
writer.WriteLine("# develop:\n# mode: ContinuousDelivery | ContinuousDeployment\n# tag: alpha");
}
}
}
6 changes: 2 additions & 4 deletions GitVersionCore/GitVersionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ public GitVersionContext(IRepository repository, Branch currentBranch, Config co
void CalculateEffectiveConfiguration()
{
var currentBranchConfig = BranchConfigurationCalculator.GetBranchConfiguration(CurrentCommit, Repository, OnlyEvaluateTrackedBranches, configuration, CurrentBranch);

// Versioning mode drills down, if top level is specified then it takes priority
var versioningMode = configuration.VersioningMode ?? currentBranchConfig.Value.VersioningMode ?? VersioningMode.ContinuousDelivery;


var versioningMode = currentBranchConfig.Value.VersioningMode ?? configuration.VersioningMode ?? VersioningMode.ContinuousDelivery;
var tag = currentBranchConfig.Value.Tag ?? "useBranchName";
var nextVersion = configuration.NextVersion;
var incrementStrategy = currentBranchConfig.Value.Increment ?? IncrementStrategy.Patch;
Expand Down
3 changes: 1 addition & 2 deletions GitVersionCore/OutputVariables/VariableProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public static VersionVariables GetVariablesFor(
}

// For continuous deployment the commits since tag gets promoted to the pre-release number
var oldPreReleaseNumber = semanticVersion.PreReleaseTag.Number;
semanticVersion.PreReleaseTag.Number = semanticVersion.BuildMetaData.CommitsSinceTag;
semanticVersion.BuildMetaData.CommitsSinceTag = oldPreReleaseNumber;
semanticVersion.BuildMetaData.CommitsSinceTag = null;
}

var variables = new VersionVariables(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using System;
using System.Reflection;

[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.3.4.0")]
[assembly: AssemblyInformationalVersion("2.3.4+5.Branch.master.Sha.commitSha")]
[assembly: ReleaseDate("2014-03-06")]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using System;
using System.Reflection;

[assembly: AssemblyVersion("2.3.0.0")]
[assembly: AssemblyFileVersion("2.3.0.0")]
[assembly: AssemblyFileVersion("2.3.4.0")]
[assembly: AssemblyInformationalVersion("2.3.4+5.Branch.master.Sha.commitSha")]
[assembly: ReleaseDate("2014-03-06")]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using System;
using System.Reflection;

[assembly: AssemblyVersion("2.3.4.5")]
[assembly: AssemblyFileVersion("2.3.4.5")]
[assembly: AssemblyFileVersion("2.3.4.0")]
[assembly: AssemblyInformationalVersion("2.3.4+5.Branch.master.Sha.commitSha")]
[assembly: ReleaseDate("2014-03-06")]

Expand Down
5 changes: 3 additions & 2 deletions GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ static class GitVersionInformation
}}


", vars.AssemblySemVer,
vars.AssemblySemVer,
",
vars.AssemblySemVer,
vars.MajorMinorPatch + ".0",
semanticVersion.ToString("i"),
semanticVersion.BuildMetaData.CommitDate.UtcDateTime.ToString("yyyy-MM-dd"),
GenerateVariableMembers(vars));
Expand Down