Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip merge commits in suggestion #397

Merged
merged 4 commits into from
Nov 7, 2023

Conversation

korthout
Copy link
Owner

@korthout korthout commented Nov 7, 2023

This makes several small improvements to the local cherry-picking suggestions:

  • No longer suggest git merge-base to determine the commits to cherry-pick
  • No longer suggest a commit range for cherry-picking but rather be explicit about the commits
  • Exclude any skipped merge commits from the commits to cherry-pick
  • Use git switch --create rather than git checkout --branch as it may be easier to understand

Resolves #395

Note
I'm making the assumption that all users of backport-action are at least on Git version 2.23 (16 Aug 2019). If anyone prefers the git checkout --branch command, please let me know, so I can prioritize #305

Example

Before this pull request

git fetch origin case3-conflict-backport-target
git worktree add -d .worktree/backport-220-to-case3-conflict-backport-target origin/case3-conflict-backport-target
cd .worktree/backport-220-to-case3-conflict-backport-target
git checkout -b backport-220-to-case3-conflict-backport-target
ancref=$(git merge-base 58bc5128788a56318e3a054b7deecd106a93a1ec b3ae1ae21f2ac6bacb9cca61eba5822e4bb05b37)
git cherry-pick -x $ancref..b3ae1ae21f2ac6bacb9cca61eba5822e4bb05b37

After this pull request

git fetch origin case3-conflict-backport-target
git worktree add -d .worktree/backport-220-to-case3-conflict-backport-target origin/case3-conflict-backport-target
cd .worktree/backport-220-to-case3-conflict-backport-target
git switch --create backport-220-to-case3-conflict-backport-target
git cherry-pick -x b3ae1ae21f2ac6bacb9cca61eba5822e4bb05b37

This compose for backport script failure method was a remnant from when
this action used a shell script to perform the git commands. Most
reasons were dead code.
The manual instructions still suggested to determine the commits to
cherry-pick by determining the common ancestor (merge-base) of the head
and base refs, first. However, this way has been abandoned for quite
some time now. This especially became a problem now that merge commits
can be skipped, meaning that the suggestion no longer produced a
reliable result.

Instead, we can simply suggest the same as the action does. It knows
exactly which commits to cherry-pick.
When the cherr-picking failed, it's very likely that there are
conflicts. We should instruct the user to cherry-pick locally and
resolve any conflicts.
The switch command has been around for 4 years now, and while still
marked as experimental, I think it's fine to "switch" to it in the
suggestion for local cherry-picking. It's unlikely that users are using
such old git versions that it doesn't support git switch --create.
@korthout korthout force-pushed the 395-skip-merge-commits-in-suggestion branch from 30f2a3e to 19a4042 Compare November 7, 2023 20:57
@korthout korthout merged commit 487faf2 into main Nov 7, 2023
2 checks passed
@korthout korthout deleted the 395-skip-merge-commits-in-suggestion branch November 7, 2023 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Instructions for manually cherry-picking are incorrect as they do not skip merge commits
1 participant