Skip to content
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

[Bug] Mainline mode not properly using next-version #2335

Closed
FISHMANPET opened this issue Jun 22, 2020 · 11 comments · Fixed by #2356
Closed

[Bug] Mainline mode not properly using next-version #2335

FISHMANPET opened this issue Jun 22, 2020 · 11 comments · Fixed by #2356
Milestone

Comments

@FISHMANPET
Copy link
Contributor

I'm trying to use GitVersion in a brand new project of mine, using GitHub Flow and mainline mode, and I'm having trouble configuring it to behave the way I'd like/am expecting to.

I've been able to use GitVersion in an existing project of mine, where I'm able to tag the most recent release. For example if I've released 1.2.3, I can tag that in Git. On changes in a new branch, GitVersion will generate 1.2.4-branch0001 versions, which is what I'm expecting and what I want.

But I can't seem to figure out how to replicate this same behavior before I have any kind of release. What I would imagine I do is set the next-version in my config to 1.0.0, then versions will be generated like 1.0.0-branch0001, 1.0.0-branch0002, etc, until I merge into master, gitversion generates 1.0.0, and Git is tagged with that version. At that point I can remove next-version and rely on GitVersion seeing the Git tags to determine the next version. However when I set next-version to 1.0.0, GitVersion generates 1.0.1-branch0001 versions. I experimented a bit, and if I run it in master with next-version set to 1.0.0 and mode:MainLine, it will generate 1.0.0. However my build processes deploys the pre-release versions to a test environment, and I need them to be a semantically lower version than the 1.0.0 that will eventually be released.

Is this a bug in gitversion? Is there an additional configuration setting I'm missing? Some misunderstanding I have with how the tool operates?

@asbjornu
Copy link
Member

This is strange. Can you try to delete your GitVersion.yml file and see if that helps? The following test shows that your use-case is working just as you describe:

[Test]
public void PreReleaseTagCanUseBranchName()
{
var config = new Config
{
NextVersion = "1.0.0",
Branches = new Dictionary<string, BranchConfig>
{
{
"custom", new BranchConfig
{
Regex = "custom/",
Tag = "useBranchName",
SourceBranches = new HashSet<string>()
}
}
}
};
using var fixture = new EmptyRepositoryFixture();
fixture.MakeACommit();
fixture.BranchTo("develop");
fixture.MakeACommit();
fixture.BranchTo("custom/foo");
fixture.MakeACommit();
fixture.AssertFullSemver("1.0.0-foo.1+2", config);
}

@FISHMANPET
Copy link
Contributor Author

If I delete gitversion.yml it works like I expect, except it's defaulting to version 0.1.0 so my versions in the branch are 0.1.0-branch0001.

I just tried it in a brand new repository, here are the exact steps I took:
Create new repository
Create new branch (bajurny) in repository based off master
Commit gitversion.yml (because I need some commit in the branch) that looks like this:

mode: Mainline
next-version: 1.0.0

And at that point, I run gitversion and the generated version is 1.0.1-bajurny0001 rather than the expected 1.0.0-bajurny0001

And I merged bajurny into master (whose only changes are the gitversion.yml) and then gitversion returns 1.0.1 as the version.

@asbjornu
Copy link
Member

What version number do you get if you remove mode: Mainline and the only thing in your GitVersion.yml is next-version 1.0.0?

@FISHMANPET
Copy link
Contributor Author

Getting a chance to play around with this again.

If I remove mode: Mainline then GitVersion properly returns a 1.0.0 prerelease number, if I add mode: Mainline back in it creates a 1.0.1 prerelease.

So it looks like that test case tests the case with no mode specified, but not with Mainline, and it also sounds like this is a bug rather than a documentation issue.

@FISHMANPET
Copy link
Contributor Author

I wrote two failing tests, it looks like mainline mode isn't properly using next-version, perhaps treating the next-version as the already deployed version, rather than truly the next version.

The first test is when inside a branch, setting next-version to 1.0.0, and gitversion returns 1.0.1-foo.1 instead of 1.0.0-foo.1.
The second test is when a branch is merged into the mainline (master) with next-version, it should produce 1.0.0 but it produces 1.0.1.

I tried to poke around at the source code to try and find where this might be happening but I'm not very fluent in C# so I wasn't able to immediately figure out where it might be happening.
I never shared this, this is the result of gitversion /diag where I would expect 1.0.0-brach1.4 but instead get 1.0.1-brach1.4

PS C:\Users\bajurny\Desktop\gitversion\gv1> gitversion /diag
INFO [07/13/20 13:25:55:16] Dumping commit graph:
INFO [07/13/20 13:25:55:21] * c32bdd4 34 minutes ago  (HEAD -> branch1)
* fc3a097 38 minutes ago
* 50aa2f3 48 minutes ago
* 5598a81 49 minutes ago
* 8adf1a4 55 minutes ago  (master)

INFO [07/13/20 13:25:55:22] Working directory: C:\Users\bajurny\Desktop\gitversion\gv1
INFO [07/13/20 13:25:55:24] Project root is: C:\Users\bajurny\Desktop\gitversion\gv1\
INFO [07/13/20 13:25:55:24] DotGit directory is: C:\Users\bajurny\Desktop\gitversion\gv1\.git
INFO [07/13/20 13:25:55:34] Using latest commit on specified branch
INFO [07/13/20 13:25:55:34] No branch configuration found for branch branch1, falling back to default configuration
INFO [07/13/20 13:25:55:35] Begin: Attempting to inherit branch configuration from parent branch
  INFO [07/13/20 13:25:55:35] Begin: Finding branch source of 'branch1'
    INFO [07/13/20 13:25:55:36] Begin: Finding merge base between 'branch1' and 'master'.
      INFO [07/13/20 13:25:55:37] Found merge base of 8adf1a4025ff4e2b13501e00018b5edc1c9219e5
      INFO [07/13/20 13:25:55:37] Merge base of branch1' and 'master is 8adf1a4025ff4e2b13501e00018b5edc1c9219e5
    INFO [07/13/20 13:25:55:37] End: Finding merge base between 'branch1' and 'master'. (Took: 10.89ms)
  INFO [07/13/20 13:25:55:38] End: Finding branch source of 'branch1' (Took: 22.31ms)
  INFO [07/13/20 13:25:55:38] Begin: Getting branches containing the commit '8adf1a4025ff4e2b13501e00018b5edc1c9219e5'.
    INFO [07/13/20 13:25:55:38] Trying to find direct branches.
    INFO [07/13/20 13:25:55:38] No direct branches found, searching through all branches.
    INFO [07/13/20 13:25:55:38] Searching for commits reachable from 'master'.
    INFO [07/13/20 13:25:55:39] The branch 'master' has a matching commit.
  INFO [07/13/20 13:25:55:39] End: Getting branches containing the commit '8adf1a4025ff4e2b13501e00018b5edc1c9219e5'. (Took: 8.49ms)
  INFO [07/13/20 13:25:55:39] Found possible parent branches: master
  INFO [07/13/20 13:25:55:39] End: Attempting to inherit branch configuration from parent branch (Took: 43.38ms)
  INFO [07/13/20 13:25:55:39] Running against branch: branch1 (c32bdd47c6a714120341b6175bec80742b12ef87)
  INFO [07/13/20 13:25:55:39] Begin: Calculating base versions
    INFO [07/13/20 13:25:55:41] NextVersion in GitVersion configuration file: 1.0.0 with commit count source External Source
    INFO [07/13/20 13:25:55:43] Base version used: NextVersion in GitVersion configuration file: 1.0.0 with commit count source 8adf1a4025ff4e2b13501e00018b5edc1c9219e5
  INFO [07/13/20 13:25:55:43] End: Calculating base versions (Took: 39.62ms)
  INFO [07/13/20 13:25:55:44] Begin: Using mainline development mode to calculate current version
    INFO [07/13/20 13:25:55:44] Found possible mainline branches: master
    INFO [07/13/20 13:25:55:45] Mainline for current branch is master
    INFO [07/13/20 13:25:55:45] Current branch (branch1) was branch from 8adf1a4025ff4e2b13501e00018b5edc1c9219e5
    INFO [07/13/20 13:25:55:45] 4 commits found between 8adf1a4025ff4e2b13501e00018b5edc1c9219e5 and c32bdd47c6a714120341b6175bec80742b12ef87
    INFO [07/13/20 13:25:55:45] Performing Patch increment for current branch
  INFO [07/13/20 13:25:55:45] End: Using mainline development mode to calculate current version (Took: 16.54ms)
  INFO [07/13/20 13:25:55:46] Using branch name to calculate version tag
  INFO [07/13/20 13:25:55:46] Begin: Getting version tags from branch 'refs/heads/branch1'.
  INFO [07/13/20 13:25:55:46] End: Getting version tags from branch 'refs/heads/branch1'. (Took: 2.88ms)
{
  "Major":1,
  "Minor":0,
  "Patch":1,
  "PreReleaseTag":"branch1.4",
  "PreReleaseTagWithDash":"-branch1.4",
  "PreReleaseLabel":"branch1",
  "PreReleaseNumber":4,
  "WeightedPreReleaseNumber":4,
  "BuildMetaData":"",
  "BuildMetaDataPadded":"",
  "FullBuildMetaData":"Branch.branch1.Sha.c32bdd47c6a714120341b6175bec80742b12ef87",
  "MajorMinorPatch":"1.0.1",
  "SemVer":"1.0.1-branch1.4",
  "LegacySemVer":"1.0.1-branch1-4",
  "LegacySemVerPadded":"1.0.1-branch1-0004",
  "AssemblySemVer":"1.0.1.0",
  "AssemblySemFileVer":"1.0.1.0",
  "FullSemVer":"1.0.1-branch1.4",
  "InformationalVersion":"1.0.1-branch1.4+Branch.branch1.Sha.c32bdd47c6a714120341b6175bec80742b12ef87",
  "BranchName":"branch1",
  "EscapedBranchName":"branch1",
  "Sha":"c32bdd47c6a714120341b6175bec80742b12ef87",
  "ShortSha":"c32bdd4",
  "NuGetVersionV2":"1.0.1-branch1-0004",
  "NuGetVersion":"1.0.1-branch1-0004",
  "NuGetPreReleaseTagV2":"branch1-0004",
  "NuGetPreReleaseTag":"branch1-0004",
  "VersionSourceSha":"8adf1a4025ff4e2b13501e00018b5edc1c9219e5",
  "CommitsSinceVersionSource":4,
  "CommitsSinceVersionSourcePadded":"0004",
  "CommitDate":"2020-07-13"
}
  INFO [07/13/20 13:25:55:48] Done writing

