From cbfbd4a6207f840fa4bf2eb7271df6347fb235f3 Mon Sep 17 00:00:00 2001 From: Daniel Halmschlager Date: Fri, 15 Aug 2025 07:11:47 +0200 Subject: [PATCH] chore: ignore PR merge commits to target branch at tip of history --- git-branch-linearity.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/git-branch-linearity.sh b/git-branch-linearity.sh index cd310d5..3625317 100755 --- a/git-branch-linearity.sh +++ b/git-branch-linearity.sh @@ -4,18 +4,28 @@ TARGET_BRANCH="${1:-main}" echo "Target branch: $TARGET_BRANCH" -git fetch origin $TARGET_BRANCH 2> /dev/null +git fetch --no-tags --depth=1 origin $TARGET_BRANCH 2> /dev/null +target_sha=$(git rev-parse origin/${TARGET_BRANCH}) -out=$(git log origin/${TARGET_BRANCH}..HEAD --merges --oneline) +# If in a github PR, base from tip of branch, not the merge commit +if [ -n "$GITHUB_HEAD_REF" ]; then + git fetch --no-tags --shallow-exclude="$target_sha" origin "$GITHUB_HEAD_REF" 2> /dev/null + tip=$(git rev-parse origin/$GITHUB_HEAD_REF) +else + tip="HEAD" +fi + +out=$(git log ${target_sha}..${tip} --merges --oneline) exit_status=$? + if [ -n "$out" ] then echo "Please rebase your branch" >&2 echo "If your branch or its base branch is a release branch then ignore this error" >&2 - echo "\nMerge commit(s):" >&2 + echo >&2 + echo "Merge commit(s):" >&2 echo "$out" >&2 # Disclaimer: current version of the check doesn't work well with release branches exit_status=1 fi - exit ${exit_status}