Skip to content

Commit 758be91

Browse files
committed
chore: ignore PR merge commits to target branch at tip of history
1 parent 0bb3d59 commit 758be91

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

git-branch-linearity.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,26 @@ TARGET_BRANCH="${1:-main}"
66
echo "Target branch: $TARGET_BRANCH"
77
git fetch origin $TARGET_BRANCH 2> /dev/null
88

9-
out=$(git log origin/${TARGET_BRANCH}..HEAD --merges --oneline)
9+
10+
# If in a github PR, base from tip of branch, not the merge commit
11+
if [ -n "$GITHUB_HEAD_REF" ]; then
12+
git fetch --no-tags --shallow-exclude="origin/${TARGET_BRANCH}" origin "$GITHUB_HEAD_REF"
13+
tip="$(git rev-parse origin/$GITHUB_HEAD_REF)"
14+
else
15+
tip="HEAD"
16+
fi
17+
18+
out=$(git log origin/${TARGET_BRANCH}..${tip} --merges --oneline)
1019
exit_status=$?
20+
1121
if [ -n "$out" ]
1222
then
1323
echo "Please rebase your branch" >&2
1424
echo "If your branch or its base branch is a release branch then ignore this error" >&2
15-
echo "\nMerge commit(s):" >&2
25+
echo >&2
26+
echo "Merge commit(s):" >&2
1627
echo "$out" >&2
1728
# Disclaimer: current version of the check doesn't work well with release branches
1829
exit_status=1
1930
fi
20-
2131
exit ${exit_status}

0 commit comments

Comments
 (0)