| 1 |
#!/bin/bash |
| 2 |
# Safe Installation of Fenrir Validation Hook |
| 3 |
# |
| 4 |
# This script safely installs the composite pre-commit hook that combines |
| 5 |
# your existing version management with new code quality validation. |
| 6 |
|
| 7 |
set -e |
| 8 |
|
| 9 |
# Colors for output |
| 10 |
GREEN='\033[0;32m' |
| 11 |
YELLOW='\033[1;33m' |
| 12 |
RED='\033[0;31m' |
| 13 |
BLUE='\033[1;34m' |
| 14 |
NC='\033[0m' # No Color |
| 15 |
|
| 16 |
echo -e "${BLUE}Fenrir Validation Hook Installation${NC}" |
| 17 |
echo "====================================" |
| 18 |
|
| 19 |
# Check we're in the right directory |
| 20 |
if [ ! -f "CLAUDE.md" ] || [ ! -d "src/fenrirscreenreader" ]; then |
| 21 |
echo -e "${RED}Error: Must be run from Fenrir project root directory${NC}" |
| 22 |
exit 1 |
| 23 |
fi |
| 24 |
|
| 25 |
# Check if there's already a pre-commit hook |
| 26 |
if [ -f ".git/hooks/pre-commit" ]; then |
| 27 |
echo -e "\n${YELLOW}Existing pre-commit hook detected${NC}" |
| 28 |
|
| 29 |
# Check if it's a symlink (our validation hook) or a regular file (version hook) |
| 30 |
if [ -L ".git/hooks/pre-commit" ]; then |
| 31 |
echo -e "${YELLOW}Current hook appears to be our validation hook (symlink)${NC}" |
| 32 |
read -p "Replace with composite hook that includes version management? (y/N): " -n 1 -r |
| 33 |
echo |
| 34 |
if [[ ! $REPLY =~ ^[Yy]$ ]]; then |
| 35 |
echo -e "${YELLOW}Installation cancelled${NC}" |
| 36 |
exit 0 |
| 37 |
fi |
| 38 |
rm .git/hooks/pre-commit |
| 39 |
else |
| 40 |
echo -e "${GREEN}Current hook appears to be the version management hook (regular file)${NC}" |
| 41 |
|
| 42 |
# Back up the existing hook |
| 43 |
backup_name=".git/hooks/pre-commit.backup.$(date +%Y%m%d_%H%M%S)" |
| 44 |
cp .git/hooks/pre-commit "$backup_name" |
| 45 |
echo -e "${GREEN}✓ Existing hook backed up to: $backup_name${NC}" |
| 46 |
|
| 47 |
# Verify the backup contains version management code |
| 48 |
if grep -q "versionFile" "$backup_name"; then |
| 49 |
echo -e "${GREEN}✓ Backup contains version management logic${NC}" |
| 50 |
else |
| 51 |
echo -e "${YELLOW}⚠ Backup doesn't appear to contain version management logic${NC}" |
| 52 |
echo -e "${YELLOW} You may need to manually restore version management functionality${NC}" |
| 53 |
fi |
| 54 |
|
| 55 |
read -p "Install composite hook (version management + validation)? (Y/n): " -n 1 -r |
| 56 |
echo |
| 57 |
if [[ $REPLY =~ ^[Nn]$ ]]; then |
| 58 |
echo -e "${YELLOW}Installation cancelled${NC}" |
| 59 |
exit 0 |
| 60 |
fi |
| 61 |
fi |
| 62 |
else |
| 63 |
echo -e "${YELLOW}No existing pre-commit hook found${NC}" |
| 64 |
read -p "Install composite hook? (Y/n): " -n 1 -r |
| 65 |
echo |
| 66 |
if [[ $REPLY =~ ^[Nn]$ ]]; then |
| 67 |
echo -e "${YELLOW}Installation cancelled${NC}" |
| 68 |
exit 0 |
| 69 |
fi |
| 70 |
fi |
| 71 |
|
| 72 |
# Install the composite hook |
| 73 |
echo -e "\n${YELLOW}Installing composite pre-commit hook...${NC}" |
| 74 |
cp tools/pre-commit-composite .git/hooks/pre-commit |
| 75 |
chmod +x .git/hooks/pre-commit |
| 76 |
echo -e "${GREEN}✓ Composite hook installed${NC}" |
| 77 |
|
| 78 |
# Test the hook |
| 79 |
echo -e "\n${YELLOW}Testing the composite hook...${NC}" |
| 80 |
if ./.git/hooks/pre-commit >/dev/null 2>&1; then |
| 81 |
echo -e "${GREEN}✓ Composite hook test passed${NC}" |
| 82 |
else |
| 83 |
echo -e "${RED}⚠ Composite hook test found issues (this may be normal)${NC}" |
| 84 |
echo " Run manually to see details: ./.git/hooks/pre-commit" |
| 85 |
fi |
| 86 |
|
| 87 |
# Final instructions |
| 88 |
echo -e "\n${GREEN}Installation Complete!${NC}" |
| 89 |
echo "" |
| 90 |
echo "Your composite pre-commit hook now provides:" |
| 91 |
echo " 1. ✓ Version management (existing functionality preserved)" |
| 92 |
echo " 2. ✓ Python syntax validation" |
| 93 |
echo " 3. ✓ Core module import testing" |
| 94 |
echo " 4. ✓ Common issue detection" |
| 95 |
echo "" |
| 96 |
echo "Development workflow:" |
| 97 |
echo " • Make your changes" |
| 98 |
echo " • git add . && git commit" |
| 99 |
echo " • Hook runs automatically (version update + validation)" |
| 100 |
echo "" |
| 101 |
echo "Manual validation (optional):" |
| 102 |
echo " • python3 tools/validate_syntax.py --fix" |
| 103 |
echo " • python3 tools/validate_release.py --quick" |
| 104 |
echo "" |
| 105 |
echo -e "${BLUE}Environment variables:${NC}" |
| 106 |
echo -e "${BLUE} SKIP_VERSION_UPDATE=1 Skip version management${NC}" |
| 107 |
echo "" |
| 108 |
if [ -f ".git/hooks/pre-commit.backup."* ]; then |
| 109 |
echo -e "${YELLOW}Note: Your original hook is backed up and can be restored if needed${NC}" |
| 110 |
fi |