post-checkout.backupโข12.5 kB
#!/bin/bash
# GitFlow Guardian - Post-checkout Hook
# Provides helpful reminders when switching branches
# Get the directory where this hook is located
HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Load configuration if it exists
CONFIG_FILE="$HOOK_DIR/config"
if [ -f "$CONFIG_FILE" ]; then
source "$CONFIG_FILE"
else
# Default configuration
USE_COLORS=true
SHOW_CHECKOUT_MESSAGES=true
MAX_DISPLAY_LENGTH=50
fi
# Exit early if messages are disabled
if [ "$SHOW_CHECKOUT_MESSAGES" != "true" ]; then
exit 0
fi
# Colors (only if enabled)
if [ "$USE_COLORS" = "true" ]; then
RED='\033[0;31m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
else
RED=''
YELLOW=''
GREEN=''
BLUE=''
CYAN=''
NC=''
fi
# Get the branch we just switched to
BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null)
# Check if this is actually a branch switch (not a file checkout)
# $3 is 1 for branch checkout, 0 for file checkout
if [ "$3" != "1" ]; then
exit 0
fi
# Provide helpful messages based on branch
case "$BRANCH" in
main|master)
echo -e "${RED}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo -e "${RED}โ ๐ You are now on the MAIN branch โ${NC}"
echo -e "${RED}โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฃ${NC}"
echo -e "${RED}โ โ${NC}"
echo -e "${RED}โ โ ๏ธ This is the PRODUCTION branch! โ${NC}"
echo -e "${RED}โ โ${NC}"
echo -e "${RED}โ Remember: โ${NC}"
echo -e "${RED}โ โข DO NOT commit directly here โ${NC}"
echo -e "${RED}โ โข Only merge from release/* or hotfix/* branches โ${NC}"
echo -e "${RED}โ โข All changes should go through pull requests โ${NC}"
echo -e "${RED}โ โ${NC}"
echo -e "${RED}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
;;
develop)
echo -e "${YELLOW}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo -e "${YELLOW}โ ๐ You are now on the DEVELOP branch โ${NC}"
echo -e "${YELLOW}โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฃ${NC}"
echo -e "${YELLOW}โ โ${NC}"
echo -e "${YELLOW}โ This is the integration branch for new features. โ${NC}"
echo -e "${YELLOW}โ โ${NC}"
echo -e "${YELLOW}โ Remember: โ${NC}"
echo -e "${YELLOW}โ โข Create feature branches for new work: โ${NC}"
echo -e "${YELLOW}โ ${GREEN}git checkout -b feature/your-feature${YELLOW} โ${NC}"
echo -e "${YELLOW}โ โข Don't commit directly unless it's a merge โ${NC}"
echo -e "${YELLOW}โ โข Keep this branch stable for other developers โ${NC}"
echo -e "${YELLOW}โ โ${NC}"
echo -e "${YELLOW}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
;;
feature/*)
# Truncate long branch names to fit in the box
if [ ${#BRANCH} -gt $MAX_DISPLAY_LENGTH ]; then
TRUNCATE_LENGTH=$((MAX_DISPLAY_LENGTH - 3))
DISPLAY_BRANCH="${BRANCH:0:$TRUNCATE_LENGTH}..."
else
DISPLAY_BRANCH="$BRANCH"
fi
echo -e "${GREEN}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo -e "${GREEN}โ โ
You are on a FEATURE branch โ${NC}"
echo -e "${GREEN}โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฃ${NC}"
echo -e "${GREEN}โ โ${NC}"
echo -e "${GREEN}โ Branch: ${CYAN}$DISPLAY_BRANCH${GREEN}${NC}"
echo -e "${GREEN}โ โ${NC}"
echo -e "${GREEN}โ You can safely commit and experiment here! โ${NC}"
echo -e "${GREEN}โ โ${NC}"
echo -e "${GREEN}โ When ready: โ${NC}"
echo -e "${GREEN}โ 1. Push your branch: ${CYAN}git push -u origin $BRANCH${GREEN} โ${NC}"
echo -e "${GREEN}โ 2. Create a PR: ${CYAN}gh pr create${GREEN} โ${NC}"
echo -e "${GREEN}โ โ${NC}"
echo -e "${GREEN}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
;;
fix/*|bugfix/*)
# Truncate long branch names to fit in the box
if [ ${#BRANCH} -gt $MAX_DISPLAY_LENGTH ]; then
TRUNCATE_LENGTH=$((MAX_DISPLAY_LENGTH - 3))
DISPLAY_BRANCH="${BRANCH:0:$TRUNCATE_LENGTH}..."
else
DISPLAY_BRANCH="$BRANCH"
fi
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo -e "${BLUE}โ ๐ง You are on a FIX branch โ${NC}"
echo -e "${BLUE}โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฃ${NC}"
echo -e "${BLUE}โ โ${NC}"
echo -e "${BLUE}โ Branch: ${CYAN}$DISPLAY_BRANCH${BLUE}${NC}"
echo -e "${BLUE}โ โ${NC}"
echo -e "${BLUE}โ Good practices for fixes: โ${NC}"
echo -e "${BLUE}โ โข Keep changes focused on the specific bug โ${NC}"
echo -e "${BLUE}โ โข Add tests to prevent regression โ${NC}"
echo -e "${BLUE}โ โข Update documentation if needed โ${NC}"
echo -e "${BLUE}โ โ${NC}"
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
;;
hotfix/*)
# Truncate long branch names to fit in the box
if [ ${#BRANCH} -gt $MAX_DISPLAY_LENGTH ]; then
TRUNCATE_LENGTH=$((MAX_DISPLAY_LENGTH - 3))
DISPLAY_BRANCH="${BRANCH:0:$TRUNCATE_LENGTH}..."
else
DISPLAY_BRANCH="$BRANCH"
fi
echo -e "${RED}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo -e "${RED}โ ๐จ You are on a HOTFIX branch โ${NC}"
echo -e "${RED}โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฃ${NC}"
echo -e "${RED}โ โ${NC}"
echo -e "${RED}โ Branch: ${CYAN}$DISPLAY_BRANCH${RED}${NC}"
echo -e "${RED}โ โ${NC}"
echo -e "${RED}โ This is for URGENT production fixes only! โ${NC}"
echo -e "${RED}โ โ${NC}"
echo -e "${RED}โ Remember to: โ${NC}"
echo -e "${RED}โ โข Fix ONLY the critical issue โ${NC}"
echo -e "${RED}โ โข Test thoroughly โ${NC}"
echo -e "${RED}โ โข Merge to both main AND develop โ${NC}"
echo -e "${RED}โ โ${NC}"
echo -e "${RED}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
;;
release/*)
# Truncate long branch names to fit in the box
if [ ${#BRANCH} -gt $MAX_DISPLAY_LENGTH ]; then
TRUNCATE_LENGTH=$((MAX_DISPLAY_LENGTH - 3))
DISPLAY_BRANCH="${BRANCH:0:$TRUNCATE_LENGTH}..."
else
DISPLAY_BRANCH="$BRANCH"
fi
echo -e "${CYAN}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo -e "${CYAN}โ ๐ฆ You are on a RELEASE branch โ${NC}"
echo -e "${CYAN}โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฃ${NC}"
echo -e "${CYAN}โ โ${NC}"
echo -e "${CYAN}โ Branch: ${CYAN}$DISPLAY_BRANCH${CYAN}${NC}"
echo -e "${CYAN}โ โ${NC}"
echo -e "${CYAN}โ Only bug fixes and release prep allowed here! โ${NC}"
echo -e "${CYAN}โ โ${NC}"
echo -e "${CYAN}โ No new features! โ${NC}"
echo -e "${CYAN}โ โ${NC}"
echo -e "${CYAN}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
;;
esac
# Show current status
echo ""
git status -sb