Skip to content

Commit

Permalink
Fix wrong suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
infinisil committed Oct 1, 2024
1 parent c1c4f53 commit efeb298
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ci/request-reviews/verify-base-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,24 @@ for branch in "${developmentBranches[@]}"; do
echo "Checking for extra commits from branch $branch" >&2

# The first ancestor of the PR head that already exists in the other branch
mergeBase=$(git -C "$localRepo" merge-base "$headRef" "$branch")
alreadyMerged=$(git -C "$localRepo" merge-base "$headRef" "$branch")

# The number of commits that are reachable from the PR head, not reachable from the PRs base branch
# (up to here this would be the number of commits in the PR itself),
# but that are _also_ in the development branch we're testing against.
# So, in other words, the number of commits that the PR includes from other development branches
count=$(git -C "$localRepo" rev-list --count "$mergeBase" ^"$baseBranch")
count=$(git -C "$localRepo" rev-list --count "$alreadyMerged" ^"$baseBranch")

if (( count != 0 )); then
mergeBase=$(git -C "$localRepo" merge-base "$headRef" "$baseBranch")

echo -en "\e[31m"
echo "This PR's base branch is set to $baseBranch, but $count already-merged commits are included from the $branch branch."
echo "To remedy this, first make sure you know the target branch for your changes: https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#branch-conventions"
echo "- If the changes should go to the $branch branch instead, change the base branch accordingly:"
echo " https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-base-branch-of-a-pull-request"
echo "- If the changes should really go to the $baseBranch branch, rebase your PR on top of the merge base with the $branch branch:"
echo " git rebase --onto $mergeBase && git push --force-with-lease"
echo " git rebase --onto $mergeBase $alreadyMerged && git push --force-with-lease"
echo -en "\e[0m"
exit 1
fi
Expand Down

0 comments on commit efeb298

Please sign in to comment.