-
Notifications
You must be signed in to change notification settings - Fork 1
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
chore: ignore merge commits to target branch at tip of history #35
Open
halms
wants to merge
1
commit into
main
Choose a base branch
from
chore/ignore-merge-at-tip
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that if the last commit is a merge commit and has the head of the target branch as the left child, you will ignore it (consider it's the GitHub generated one) and check for merge commit in the below commits.
It's not clear to me if this approach works if someone did the same thing in his/her branch that GitHub CI does, i.e. he/she merged the main branch into its development branch, which we also wouldn't want in case of linearity check.
I tried locally and the check worked, but it was because the origin/main commit was the right child of the merge commit and not the left child.
Are you sure testing always the left child will achieve the expected results?
Unfortunately, I was not able to test it in a real PR, I had some difficulties reproducing the issue.
BTW I thought initially to use something more GitHub specific, using for instance the environment variable exported.
The
GITHUB_SHA
contains the tip commit (which will be the merge commit if one was created)and
GITHUB_HEAD_REF
contains the source branch name (and is only defined in PR context)If the 2 don't point to the same thing, we are probably in a GitHub merge commit situation.
Or simpler, if
GITHUB_HEAD_REF
is non-empty, we dogit rev-parse ${GITHUB_HEAD_REF}
to get the tip commit to use.BTW I found this page informative about the process: https://www.kenmuse.com/blog/the-many-shas-of-a-github-pull-request/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I think it will work because locally the left child is the target of the merge (ours) and the right side what is merged into the target (theirs).
A local merge commit will merge main into the current branch, so it will end up on the right.
Whereas GitHub create a new branch from the base commit and merge the pull request branch into it so the origin/main commit will be on the left.
I still think using
GITHUB_HEAD_REF
would be simpler but as you want :-)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took me a while (and needed some calm time) to wholly follow through your points.
I have to say, I did not think at all about any GH-specific variables, only about the git history itself. But what you suggested makes a lot of sense.
So the case you were concerned about is if we have a merge commit from
main
into thedev
branch (what we don't want to allow) at the tip of the history.But this is detected correctly because it has the left and right parent commits inversed.
In any case, yes, I think using the
GITHUB_HEAD_REF
is a good idea here. And ignoring it if it's empty.We could even compare SHAs of
rev-parse $GITHUB_HEAD_REF
andHEAD^
and if they match assume we are in a GH merge commit scenario and start the history check from that SHA?