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

mvn gitflow:release-finish triggers error regarding unrelated histories.

4soft-liebig opened this issue · comments

Hi,

I'm using gitflow-maven-plugin with gitlab-ci for release generation. We split the release generation using release-start and release-finish to generate the changelog from the git history automatically in between.

I'm running into a problem when running gitflow:release-finish. According to the git output develop, release-branch, and master are up2date. Nevertheless, I'm getting "refusing to merge unrelated histories" when running the command.

Interestingly, creating releases work the previous releases 0.0.1 to 0.0.14. I'm getting the error when creating the new release 0.0.15.

What do i miss? I'm using gitflow-maven-plugin version 1.18.0.

gitlab-ci configuration:

...
.git_template: &git_setup |
  git remote set-url --push origin "https://oauth2:${GITLAB_TOKEN}@${CI_SERVER_HOST}:8099/${CI_PROJECT_PATH}.git"
  git config user.name ${GITLAB_USER_NAME}
  git config user.email ${GITLAB_USER_EMAIL}

release-start:
  stage: Release
  variables:
    # Clone repository to have a fresh copy of the remote without any changes of a local working copy.
    GIT_STRATEGY: clone
    RELEASE_VERSION: ""
  before_script:
    - *git_setup
  script:
    # Setting RELEASE_VERSION is optional. If not set then version information are set automatically based on patch
    # version via semantic versioning.
    - 'mvn gitflow:release-start -B -DreleaseVersion=$RELEASE_VERSION'
    # Fetch version from maven project to determine corresponding release branch.
    - 'VERSION=$(mvn --non-recursive help:evaluate -Dexpression=project.version -q -DforceStdout)'
    # Generate changelog from last tag to current release-branch commit.
    # When creating changelog for the first time, use "from=<commit-id>&version=..." for proper operation!
    - 'curl --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --data "version=$VERSION&branch=release/$VERSION" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/repository/changelog"'
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
      when: manual

release-finish:
  stage: Release
  variables:
    # Change strategy to git clone, since changelog generation together with additional commits pushed manually to
    # the release branch results in remote being ahead.
    GIT_STRATEGY: clone
  before_script:
    - *git_setup
  script:
    - "mvn gitflow:release-finish"
  only:
    - /^release\/.*$/
  when: manual
...

gitflow-maven-plugin configuration:

...
			<plugin>
				<groupId>com.amashchenko.maven.plugin</groupId>
				<artifactId>gitflow-maven-plugin</artifactId>
				<version>1.18.0</version>
				<configuration>
					<argLine>-Ddocker.skip=true</argLine>
					<installProject>true</installProject>
					<skipTestProject>true</skipTestProject>
					<pushRemote>true</pushRemote>
					<verbose>true</verbose>
				</configuration>
			</plugin>
...

mvn log:

...
1946 [INFO] --- gitflow-maven-plugin:1.18.0:release-finish (default-cli) @ vps-parent ---
7884 [INFO] Checking for uncommitted changes.
7972 [INFO] Fetching remote branch 'origin '.
"origin/release/0.0.15"
8533 [INFO] Creating a new branch 'release/0.0.15' from 'origin/release/0.0.15' and checking it out.
Branch 'release/0.0.15' set up to track remote branch 'release/0.0.15' from 'origin'.
8562 [INFO] Checking out 'release/0.0.15' branch.
Your branch is up to date with 'origin/release/0.0.15'.
8585 [INFO] Checking for SNAPSHOT versions in dependencies.
8629 [INFO] Fetching remote branch 'origin release/0.0.15'.
8843 [INFO] Comparing local branch 'release/0.0.15' with remote 'origin/release/0.0.15'.
0	0
8891 [INFO] Local branch 'develop' doesn't exist. Trying to fetch and check it out from 'origin'.
8892 [INFO] Fetching remote branch 'origin develop'.
9113 [INFO] Creating a new branch 'develop' from 'origin/develop' and checking it out.
Branch 'develop' set up to track remote branch 'develop' from 'origin'.
9136 [INFO] Fetching remote branch 'origin develop'.
9394 [INFO] Comparing local branch 'develop' with remote 'origin/develop'.
0	0
9437 [INFO] Local branch 'master' doesn't exist. Trying to fetch and check it out from 'origin'.
9438 [INFO] Fetching remote branch 'origin master'.
9666 [INFO] Creating a new branch 'master' from 'origin/master' and checking it out.
Branch 'master' set up to track remote branch 'master' from 'origin'.
9693 [INFO] Fetching remote branch 'origin master'.
9918 [INFO] Comparing local branch 'master' with remote 'origin/master'.
0	0
9942 [INFO] Checking out 'release/0.0.15' branch.
Your branch is up to date with 'origin/release/0.0.15'.
9990 [INFO] Checking out 'master' branch.
Your branch is up to date with 'origin/master'.
10015 [INFO] Merging (--no-ff) 'release/0.0.15' branch.
10042 [INFO] ------------------------------------------------------------------------
10042 [INFO] Reactor Summary for vps 0.0.15:
10043 [INFO] 
10044 [INFO] vps ............................ FAILURE [  8.103 s]
10044 [INFO] vps-design ......................................... SKIPPED
10045 [INFO] vps-frontend ....................................... SKIPPED
10045 [INFO] vps-backend ........................................ SKIPPED
10045 [INFO] vps-coverage ....................................... SKIPPED
10045 [INFO] ------------------------------------------------------------------------
10045 [INFO] BUILD FAILURE
10045 [INFO] ------------------------------------------------------------------------
10046 [INFO] Total time:  8.955 s
10047 [INFO] Finished at: 2022-03-31T22:28:39Z
10047 [INFO] ------------------------------------------------------------------------
10049 [ERROR] Failed to execute goal com.amashchenko.maven.plugin:gitflow-maven-plugin:1.18.0:release-finish (default-cli) on project vps-parent: release-finish: fatal: refusing to merge unrelated histories -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.amashchenko.maven.plugin:gitflow-maven-plugin:1.18.0:release-finish (default-cli) on project vps-parent: release-finish
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoFailureException: release-finish
    at com.amashchenko.maven.plugin.gitflow.GitFlowReleaseFinishMojo.execute (GitFlowReleaseFinishMojo.java:392)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoFailureException: fatal: refusing to merge unrelated histories
    at com.amashchenko.maven.plugin.gitflow.AbstractGitFlowMojo.executeCommand (AbstractGitFlowMojo.java:1382)
    at com.amashchenko.maven.plugin.gitflow.AbstractGitFlowMojo.executeGitCommand (AbstractGitFlowMojo.java:1308)
    at com.amashchenko.maven.plugin.gitflow.AbstractGitFlowMojo.gitMerge (AbstractGitFlowMojo.java:855)
    at com.amashchenko.maven.plugin.gitflow.GitFlowReleaseFinishMojo.execute (GitFlowReleaseFinishMojo.java:279)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
10055 [ERROR] 
10055 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
10055 [ERROR] 
10055 [ERROR] For more information about the errors and possible solutions, please read the following articles:
10055 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
...

@4soft-liebig Maybe it is related to origin change with git remote set-url? Can you reproduce this error locally?

@aleksandr-m Hi thanks for the fast response.

I cannot reproduce the error locally. The orgin change on the other side is required, since we add authentication information for accessing the "git server". Interestingly, after creating a release with the plugin locally and pushing it to gitlab the next release could be created on the gitlab instance again. So far I'm investigating into the direction that the cloned repository in gitlab may have a problem due to the fact that the HEADs for different branches are not setup correctly.

@aleksandr-m I'm still getting the error sometimes. git remote set-url is required, so that git/gitflow can push changes to remote, since the original clone does not contain credentials in it's remote definition.
Is there a way to get more information on the error?

Well, you can run git merge directly e.g. w/o plugin, but I doubt there will be more info.

I have exactly the same problem. Do you success to close the problem using release finish command ?

@ari1008: I'm afraid not.

Hi,
I could fix the problem setting gitlab-config variable GIT_DEPTH to 0. gitlab makes use of git clone --depth to improve the performance during checkout, since most git operations do not require the complete repository to be cloned. Standard depth is 20. Sometimes the release-finish operation worked, when the number of commits is less than 20. Sometimes it did not.

Running release-finish locally always succeeded, since the local git clone is complete (i.e., not shallow).

The following setup worked for me:

release-finish:
  stage: Release
  variables:
    # Change strategy to git clone, since changelog generation together with additional commits pushed manually to
    # the release branch results in remote being ahead.
    GIT_STRATEGY: clone
    # Make a full clone. This is required, since otherwise we get an error regarding unrelated merge histories.
    GIT_DEPTH: 0
  before_script:
    - *git_setup
  only:
    - /^release\/.*$/
  when: manual
  script:
    - 'mvn gitflow:release-finish -DskipTestProject=true -DversionDigitToIncrement=1'

@4soft-liebig Thank you for sharing your solution!