GitTools / GitVersion

From git log to SemVer in no time
https://gitversion.net/docs/
MIT License
2.87k stars 654 forks source link

[ISSUE]: Prevent auto increment per commit for master #4207

Closed prostakov closed 2 months ago

prostakov commented 2 months ago

Prerequisites

GitVersion package

GitVersion.Tool

GitVersion version

6.0.2

Operating system

macOS

What are you seeing?

I currently have following config:

assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatchTag
assembly-informational-format: '{InformationalVersion}'
mode: ContinuousDelivery
increment: Inherit
commit-date-format: 'yyyy-MM-dd'
merge-message-formats: {}
branches:
  master:
    regex: ^master$
    mode: ContinuousDelivery
    label: ''
    increment: None
    track-merge-target: false
    tracks-release-branches: false
    is-release-branch: false
    prevent-increment:
      of-merged-branch: false
      when-current-commit-tagged: false

And I currently have following situation in master branch:

- Commit 1 = 1.0.0 (tagged 1.0.0)
- Commit 2 = 1.0.1-1
- Commit 3 = 1.0.1-2
- Commit 4 = 1.0.1-3

The patch value gets automatically incremented once, on first commit after tagged commit. And since I set configuration on master: increment: None, this was not expected.

What is expected?

The expected behavior would be like this:

- Commit 1 = 1.0.0 (tagged 1.0.0)
- Commit 2 = 1.0.0-1
- Commit 3 = 1.0.0-2
- Commit 4 = 1.0.0-3

This way the major-minor-patch gets fully controlled by release tag.

Steps to Reproduce

Tags commit with version, create extra 3 commits.

RepositoryFixture Test

No response

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

No response

HHobeck commented 2 months ago

Please keep in mind that you are inheriting from the default workflow which is in your example the GitFlow/v1 workflow. Because you choice master instead of main, you are not overriding but defining a second definition for the master branch:

branches:
  main:
    regex: ^master$|^main$
    ...
  master:
    regex: ^master$
    ...
  ...

Saying: First comes first servers.

To the workflow property you will find the following documentation:

workflow The base template of the configuration to use. Possible values are GitFlow/v1 or GitHubFlow/v1. Defaults to GitFlow/v1 if not set. To create a configuration from scratch without using a base template, please specify an empty string.

What you want is probably to define your configuration from scratch:

workflow: ''
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
tag-prefix: '[vV]?'
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
...

Happy Branching!

prostakov commented 2 months ago

Thank you very much.

It works. Had to add the strategies: [TaggedCommit] though.

The final working configuration snippet looks like following:

workflow: ''
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatchTag
assembly-informational-format: '{InformationalVersion}'
mode: ContinuousDelivery
increment: None
tag-prefix: '[v]'
commit-message-incrementing: Disabled
commit-date-format: 'yyyy-MM-dd'
tag-pre-release-weight: 60000
strategies: [TaggedCommit]
branches:
  master:
    regex: ^master$
    label: ''
    increment: None
    track-merge-target: false
    tracks-release-branches: false
    is-release-branch: false
  release:
    regex: ^release?[/-]
    label: beta
    increment: None
    track-merge-target: true
    tracks-release-branches: true
    is-release-branch: true