fix: filtering of changes introduced by merges #864
Closed
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.
Justification
As part of our Prometheus rules repository, we enforce that a branch must be up-to-date with
main
before merging a PR. This typically results in folks mergingmain
into their branch (as opposed to a rebase). However, with currentpint
behavior, that results in commits frommain
being included in the rules files thatpint
looks at since it considers them changed.This results in extraneous evaluation of rules files unrelated to a given PR, but also HTTP 422 responses from GitHub for trying to adding comments to files that aren't changed in a PR.
Explanation
While the '--no-merges' flag excludes merge commits themselves from being included, the commits that they introduced are still included.
This means that -- in Git workflows where people are often merging the latest changes from the main branch into theirs -- the changes from the upstream get included and evaluated, rather than just the files changed within the pull request.
By adding the '--first-parent' flag, it ensures that only commits that have a "first parent" of the current branch will be included.
So, if you merge BranchB into BranchA, and now BranchB's commits will be included when merging BranchA to main, BranchB's commits will still be included in the log.
However, when merging main to BranchA and then merging BranchA to main, the commits that already came from main will be ignored.
I hope this makes sense, but it's hard to explain anything to do with Git in a simple manner lol.