Skip to content

[Bug] GitVersion mainline always returns latest version based on master branch history, even if building for an older commit #3206

@esimkowitz

Description

@esimkowitz

Describe the bug
My team's build agents sometimes slow down, meaning that new commits are checked into our main branch before old ones have been built. I'm noticing that when GitVersion runs (in separate pipeline runs) for these two backed-up commits, it is applying the same version to both commits.

Expected Behavior

I expect that when GitVersion mainline runs for a specific commit hash, it will generate the version for that hash and not for the latest commit, as it appears to be doing.

Actual Behavior

GitVersion mainline generates the commit for the latest commit hash, even if the commit that is checked out in the build agent (or locally) is older than the latest.

Possible Fix

MainlineVersionCalculator.IncrementForEachCommit should stop at the current reference hash, rather than run for all direct commits on the target master branch.

Steps to Reproduce

Run GitVersion with mainline configuration for the head of the master branch, record the version returned. Then, switch your commit to the next-oldest commit in the branch. You should see that the same version is produced.

Context

In our case, we error out a build if the same version is generated for two commits as it will cause conflicts in our container image tags. While this does not necessarily cause later builds to fail, since we tag the commit after a successful build providing a new base for versioning, it does cause our build pipelines to be flaky when handling commits in rapid succession.

Your Environment

Azure DevOps YAML pipelines and .NET .

  • Version Used: 5.5.1, also reproduced in 5.10.3
  • Operating System and version (Windows 10, Ubuntu 18.04): Ubuntu 22.04 and Windows 11
  • Link to your project: Not publicly available
  • Link to your CI build (if appropriate): Not publicly available

Here's the output from gitversion showing it using the latest commit, instead of the current commit to calculate the version:

INFO [09/23/22 9:53:15:59] Found multiple base versions which will produce the same SemVer (1.1.73), taking oldest source for commit counting (Git tag '1.1.72')
    INFO [09/23/22 9:53:15:59] Base version used: Git tag '1.1.72': 1.1.72 with commit count source ae487caac07dafa44d5396bdeda9f1e0fd84d1c1
  INFO [09/23/22 9:53:15:59] End: Calculating base versions (Took: 767.63ms)   
  INFO [09/23/22 9:53:15:60] Begin: Using mainline development mode to calculate current version
    INFO [09/23/22 9:53:15:69] Found possible mainline branches: xxx/test-main
    INFO [09/23/22 9:53:15:73] Mainline for current branch is xxx/test-main
    INFO [09/23/22 9:53:15:74] Direct commit on master 5ac034636007d74195e9f625282f8e1d29b99895 incremented base versions Patch, now 1.1.73
    INFO [09/23/22 9:53:15:74] Direct commit on master 4ecd4ec06985ff50af0f878d7700b1a9af408f1d incremented base versions Patch, now 1.1.74
    INFO [09/23/22 9:53:15:74] Direct commit on master 97d6e4faee6586b2518ae3f95b41407692b76f2f incremented base versions Patch, now 1.1.75
    INFO [09/23/22 9:53:15:74] 2 commits found between ae487caac07dafa44d5396bdeda9f1e0fd84d1c1 and 4ecd4ec06985ff50af0f878d7700b1a9af408f1d

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