Verified Commit 48723225 authored by Karel Koci's avatar Karel Koci 🤘 Committed by Josef Schlehofer
Browse files

githooks: fix push reject when hbl is directly based on hbk

The issue this fixes is that git reports same commit as being ancestor
of itself. It kind of makes sense but it breaks check if branch is based
on hbk or hbl or hbd. In such case for example the common base between
hbl and target branch and hbk and target branch is the same.

This changes the logic. Because git merge-base does effectively the
operation of 'less than or equal' we have to swap compare order and
negate the result. This way we get effectively the 'less than'
operation.
parent c06fe222
Pipeline #79191 passed with stages
in 12 minutes and 10 seconds
......@@ -13,8 +13,8 @@ compare_ancestors() {
correct_base="$(git merge-base "$local_hash" "$2")"
invalid_base_a="$(git merge-base "$local_hash" "$3")"
invalid_base_b="$(git merge-base "$local_hash" "$4")"
git merge-base --is-ancestor "$correct_base" "$invalid_base_a" \
&& git merge-base --is-ancestor "$correct_base" "$invalid_base_b"
git merge-base --is-ancestor "$invalid_base_a" "$correct_base" \
|| git merge-base --is-ancestor "$invalid_base_b" "$correct_base"
}
......@@ -49,19 +49,19 @@ while read -r local_ref local_sha1 remote_ref remote_sha1; do
push_hbd="$local_sha1"
;;
hotfix/*)
if compare_ancestors "$local_sha1" hbk hbl hbd; then
if ! compare_ancestors "$local_sha1" hbk hbl hbd; then
echo "Reference has invalid ancestor, please base it on top of hbk: $local_ref" >&2
exit 1
fi
;;
feature/*|bugfix/*|refactor/*|hack/*)
if compare_ancestors "$local_sha1" hbl hbk hbd; then
if ! compare_ancestors "$local_sha1" hbl hbk hbd; then
echo "Reference has invalid ancestor, please base it on top of hbl: $local_ref" >&2
exit 1
fi
;;
majorfeature/*|fix/*|majorrefactor/*|majorhack/*)
if compare_ancestors "$local_sha1" hbd hbk hbl; then
if ! compare_ancestors "$local_sha1" hbd hbk hbl; then
echo "Reference has invalid ancestor, please base it on top of hbd: $local_ref" >&2
exit 1
fi
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment