Skip to content

Commit d87c44f

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

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

git-branch-linearity.sh

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,38 @@ 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+
echo "GITHUB_HEAD_REF: $GITHUB_HEAD_REF"
13+
echo "1: $(git rev-parse $GITHUB_HEAD_REF)"
14+
echo "2: $(git rev-parse origin/$GITHUB_HEAD_REF)"
15+
echo "3: $(git rev-parse refs/heads/$GITHUB_HEAD_REF)"
16+
echo "4: $(git rev-parse refs/heads/origin/$GITHUB_HEAD_REF)"
17+
git fetch --no-tags --depth=1 origin "$GITHUB_HEAD_REF"
18+
echo "5: $(git rev-parse $GITHUB_HEAD_REF)"
19+
echo "6: $(git rev-parse origin/$GITHUB_HEAD_REF)"
20+
echo "7: $(git rev-parse refs/heads/$GITHUB_HEAD_REF)"
21+
echo "8: $(git rev-parse refs/heads/origin/$GITHUB_HEAD_REF)"
22+
echo "9: $(git rev-parse FETCH_HEAD)"
23+
tip="$(git rev-parse FETCH_HEAD)"
24+
echo "Tip: $tip"
25+
else
26+
tip="HEAD"
27+
fi
28+
29+
out=$(git log origin/${TARGET_BRANCH}..${tip} --merges --oneline)
1030
exit_status=$?
31+
1132
if [ -n "$out" ]
1233
then
1334
echo "Please rebase your branch" >&2
1435
echo "If your branch or its base branch is a release branch then ignore this error" >&2
15-
echo "\nMerge commit(s):" >&2
36+
echo >&2
37+
echo "Merge commit(s):" >&2
1638
echo "$out" >&2
1739
# Disclaimer: current version of the check doesn't work well with release branches
1840
exit_status=1
1941
fi
20-
21-
exit ${exit_status}
42+
exit 1
43+
#exit ${exit_status}

0 commit comments

Comments
 (0)