From what I can tell it's properly finding the next-version, but then I suspect the mainline code isn't using it properly, but I haven't found where those parts are glued together yet to try and get a better idea of the logic.

@asbjornu
Copy link
Member

Please take a look at the mainline mode tests we have and whether they are covering your scenario at all. If not, we would welcome a PR with more tests and a fix that hopefully doesn't break a bunch of the existing tests.

public class MainlineDevelopmentMode : TestBase
{
private readonly Config config = new Config
{
VersioningMode = VersioningMode.Mainline
};
[Test]
public void VerifyNonMasterMainlineVersionIdenticalAsMaster()
{
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeACommit("1");
fixture.BranchTo("feature/foo", "foo");
fixture.MakeACommit("2 +semver: major");
fixture.Checkout("master");
fixture.MergeNoFF("feature/foo");
fixture.AssertFullSemver("1.0.0", config);
fixture.BranchTo("support/1.0", "support");
fixture.AssertFullSemver("1.0.0", config);
}
[Test]
public void MergedFeatureBranchesToMasterImpliesRelease()
{
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeACommit("1");
fixture.MakeATaggedCommit("1.0.0");
fixture.BranchTo("feature/foo", "foo");
fixture.MakeACommit("2");
fixture.AssertFullSemver("1.0.1-foo.1", config);
fixture.MakeACommit("2.1");
fixture.AssertFullSemver("1.0.1-foo.2", config);
fixture.Checkout("master");
fixture.MergeNoFF("feature/foo");
fixture.AssertFullSemver("1.0.1", config);
fixture.BranchTo("feature/foo2", "foo2");
fixture.MakeACommit("3 +semver: minor");
fixture.AssertFullSemver("1.1.0-foo2.1", config);
fixture.Checkout("master");
fixture.MergeNoFF("feature/foo2");
fixture.AssertFullSemver("1.1.0", config);
fixture.BranchTo("feature/foo3", "foo3");
fixture.MakeACommit("4");
fixture.Checkout("master");
fixture.MergeNoFF("feature/foo3");
fixture.SequenceDiagram.NoteOver("Merge message contains '+semver: minor'", "master");
var commit = fixture.Repository.Head.Tip;
// Put semver increment in merge message
fixture.Repository.Commit(commit.Message + " +semver: minor", commit.Author, commit.Committer, new CommitOptions
{
AmendPreviousCommit = true
});
fixture.AssertFullSemver("1.2.0", config);
fixture.BranchTo("feature/foo4", "foo4");
fixture.MakeACommit("5 +semver: major");
fixture.AssertFullSemver("2.0.0-foo4.1", config);
fixture.Checkout("master");
fixture.MergeNoFF("feature/foo4");
fixture.AssertFullSemver("2.0.0", config);
// We should evaluate any commits not included in merge commit calculations for direct commit/push or squash to merge commits
fixture.MakeACommit("6 +semver: major");
fixture.AssertFullSemver("3.0.0", config);
fixture.MakeACommit("7 +semver: minor");
fixture.AssertFullSemver("3.1.0", config);
fixture.MakeACommit("8");
fixture.AssertFullSemver("3.1.1", config);
// Finally verify that the merge commits still function properly
fixture.BranchTo("feature/foo5", "foo5");
fixture.MakeACommit("9 +semver: minor");
fixture.AssertFullSemver("3.2.0-foo5.1", config);
fixture.Checkout("master");
fixture.MergeNoFF("feature/foo5");
fixture.AssertFullSemver("3.2.0", config);
// One more direct commit for good measure
fixture.MakeACommit("10 +semver: minor");
fixture.AssertFullSemver("3.3.0", config);
// And we can commit without bumping semver
fixture.MakeACommit("11 +semver: none");
fixture.AssertFullSemver("3.3.0", config);
Console.WriteLine(fixture.SequenceDiagram.GetDiagram());
}
[Test]
public void VerifyPullRequestsActLikeContinuousDelivery()
{
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeACommit("1");
fixture.MakeATaggedCommit("1.0.0");
fixture.MakeACommit();
fixture.AssertFullSemver("1.0.1", config);
fixture.BranchTo("feature/foo", "foo");
fixture.AssertFullSemver("1.0.2-foo.0", config);
fixture.MakeACommit();
fixture.MakeACommit();
fixture.Repository.CreatePullRequestRef("feature/foo", "master", normalise: true, prNumber: 8);
fixture.AssertFullSemver("1.0.2-PullRequest0008.3", config);
}
[Test]
public void SupportBranches()
{
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeACommit("1");
fixture.MakeATaggedCommit("1.0.0");
fixture.MakeACommit(); // 1.0.1
fixture.MakeACommit(); // 1.0.2
fixture.AssertFullSemver("1.0.2", config);
fixture.BranchTo("support/1.0", "support10");
fixture.AssertFullSemver("1.0.2", config);
// Move master on
fixture.Checkout("master");
fixture.MakeACommit("+semver: major"); // 2.0.0 (on master)
fixture.AssertFullSemver("2.0.0", config);
// Continue on support/1.0
fixture.Checkout("support/1.0");
fixture.MakeACommit(); // 1.0.3
fixture.MakeACommit(); // 1.0.4
fixture.AssertFullSemver("1.0.4", config);
fixture.BranchTo("feature/foo", "foo");
fixture.AssertFullSemver("1.0.5-foo.0", config);
fixture.MakeACommit();
fixture.AssertFullSemver("1.0.5-foo.1", config);
fixture.MakeACommit();
fixture.AssertFullSemver("1.0.5-foo.2", config);
fixture.Repository.CreatePullRequestRef("feature/foo", "support/1.0", normalise: true, prNumber: 7);
fixture.AssertFullSemver("1.0.5-PullRequest0007.3", config);
}
[Test]
public void VerifyForwardMerge()
{
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeACommit("1");
fixture.MakeATaggedCommit("1.0.0");
fixture.MakeACommit(); // 1.0.1
fixture.BranchTo("feature/foo", "foo");
fixture.MakeACommit();
fixture.AssertFullSemver("1.0.2-foo.1", config);
fixture.MakeACommit();
fixture.AssertFullSemver("1.0.2-foo.2", config);
fixture.Checkout("master");
fixture.MakeACommit();
fixture.AssertFullSemver("1.0.2", config);
fixture.Checkout("feature/foo");
// This may seem surprising, but this happens because we branched off mainline
// and incremented. Mainline has then moved on. We do not follow mainline
// in feature branches, you need to merge mainline in to get the mainline version
fixture.AssertFullSemver("1.0.2-foo.2", config);
fixture.MergeNoFF("master");
fixture.AssertFullSemver("1.0.3-foo.3", config);
}
[Test]
public void VerifySupportForwardMerge()
{
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeACommit("1");
fixture.MakeATaggedCommit("1.0.0");
fixture.MakeACommit(); // 1.0.1
fixture.BranchTo("support/1.0", "support10");
fixture.MakeACommit();
fixture.MakeACommit();
fixture.Checkout("master");
fixture.MakeACommit("+semver: minor");
fixture.AssertFullSemver("1.1.0", config);
fixture.MergeNoFF("support/1.0");
fixture.AssertFullSemver("1.1.1", config);
fixture.MakeACommit();
fixture.AssertFullSemver("1.1.2", config);
fixture.Checkout("support/1.0");
fixture.AssertFullSemver("1.0.3", config);
fixture.BranchTo("feature/foo", "foo");
fixture.MakeACommit();
fixture.MakeACommit();
fixture.AssertFullSemver("1.0.4-foo.2", config); // TODO This probably should be 1.0.5
}
[Test]
public void VerifyDevelopTracksMasterVersion()
{
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeACommit("1");
fixture.MakeATaggedCommit("1.0.0");
fixture.MakeACommit();
// branching increments the version
fixture.BranchTo("develop");
fixture.AssertFullSemver("1.1.0-alpha.0", config);
fixture.MakeACommit();
fixture.AssertFullSemver("1.1.0-alpha.1", config);
// merging develop into master increments minor version on master
fixture.Checkout("master");
fixture.MergeNoFF("develop");
fixture.AssertFullSemver("1.1.0", config);
// a commit on develop before the merge still has the same version number
fixture.Checkout("develop");
fixture.AssertFullSemver("1.1.0-alpha.1", config);
// moving on to further work on develop tracks master's version from the merge
fixture.MakeACommit();
fixture.AssertFullSemver("1.2.0-alpha.1", config);
// adding a commit to master increments patch
fixture.Checkout("master");
fixture.MakeACommit();
fixture.AssertFullSemver("1.1.1", config);
// adding a commit to master doesn't change develop's version
fixture.Checkout("develop");
fixture.AssertFullSemver("1.2.0-alpha.1", config);
}
[Test]
public void VerifyDevelopFeatureTracksMasterVersion()
{
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeACommit("1");
fixture.MakeATaggedCommit("1.0.0");
fixture.MakeACommit();
// branching increments the version
fixture.BranchTo("develop");
fixture.AssertFullSemver("1.1.0-alpha.0", config);
fixture.MakeACommit();
fixture.AssertFullSemver("1.1.0-alpha.1", config);
// merging develop into master increments minor version on master
fixture.Checkout("master");
fixture.MergeNoFF("develop");
fixture.AssertFullSemver("1.1.0", config);
// a commit on develop before the merge still has the same version number
fixture.Checkout("develop");
fixture.AssertFullSemver("1.1.0-alpha.1", config);
// a branch from develop before the merge tracks the pre-merge version from master
// (note: the commit on develop looks like a commit to this branch, thus the .1)
fixture.BranchTo("feature/foo");
fixture.AssertFullSemver("1.0.2-foo.1", config);
// further work on the branch tracks the merged version from master
fixture.MakeACommit();
fixture.AssertFullSemver("1.1.1-foo.1", config);
// adding a commit to master increments patch
fixture.Checkout("master");
fixture.MakeACommit();
fixture.AssertFullSemver("1.1.1", config);
// adding a commit to master doesn't change the feature's version
fixture.Checkout("feature/foo");
fixture.AssertFullSemver("1.1.1-foo.1", config);
// merging the feature to develop increments develop
fixture.Checkout("develop");
fixture.MergeNoFF("feature/foo");
fixture.AssertFullSemver("1.2.0-alpha.2", config);
}
[Test]
public void VerifyMergingMasterToFeatureDoesNotCauseBranchCommitsToIncrementVersion()
{
using var fixture = new EmptyRepositoryFixture();
fixture.MakeACommit("first in master");
fixture.BranchTo("feature/foo", "foo");
fixture.MakeACommit("first in foo");
fixture.Checkout("master");
fixture.MakeACommit("second in master");
fixture.Checkout("feature/foo");
fixture.MergeNoFF("master");
fixture.MakeACommit("second in foo");
fixture.Checkout("master");
fixture.MakeATaggedCommit("1.0.0");
fixture.MergeNoFF("feature/foo");
fixture.AssertFullSemver("1.0.1", config);
}
[Test]
public void VerifyMergingMasterToFeatureDoesNotStopMasterCommitsIncrementingVersion()
{
using var fixture = new EmptyRepositoryFixture();
fixture.MakeACommit("first in master");
fixture.BranchTo("feature/foo", "foo");
fixture.MakeACommit("first in foo");
fixture.Checkout("master");
fixture.MakeATaggedCommit("1.0.0");
fixture.MakeACommit("third in master");
fixture.Checkout("feature/foo");
fixture.MergeNoFF("master");
fixture.MakeACommit("second in foo");
fixture.Checkout("master");
fixture.MergeNoFF("feature/foo");
fixture.AssertFullSemver("1.0.2", config);
}
[Test]
public void VerifyIssue1154CanForwardMergeMasterToFeatureBranch()
{
using var fixture = new EmptyRepositoryFixture();
fixture.MakeACommit();
fixture.BranchTo("feature/branch2");
fixture.BranchTo("feature/branch1");
fixture.MakeACommit();
fixture.MakeACommit();
fixture.Checkout("master");
fixture.MergeNoFF("feature/branch1");
fixture.AssertFullSemver("0.1.1", config);
fixture.Checkout("feature/branch2");
fixture.MakeACommit();
fixture.MakeACommit();
fixture.MakeACommit();
fixture.MergeNoFF("master");
fixture.AssertFullSemver("0.1.2-branch2.4", config);
}
[Test]
public void VerifyMergingMasterIntoAFeatureBranchWorksWithMultipleBranches()
{
using var fixture = new EmptyRepositoryFixture();
fixture.MakeACommit("first in master");
fixture.BranchTo("feature/foo", "foo");
fixture.MakeACommit("first in foo");
fixture.BranchTo("feature/bar", "bar");
fixture.MakeACommit("first in bar");
fixture.Checkout("master");
fixture.MakeACommit("second in master");
fixture.Checkout("feature/foo");
fixture.MergeNoFF("master");
fixture.MakeACommit("second in foo");
fixture.Checkout("feature/bar");
fixture.MergeNoFF("master");
fixture.MakeACommit("second in bar");
fixture.Checkout("master");
fixture.MakeATaggedCommit("1.0.0");
fixture.MergeNoFF("feature/foo");
fixture.MergeNoFF("feature/bar");
fixture.AssertFullSemver("1.0.2", config);
}
[Test]
public void MergingFeatureBranchThatIncrementsMinorNumberIncrementsMinorVersionOfMaster()
{
var currentConfig = new Config
{
VersioningMode = VersioningMode.Mainline,
Branches = new Dictionary<string, BranchConfig>
{
{
"feature", new BranchConfig
{
VersioningMode = VersioningMode.ContinuousDeployment,
Increment = IncrementStrategy.Minor
}
}
}
};
using var fixture = new EmptyRepositoryFixture();
fixture.MakeACommit("first in master");
fixture.MakeATaggedCommit("1.0.0");
fixture.AssertFullSemver("1.0.0", currentConfig);
fixture.BranchTo("feature/foo", "foo");
fixture.MakeACommit("first in foo");
fixture.MakeACommit("second in foo");
fixture.AssertFullSemver("1.1.0-foo.2", currentConfig);
fixture.Checkout("master");
fixture.MergeNoFF("feature/foo");
fixture.AssertFullSemver("1.1.0", currentConfig);
}
[Test]
public void VerifyIncrementConfigIsHonoured()
{
var minorIncrementConfig = new Config
{
VersioningMode = VersioningMode.Mainline,
Increment = IncrementStrategy.Minor,
Branches = new Dictionary<string, BranchConfig>
{
{
"master",
new BranchConfig
{
Increment = IncrementStrategy.Minor,
Name = "master",
Regex = "master"
}
},
{
"feature",
new BranchConfig
{
Increment = IncrementStrategy.Minor,
Name = "feature",
Regex = "features?[/-]"
}
}
}
};
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeACommit("1");
fixture.MakeATaggedCommit("1.0.0");
fixture.BranchTo("feature/foo", "foo");
fixture.MakeACommit("2");
fixture.AssertFullSemver("1.1.0-foo.1", minorIncrementConfig);
fixture.MakeACommit("2.1");
fixture.AssertFullSemver("1.1.0-foo.2", minorIncrementConfig);
fixture.Checkout("master");
fixture.MergeNoFF("feature/foo");
fixture.AssertFullSemver("1.1.0", minorIncrementConfig);
fixture.BranchTo("feature/foo2", "foo2");
fixture.MakeACommit("3 +semver: patch");
fixture.AssertFullSemver("1.1.1-foo2.1", minorIncrementConfig);
fixture.Checkout("master");
fixture.MergeNoFF("feature/foo2");
fixture.AssertFullSemver("1.1.1", minorIncrementConfig);
fixture.BranchTo("feature/foo3", "foo3");
fixture.MakeACommit("4");
fixture.Checkout("master");
fixture.MergeNoFF("feature/foo3");
fixture.SequenceDiagram.NoteOver("Merge message contains '+semver: patch'", "master");
var commit = fixture.Repository.Head.Tip;
// Put semver increment in merge message
fixture.Repository.Commit(commit.Message + " +semver: patch", commit.Author, commit.Committer, new CommitOptions
{
AmendPreviousCommit = true
});
fixture.AssertFullSemver("1.1.2", minorIncrementConfig);
fixture.BranchTo("feature/foo4", "foo4");
fixture.MakeACommit("5 +semver: major");
fixture.AssertFullSemver("2.0.0-foo4.1", minorIncrementConfig);
fixture.Checkout("master");
fixture.MergeNoFF("feature/foo4");
fixture.AssertFullSemver("2.0.0", config);
// We should evaluate any commits not included in merge commit calculations for direct commit/push or squash to merge commits
fixture.MakeACommit("6 +semver: major");
fixture.AssertFullSemver("3.0.0", minorIncrementConfig);
fixture.MakeACommit("7");
fixture.AssertFullSemver("3.1.0", minorIncrementConfig);
fixture.MakeACommit("8 +semver: patch");
fixture.AssertFullSemver("3.1.1", minorIncrementConfig);
// Finally verify that the merge commits still function properly
fixture.BranchTo("feature/foo5", "foo5");
fixture.MakeACommit("9 +semver: patch");
fixture.AssertFullSemver("3.1.2-foo5.1", minorIncrementConfig);
fixture.Checkout("master");
fixture.MergeNoFF("feature/foo5");
fixture.AssertFullSemver("3.1.2", minorIncrementConfig);
// One more direct commit for good measure
fixture.MakeACommit("10 +semver: patch");
fixture.AssertFullSemver("3.1.3", minorIncrementConfig);
// And we can commit without bumping semver
fixture.MakeACommit("11 +semver: none");
fixture.AssertFullSemver("3.1.3", minorIncrementConfig);
Console.WriteLine(fixture.SequenceDiagram.GetDiagram());
}
}
internal static class CommitExtensions
{
public static void MakeACommit(this RepositoryFixtureBase fixture, string commitMsg)
{
fixture.Repository.MakeACommit(commitMsg);
var diagramBuilder = (StringBuilder)typeof(SequenceDiagram)
.GetField("_diagramBuilder", BindingFlags.Instance | BindingFlags.NonPublic)
?.GetValue(fixture.SequenceDiagram);
string GetParticipant(string participant) =>
(string)typeof(SequenceDiagram).GetMethod("GetParticipant", BindingFlags.Instance | BindingFlags.NonPublic)
?.Invoke(fixture.SequenceDiagram, new object[]
{
participant
});
diagramBuilder.AppendLineFormat("{0} -> {0}: Commit '{1}'", GetParticipant(fixture.Repository.Head.FriendlyName),
commitMsg);
}
}

@FISHMANPET
Copy link
Contributor Author

None of the Mainline tests include Next-Version, which seems to be the source of the problem. I've written failing tests and opened a PR, and I'll keep looking over the code to see if I can find out what's happening.

@asbjornu asbjornu added this to the 5.5.0 milestone Jul 14, 2020
@arturcic
Copy link
Member

🎉 This issue has been resolved in version 5.5.0 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

@FISHMANPET FISHMANPET changed the title [Docs] How to start using GitVersion in a new project? [Bug] Mainline mode not properly using next-version Oct 27, 2020
@FISHMANPET
Copy link
Contributor Author

A small thing, but I never updated the title of this to reflect that it was actually a bug rather than a documentation issue, I've updated the title to more accurately describe the actual bug found. If you want to move this under "Bug" rather than "Documentation" in the release notes, that would be more accurate, but it's a small thing and I don't mind either way

@arturcic
Copy link
Member

I think we keep it like this

@asbjornu
Copy link
Member

Those particularly interested can always click from the release notes to the particular issue and get the right title, so I agree with @arturcic that this is fine as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants