Skip to content

[IMPROVEMENT]: Topological commit sort causes issues when master is merged into a feature branch #4347

@dauthleikr

Description

@dauthleikr

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

GitVersion package

GitVersion.Tool

GitVersion version

6.0.2+Branch.main.Sha.30211316bc16e481dc440baae39ff904c4fa4966

Operating system

Windows

What are you seeing?

Consider the following commit graph, where green is a feature branch, and pink is master.
Image

  • The bottom-most pink square on the image is a version source (commit is tagged with a version, 1.0.0)
  • The green commit below the blue (selected) line contains a bump message

Configuration:
The idea of this configuration is as follows:

  1. Developers can not commit on master
  2. Merges into master trigger a pipeline, which builds, tests, and publishes a build, and creates a tag on the commit, which acts as a version source
  3. Feature branches are created from master
  4. Bump messages are created on the feature branch by the developer developing the feature
  5. PR to master
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
tag-prefix: '(?i)REDACTEDPRODUCTNAME\/'
version-in-branch-pattern: '\s?REDACTEDPRODUCTNAME:?\s?(?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*'
major-version-bump-message: '\+(sem)?ver\s?REDACTEDPRODUCTNAME[:\s_\/]*(breaking|major)'
minor-version-bump-message: '\+(sem)?ver\s?REDACTEDPRODUCTNAME[:\s_\/]*(feature|minor)'
patch-version-bump-message: '\+(sem)?ver\s?REDACTEDPRODUCTNAME[:\s_\/]*(fix|patch)'
no-bump-message: '\+semver\s?REDACTEDPRODUCTNAME:\s?(none|skip)'
tag-pre-release-weight: 60000
commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
strategies:
  - Fallback
  - ConfiguredNextVersion
  - MergeMessage
  - TaggedCommit
branches:
  master:
    mode: ManualDeployment
    label: ""
    increment: None
    prevent-increment:
      of-merged-branch: true
    track-merge-target: false
    track-merge-message: true
    regex: ^(?<BranchName>.+)
    source-branches: []
    is-source-branch-for: []
    tracks-release-branches: false
    is-release-branch: true
    is-main-branch: true
    pre-release-weight: 55000
  feature:
    mode: ContinuousDelivery
    label: "{BranchName}"
    increment: None
    prevent-increment:
      when-current-commit-tagged: false
    track-merge-message: false
    regex: ^(?<BranchName>.+)
    source-branches: []
    is-source-branch-for: []
    is-main-branch: false
    pre-release-weight: 30000
  pull-request:
    mode: ContinuousDelivery
    label: PullRequest
    increment: None
    prevent-increment:
      of-merged-branch: true
      when-current-commit-tagged: false
    label-number-pattern: '[/-](?<number>\d+)'
    track-merge-message: true
    regex: ^(pull|pull\-requests|pr)[/-]
    source-branches:
      - master
      - feature
    is-source-branch-for: []
    pre-release-weight: 30000
  unknown:
    mode: ManualDeployment
    label: "{BranchName}unk"
    increment: Inherit
    prevent-increment:
      when-current-commit-tagged: true
    regex: (?<BranchName>.+)
    source-branches:
      - master
      - feature
    is-source-branch-for: []
    is-main-branch: false
ignore:
  sha: []
mode: ManualDeployment
label: "{BranchName}"
increment: Inherit
prevent-increment:
  of-merged-branch: false
  when-branch-merged: false
  when-current-commit-tagged: true
track-merge-target: false
track-merge-message: true
commit-message-incrementing: Enabled
regex: ""
source-branches: []
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: false
workflow: '' # Do not use a default template

Even though the feature branch contains a bump message, it is not respected, because a merge from master into the feature branch happened, after the bump message was created. Without the merge, everything is fine.
We want merges from master into feature branches to be possible, without the bump message getting lost.
Example:

  • I create a feature branch based on 1.0.0
  • I develop my feature, create a bump message for "feature" -> 1.1.0
  • My team merges a new major feature into master -> master is 2.0.0
  • I merge master in my feature branch. I expect: 2.1.0. I get: 2.0.0
  • I need to create my bump message again <- I do not want to do this

What is expected?

Somehow consider the bump messages from before the merge of master into my feature branch. The bump version commit is not discoverable from the head of master, but it is discoverable from the head of my feature branch, so I feel like it should be possible to implement.

The issue can also be "fixed" by changing the filter in GetCommitsReacheableFromHead to CommitSortStrategies.Topological | CommitSortStrategies.Time | CommitSortStrategies.Reverse, or CommitSortStrategies.Time | CommitSortStrategies.Reverse (which seems to be the default for git log), but is not optimal for obvious reasons.

Steps to Reproduce

Please recreate the commit graph shown above. Sorry for the heavy redaction :(

RepositoryFixture Test

No response

Output log or link to your CI build (if appropriate).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions