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.
https://aleksandr-m.github.io/gitflow-maven-plugin/
Apache License 2.0
494 stars 182 forks source link

Conflict handling #366

Closed AdrienHorgnies closed 1 year ago

AdrienHorgnies commented 1 year ago

Hi,

Using any finish flow that involves merging, the plugin can crash due to git conflicts. It's mainly a problem for release-finish, which I will focus on in this issue.

As far as I understand, it's currently not possible to skip merging the commit done on the release branch. Depending on the configuration, one of the three following reference is merged:

So if there's a git conflict between the release branch and develop, it's not possible to use release-finish before manually solving the conflict, and it's blocking the release-finish from finishing.

Most of the time, I don't have the option to delay the release, and I basically reproduce the effect of the release-finish goal minus the merge into develop.

Is there something I'm missing ?

I'd like to suggest and implement (myself) one of the following :

Any of these three options would allow the developer to try the goal once, fail, then retry without the conflicting merge.

AdrienHorgnies commented 1 year ago

Related to #352 .

aleksandr-m commented 1 year ago

Give an option to skip merging into develop

Something like that should be implemented to support protected branches and opening PR-s - see #363.

Give an option to not crash on merge conflict, and simply give up merging.

We still need to report merge conflicts to user and somehow handle pushing, tagging, branch deletion, etc.

Give an option to not crash on merge conflict, and create a branch that the developer must manually merge.

Can you explain it further?

AdrienHorgnies commented 1 year ago

Give an option to skip merging into develop

See PR #368 for the option (only skipping merge, not the part about creating a PR).

We still need to report merge conflicts to user

True. How would we do that ? It should be something that a CI can easily pick up to assign the build / stage a corresponding status. So... An exit status ? A text file ? A local git branch ? A remote git branch ? I think I prefer the remote git branch, see next point.

Give an option to not crash on merge conflict, and create a branch that the developer must manually merge.

  1. The plugin tries to merge the reference X (release, tag or master depending on the options) into develop.
  2. It fails
  3. It aborts the merge
  4. It creates a branch Y that reference the current HEAD of X
  5. It pushes branch Y along whatever reference it must push
  6. It somehow reports that the developer should merge branch Y into develop. The branch can be considered enough, given a special name, any decent CI will pick it up and be able to notify the developer (either by manually checking the existence of the branch during the build that ran the plugin, or as a job picks up the new branch and triggers a build on it). Or it could create a PR (and it joins the idea of #363 but for develop).

An alternative could be :

  1. The plugin tries to merge the reference X (release, tag or master depending on the options) into develop.
  2. It fails
  3. It aborts the merge
  4. It creates a branch Y that reference the current HEAD of X
  5. It tries to merge develop into Y
  6. It fails (theses are the same two commits as during step 2, just different branches)
  7. It commits the conflicts as is
  8. It pushes branch Y along whatever reference it must push
  9. It somehow reports that the developer should merge branch Y into develop. Though, the newly created git branch is something that any decent CI should pick up, so it could be considered enough ? Or it could create the PR.

We could try to make these solutions generic to any merge conflict, implement several of them of offer them as conflict handling strategies the plugin user could use from. Though in some cases, the plugin makes two merges sequentially, so if the first merge fail, the plugin should fail no matter what. Anyway, most of the time, it's the merge into develop that will fail. A merge into master should never fail (but it can, so the plugin should crash and not try to handle the conflict).

sriram0721 commented 1 year ago

Hello,

Can we use <skipMergeDevBranch> to our pom.xml for not merging to develop directly now. Is the PR merged ? Super excited to use this feature

sriram0721 commented 1 year ago

can we have a post-release branch (an intermediate branch) to handle merge conflict. After finish goal, once main is merged, it will create an intermediate branch and creates a MR to develop. The developers can merge the commit to develop upon resolving conflicts ? @aleksandr-m @AdrienHorgnies

aleksandr-m commented 1 year ago

The skipReleaseMergeDevBranch parameter added in 401c69238538fcdbe6c9b4239118b7318b773437