aleksandr-m / gitflow-maven-plugin

The Git-Flow Maven Plugin supports various Git workflows, including GitFlow and GitHub Flow. This plugin runs Git and Maven commands from the command line.

Home Page:https://aleksandr-m.github.io/gitflow-maven-plugin/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Help needed: "Hotfix branch with name 'hotfix/1.16.1' doesn't exist. Cannot finish hotfix."

jenslauterbach opened this issue Β· comments

Hi πŸ‘‹ ,

I am trying to integrate hotfixes into my flow in Gitlab (non-interactive, batch mode). When I finish the hotfix from the hotfix branch itself, it get the following error:

Hotfix branch with name 'hotfix/1.16.1' doesn't exist. Cannot finish hotfix.

This is odd, since the command is run from the very same branch.


The general process is as follows:

  1. User starts hotfix from production branch
  2. User finishes hotfix from hotfix branch

To start the hotfix from production branch, the following command is used:

mvn \
    --batch-mode \
    gitflow:hotfix-start \
    -DuseSnapshotInHotfix=true \
    -DpushRemote=true \
    -DhotfixVersionDigitToIncrement=2

To finish the hotfix from the hotfix branch, the following command is used:

mvn \
    --batch-mode \
    gitflow:hotfix-finish \
    -DuseSnapshotInHotfix=true \
    -DpushRemote=true \
    -DhotfixVersionDigitToIncrement=2 \
    -DhotfixBranch=$CI_COMMIT_REF_NAME

Note, the usage of the hotfixBranch option and that the variable $CI_COMMIT_REF_NAME is replaced with the full branch name (e.g. hotfix/1.16.1).


Version used is 1.18.0.

Configuration:

<configuration>
    <installProject>false</installProject>
    <verbose>true</verbose>

    <gitFlowConfig>
        <productionBranch>main</productionBranch>
        <developmentBranch>develop</developmentBranch>
    </gitFlowConfig>
</configuration>

I was not able to figure out what I am doing wrong, so I would kindly ask for some help.

@jenslauterbach Can you run git show-ref and show the output?

@aleksandr-m I have run the command in the Gitlab pipeline and got the following output:

4f5dfc4ca01dbf25db9bea283ac5d46dc76ebe19 refs/pipelines/13907985
4f5dfc4ca01dbf25db9bea283ac5d46dc76ebe19 refs/remotes/origin/hotfix/1.16.1
f41e4a85be183e784e5f7cdaf6433e98be20565a refs/tags/1.11.0
245e8f7663f7004340ac0e41fc83e509d64356e0 refs/tags/1.11.1
bc572e55f5c095acdaf1152109ab6114a4132a53 refs/tags/1.11.2
6cbcf247adfe6bc520c4cddc9acb4db87de6438c refs/tags/1.11.3-SNAPSHOT
c9fc19a6c101851d49e6abf0ee7a51b8418959a1 refs/tags/1.11.4-SNAPSHOT
f76ad2413ebca51a5221f48bb4a2cf52d618c7f8 refs/tags/1.13.0
f9b503242710dc21dd7a85572e24be1559385d15 refs/tags/1.13.1
6c17e6900733384b86269f1504cfece7b47009a2 refs/tags/1.14.0
7c64e778b754139cd0826f6dc3456caed79ace34 refs/tags/1.16.0

As I said before, the command is run on the branch itself (hotfix/1.16.1). Interestingly, git status and git branch do not reflect that (as it would locally). I am not 100% sure if that's an issue:

$ git branch
* (HEAD detached at 4f5dfc4)
$ git status
HEAD detached at 4f5dfc4

@jenslauterbach Yes, that is it. Somehow there is a detached head, not a hotfix branch.

@jenslauterbach Yes, that is it. Somehow there is a detached head, not a hotfix branch.

I'll try to figure this out and add an update here.

commented

We are experiencing the same issue when running the plugin from a Jenkins CI environment. All other goals (release-start, release-finish and hotfix-start) are working fine in the Jenkins.
Interestingly, the same command does not have any problem when run on a developer machine:
mvn -B com.amashchenko.maven.plugin:gitflow-maven-plugin:hotfix-finish -Prelease -DpushRemote=true -DskipTestProject=true -DhotfixVersion=2022.04-2.0

Also with version 1.18.0. The following configuration is defined in the pom.xml:

<useSnapshotInRelease>true</useSnapshotInRelease>
<useSnapshotInHotfix>true</useSnapshotInHotfix>
<versionsForceUpdate>true</versionsForceUpdate>

In contrast to the OP, the git repository on the Jenkins file systems looks good to me. Both git branch -a and git show-ref show the exact hotfix branch and there is no detached head (abbreviated as other refs are not relevant):

f9a54b0d0488edc9011a7f6dd8e6979a4c5da4a9 refs/heads/master
9b71b200ae43514b500900d96c21f97f53b63d62 refs/remotes/origin/develop
6fda41279cee95f3f76d4bd6539916e9c4a87d6b refs/remotes/origin/hotfix/2022.04-2.0
f9a54b0d0488edc9011a7f6dd8e6979a4c5da4a9 refs/remotes/origin/master
commented

I found out that not the Jenkins is the problem but the checked out branch.
Even locally the goal fails when the working directory is not set to the hotfix branch.

This seems like a bug to me as the plugin should be able to check out any needed branch after a fetch (which it does at later steps of the execution). Also, the release-finish goal has no problem with running from the master branch.
Locally it's easy to just check out the needed branch, but in the Jenkins the Git plugin runs before the hotfix version property is injected to the build.
I should be able to create a workaround for that, but it would be nice to have hotfix-finish behave the same as release-finish in this regard.

@stifm Should be improved in a11b0a3.

@jenslauterbach Seems like not a plugin issue. Feel free to re-open if disagree.