Skip to content

Gitversion calculated wrong version number on a recursive merge  #2302

@cuichenli

Description

@cuichenli

Describe the bug
The version number is incorrect on a recursive merge commit. As shown in the following image, the version calculated in the normal commit (dummy) is 19.2.9, which is as expected. After we merge from develop branch, the version calculated would become 19.2.7.
image

Expected Behavior

The version calculated on merge commit should be 19.2.9

Actual Behavior

The version calculated on merge commit is 19.2.7

Possible Fix

var parents = currentCommit.Parents.ToArray();
var branches = repositoryMetadataProvider.GetBranchesForCommit(parents[1]);
if (branches.Count == 1)
{
var branch = branches[0];
excludedBranches = new[]
{
currentBranch,
branch
};
currentBranch = branch;
}
else if (branches.Count > 1)
{
currentBranch = branches.FirstOrDefault(b => b.NameWithoutRemote() == "master") ?? branches.First();
}
else
{
var possibleTargetBranches = repositoryMetadataProvider.GetBranchesForCommit(parents[0]);
if (possibleTargetBranches.Count > 1)
{
currentBranch = possibleTargetBranches.FirstOrDefault(b => b.NameWithoutRemote() == "master") ?? possibleTargetBranches.First();
}
else
{
currentBranch = possibleTargetBranches.FirstOrDefault() ?? currentBranch;
}
}
log.Info("HEAD is merge commit, this is likely a pull request using " + currentBranch.FriendlyName + " as base");

Not sure if my understanding is correct, but L182 is suspicious to me. In my case, the currentBranch is changed to develop from my local feature branch, not sure what is the reason for this change.

Steps to Reproduce

Sorry I can not share my repo here, but the similar behaviour can be reproduced with the gitversion repo.

# Create a test branch based on previous commit 
git checkout -b test-branch d7abddbd4b51045cc33947bfe
gitversion # 5.3.5

# Make some dummy changes 
git commit -am "Dummy changes"
gitversion # 5.3.5


git merge master 
gitversion # 5.4.0

Your Environment

Windows

  • Version Used:
    Windows 10, GitVersion v5.3.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions