Skip to content

Commit 780f815

Browse files
committed
Improve exceptions when no Mainline branches are found
1 parent 309118b commit 780f815

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using GitVersion.VersionCalculation;
66
using LibGit2Sharp;
77
using NUnit.Framework;
8+
using Shouldly;
89

910
namespace GitVersion.Core.Tests.IntegrationTests;
1011

@@ -537,6 +538,32 @@ public void BranchWithoutMergeBaseMainlineBranchIsFound()
537538
fixture.AssertFullSemver("0.1.3-issue-branch.1", currentConfig);
538539
}
539540

541+
[Test]
542+
public void GivenARemoteGitRepositoryWithCommitsThenClonedLocalDevelopShouldMatchRemoteVersion()
543+
{
544+
using var fixture = new RemoteRepositoryFixture();
545+
fixture.AssertFullSemver("0.1.4", config);
546+
fixture.BranchTo("develop");
547+
fixture.AssertFullSemver("0.2.0-alpha.0", config);
548+
Console.WriteLine(fixture.SequenceDiagram.GetDiagram());
549+
var local = fixture.CloneRepository();
550+
fixture.AssertFullSemver("0.2.0-alpha.0", config, repository: local.Repository);
551+
local.Repository.DumpGraph();
552+
}
553+
554+
[Test]
555+
public void GivenNoMainThrowsWarning()
556+
{
557+
using var fixture = new EmptyRepositoryFixture();
558+
fixture.Repository.MakeACommit();
559+
fixture.Repository.MakeATaggedCommit("1.0.0");
560+
fixture.Repository.MakeACommit();
561+
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("develop"));
562+
fixture.Repository.Branches.Remove(fixture.Repository.Branches["main"]);
563+
564+
var exception = Assert.Throws<WarningException>(() => fixture.AssertFullSemver("1.1.0-alpha.1", config));
565+
exception.Message.ShouldMatch("No branches can be found matching the commit .* in the configured Mainline branches: main, support");
566+
}
540567
}
541568

542569
internal static class CommitExtensions

src/GitVersion.Core/VersionCalculation/MainlineVersionCalculator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ private IBranch GetMainline(ICommit? baseVersionSource)
128128

129129
if (!mainlineBranches.Any())
130130
{
131-
throw new WarningException("No mainline branches found!");
131+
var mainlineBranchConfigsString = string.Join(", ", mainlineBranchConfigs.Select(b => b.Value.Name));
132+
throw new WarningException($"No branches can be found matching the commit {context.CurrentCommit.Sha} in the configured Mainline branches: {mainlineBranchConfigsString}");
132133
}
133134

134135
var mainlineBranchNames = mainlineBranches.Values.SelectMany(branches => branches.Select(b => b.Name.Friendly));

0 commit comments

Comments
 (0)