git-commit-id-maven-plugin icon indicating copy to clipboard operation
git-commit-id-maven-plugin copied to clipboard

Version with branch name if not on master

Open torsten-github opened this issue 5 years ago • 2 comments

Describe your idea

A proeprty which displays the feature branch name. It's empty if on master. A leading dash is needed to use it as postfix.

Expected Behavior

Default Release is mostly: artifact-v1.0.0 Release on feature branch is now: artifact-v1.0.0-7 Better would be: artifact-v1.0.0-7-my-new-featuer

<version>${artifact-id}-${git.commit.id.describe-short}${git.feature.dashed}</version>

Additional context

Please also have a look at this tool, doing the same in the MS world: https://gitversion.net/docs/more-info/variables

torsten-github avatar Jan 21 '20 15:01 torsten-github

Hello, thanks for opening your issue here. That sounds like a very specific property and the properties linked in https://gitversion.net/docs/more-info/variables are also very specific to the branch or tagging pattern used. Not everyone uses or follows that pattern. However you still probability can get away by using the replacementProperties:

<replacementProperties>
  <!--
      example:
      apply replacement only to the specific property git.branch and replace '/' with '-'
      see also [issue 138](https://github.com/git-commit-id/maven-git-commit-id-plugin/issues/138)
  -->
  <replacementProperty>
    <property>git.branch</property>
    <propertyOutputSuffix>something</propertyOutputSuffix>
    <token>^([^\/]*)\/([^\/]*)$</token>
    <value>$1-$2</value>
    <regex>true</regex>
    <forceValueEvaluation>false</forceValueEvaluation>
  </replacementProperty>
</replacementProperties>

When looking at the https://gitversion.net/docs/more-info/variables it seems that all variables can be generated from InformationalVersion using regex expressions following a similar pattern.

TheSnoozer avatar Jan 21 '20 19:01 TheSnoozer

Thanks for the prompt feedback. That works.

Didn't know about the <replacementPrperty>. With them I managed to build the desired properties:

  • git.branch.feat // empty if master
  • git.branch.feat.dashed // prefixed with a dash if not empty

-- By the way:

I realize it's not that easy to build a semantic compatible version (https://semver.org/) A tagged 1.2.3 with an additional commit would need to increment the patch part like: 1.2.4+1 On a branch: 1.2.4-feature-xyz+1

https://gitversion.net/docs/git-branching-strategies/githubflow-examples

torsten-github avatar Jan 30 '20 10:01 torsten-github