Skip to content

Commit abc6444

Browse files
committed
Colorize output of branch validation
1 parent ebb42f8 commit abc6444

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

scripts/pre-push-branch-check.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/bin/bash
22
# Git pre-push hook for validating branch names.
33

4-
# --- Configuration ---
54
BRANCH_REGEX="^(task|bug|feature)/[0-9]+-[a-zA-Z0-9-]+$"
65

7-
# --- Script Logic ---
6+
# ANSI Colors
7+
RED='\033[0;31m'
8+
GREEN='\033[0;32m'
9+
NC='\033[0m' # No Color (reset)
810

911
# Get the name of the current branch
1012
CURRENT_BRANCH=$(git symbolic-ref --short HEAD)
@@ -15,20 +17,20 @@ EXCLUDED_BRANCHES=("main")
1517
# Check if the current branch is one of the excluded branches
1618
for EXCLUDED in "${EXCLUDED_BRANCHES[@]}"; do
1719
if [[ "$CURRENT_BRANCH" == "$EXCLUDED" ]]; then
18-
echo "Skipping branch name validation for protected branch: $CURRENT_BRANCH"
20+
echo -e "${GREEN}Skipping branch name validation for protected branch: $CURRENT_BRANCH${NC}"
1921
exit 0
2022
fi
2123
done
2224

2325
# Validate the current branch name against the regex
2426
if [[ "$CURRENT_BRANCH" =~ $BRANCH_REGEX ]]; then
25-
echo "Branch name '$CURRENT_BRANCH' is valid. Push allowed."
27+
echo -e "${GREEN}Branch name '$CURRENT_BRANCH' is valid. Push allowed.${NC}"
2628
exit 0
2729
else
28-
echo "--------------------------------------------------------"
29-
echo "PUSH FAILED: Invalid branch name format."
30-
echo "Branch: $CURRENT_BRANCH"
31-
echo "--------------------------------------------------------"
30+
echo -e "${RED}--------------------------------------------------------${NC}"
31+
echo -e "${RED}PUSH FAILED: Invalid branch name format.${NC}"
32+
echo -e "${RED}Branch: $CURRENT_BRANCH${NC}"
33+
echo -e "${RED}--------------------------------------------------------${NC}"
3234
echo "Branch naming rules are:"
3335
echo "1. Must start with 'task/', 'bug/', or 'feature/'"
3436
echo "2. Must include an issue number (digits) followed by a dash."
@@ -38,7 +40,7 @@ else
3840
echo " - feature/123-add-user-profile"
3941
echo " - bug/45-fix-login-redirect"
4042
echo " - task/789-update-composer-deps"
41-
echo "--------------------------------------------------------"
43+
echo -e "${RED}--------------------------------------------------------${NC}"
4244
# Exit with a non-zero status to abort the push
4345
exit 1
4446
fi

0 commit comments

Comments
 (0)