Skip to content

Commit

Permalink
Merge branch 'master' into GitVersion-calculating-wrong-version-when-…
Browse files Browse the repository at this point in the history
…building-a-tag
  • Loading branch information
gerwinjansen authored Nov 5, 2020
2 parents a954ba7 + 14fc094 commit 2bdebfa
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<PackageVersion_NUnit>3.12.0</PackageVersion_NUnit>
<PackageVersion_GitToolsTesting>1.2.0</PackageVersion_GitToolsTesting>
<PackageVersion_NUnit3TestAdapter>3.17.0</PackageVersion_NUnit3TestAdapter>
<PackageVersion_NunitXmlTestLogger>2.1.62</PackageVersion_NunitXmlTestLogger>
<PackageVersion_NunitXmlTestLogger>2.1.80</PackageVersion_NunitXmlTestLogger>
<PackageVersion_Shouldly>4.0.0-beta0004</PackageVersion_Shouldly>

</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using GitVersion.Model.Configuration;
using GitVersion.VersionCalculation;
using GitVersionCore.Tests.Helpers;
using GitVersionCore.Tests.IntegrationTests;
using GitVersionCore.Tests.Mocks;
using LibGit2Sharp;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -214,5 +215,20 @@ public void PreReleaseNumberShouldBeScopeToPreReleaseLabelInContinuousDelivery()

fixture.AssertFullSemver("0.1.0-beta.1+2", config);
}

[Test]
public void GetNextVersionOnNonMainlineBranchWithoutCommitsShouldWorkNormally()
{
var config = new Config
{
VersioningMode = VersioningMode.Mainline,
NextVersion = "1.0.0"
};

using var fixture = new EmptyRepositoryFixture();
fixture.MakeACommit("initial commit");
fixture.BranchTo("feature/f1");
fixture.AssertFullSemver("1.0.0-f1.0", config);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,17 @@ private Commit FindMergeBaseBeforeForwardMerge(Commit baseVersionSource, Branch
// detect forward merge and rewind mainlineTip to before it
if (mergeBase == context.CurrentCommit && !mainlineCommitLog.Contains(mergeBase))
{
var mainlineTipPrevious = mainlineTip.Parents.First();
var message = $"Detected forward merge at {mainlineTip}; rewinding mainline to previous commit {mainlineTipPrevious}";
var mainlineTipPrevious = mainlineTip.Parents.FirstOrDefault();
if (mainlineTipPrevious != null)
{
var message = $"Detected forward merge at {mainlineTip}; rewinding mainline to previous commit {mainlineTipPrevious}";

log.Info(message);
log.Info(message);

// re-do mergeBase detection before the forward merge
mergeBase = repositoryMetadataProvider.FindMergeBase(context.CurrentCommit, mainlineTipPrevious);
mainlineTip = GetEffectiveMainlineTip(mainlineCommitLog, mergeBase, mainlineTipPrevious);
// re-do mergeBase detection before the forward merge
mergeBase = repositoryMetadataProvider.FindMergeBase(context.CurrentCommit, mainlineTipPrevious);
mainlineTip = GetEffectiveMainlineTip(mainlineCommitLog, mergeBase, mainlineTipPrevious);
}
}

return mergeBase;
Expand Down
63 changes: 63 additions & 0 deletions src/GitVersionExe.Tests/ArgumentParserOnBuildServerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using GitVersion;
using GitVersion.OutputVariables;
using GitVersionCore.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using Shouldly;

namespace GitVersionExe.Tests
{
[TestFixture]
public class ArgumentParserOnBuildServerTests : TestBase
{
private IArgumentParser argumentParser;

[SetUp]
public void SetUp()
{
var sp = ConfigureServices(services =>
{
services.AddSingleton<IArgumentParser, ArgumentParser>();
services.AddSingleton<IGlobbingResolver, GlobbingResolver>();
services.AddSingleton<ICurrentBuildAgent, MockBuildAgent>();
});
argumentParser = sp.GetService<IArgumentParser>();
}

[Test]
public void EmptyOnFetchDisabledBuildServerMeansNoFetchIsTrue()
{
var arguments = argumentParser.ParseArguments("");
arguments.NoFetch.ShouldBe(true);
}

private class MockBuildAgent : ICurrentBuildAgent
{
public bool CanApplyToCurrentContext()
{
throw new NotImplementedException();
}

public void WriteIntegration(Action<string> writer, VersionVariables variables, bool updateBuildNumber = true)
{
throw new NotImplementedException();
}

public string GetCurrentBranch(bool usingDynamicRepos)
{
throw new NotImplementedException();
}

public bool PreventFetch()
{
return true;
}

public bool ShouldCleanUpRemotes()
{
throw new NotImplementedException();
}
}
}
}
2 changes: 2 additions & 0 deletions src/GitVersionExe/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public Arguments ParseArguments(string[] commandLineArguments)

AddAuthentication(args);

args.NoFetch = buildAgent != null && buildAgent.PreventFetch();

return args;
}

Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionTask.Tests/GitVersionTask.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Buildalyzer" Version="3.0.1" />
<PackageReference Include="Buildalyzer" Version="3.1.0" />
<PackageReference Include="LibGit2Sharp" Version="$(PackageVersion_LibGit2Sharp)" />
<PackageReference Include="Microsoft.Build" Version="$(PackageVersion_MsBuild)" />
<PackageReference Include="MSBuild.ProjectCreation" Version="1.4.6" />
Expand Down

0 comments on commit 2bdebfa

Please sign in to comment.