refactor(hooks): simplify new branch validation logic
This commit is contained in:
parent
411b4dec84
commit
1d1ddc3ea0
1 changed files with 8 additions and 30 deletions
|
@ -45,37 +45,15 @@ while read -r OLD_REV NEW_REV REF_NAME; do
|
||||||
if [[ "$OLD_REV" = "0000000000000000000000000000000000000000" ]]; then
|
if [[ "$OLD_REV" = "0000000000000000000000000000000000000000" ]]; then
|
||||||
echo -e "${YELLOW}New branch detected: $REF_NAME${NC}"
|
echo -e "${YELLOW}New branch detected: $REF_NAME${NC}"
|
||||||
|
|
||||||
# Find the common ancestor with other branches
|
# For new branches, only validate the last 10 commits by default
|
||||||
# This helps us identify only the new commits unique to this branch
|
|
||||||
COMMON_ANCESTOR=""
|
|
||||||
|
|
||||||
# Get list of all other refs excluding the current one and tags
|
|
||||||
OTHER_REFS=$(git for-each-ref --format='%(refname)' refs/heads/ | grep -v "$REF_NAME")
|
|
||||||
|
|
||||||
if [ -n "$OTHER_REFS" ]; then
|
|
||||||
# Find the merge-base with each existing branch and use the most recent one
|
|
||||||
for REF in $OTHER_REFS; do
|
|
||||||
BASE=$(git merge-base "$NEW_REV" "$REF" 2>/dev/null || echo "")
|
|
||||||
if [ -n "$BASE" ]; then
|
|
||||||
if [ -z "$COMMON_ANCESTOR" ] || [ "$(git rev-list -n 1 --date-order "$BASE" "$COMMON_ANCESTOR" | wc -l)" -eq 1 ]; then
|
|
||||||
COMMON_ANCESTOR="$BASE"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$COMMON_ANCESTOR" ]; then
|
|
||||||
echo -e "${BLUE}Only validating commits unique to this branch${NC}"
|
|
||||||
OLD_REV="$COMMON_ANCESTOR"
|
|
||||||
else
|
|
||||||
# Brand new branch with no common ancestor - validate only the last 10 commits
|
|
||||||
echo -e "${BLUE}New branch with no common history - validating only the latest 10 commits${NC}"
|
|
||||||
COMMIT_COUNT=$(git rev-list --count "$NEW_REV")
|
COMMIT_COUNT=$(git rev-list --count "$NEW_REV")
|
||||||
if [ "$COMMIT_COUNT" -gt 10 ]; then
|
if [ "$COMMIT_COUNT" -gt 10 ]; then
|
||||||
OLD_REV=$(git rev-list -n 1 "$NEW_REV"~10)
|
OLD_REV=$(git rev-list -n 1 "$NEW_REV"~10)
|
||||||
|
echo -e "${BLUE}New branch - validating only the latest 10 commits${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${BLUE}New branch - validating all $COMMIT_COUNT commits${NC}"
|
||||||
fi
|
fi
|
||||||
fi
|
}
|
||||||
fi
|
|
||||||
|
|
||||||
echo -e "${YELLOW}Checking commits in $REF_NAME${NC}"
|
echo -e "${YELLOW}Checking commits in $REF_NAME${NC}"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue