Fix bin/publish: use correct .env path for rspade_system Fix bin/publish script: prevent grep exit code 1 from terminating script 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
99 lines
2.8 KiB
Bash
Executable File
99 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Git Hooks Installation Script for RSpade Framework
|
|
# This script installs version-controlled git hooks into the local repository
|
|
#
|
|
|
|
# Color codes for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
CYAN='\033[0;36m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Get the repository root (where .git directory is)
|
|
REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null)
|
|
|
|
if [ -z "$REPO_ROOT" ]; then
|
|
echo -e "${RED}Error: Not in a git repository${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
HOOKS_SOURCE_DIR="$REPO_ROOT/bin/git-hooks"
|
|
GIT_HOOKS_DIR="$REPO_ROOT/.git/hooks"
|
|
|
|
echo -e "${CYAN}RSpade Git Hooks Installer${NC}"
|
|
echo "============================"
|
|
echo ""
|
|
|
|
# Check if source hooks directory exists
|
|
if [ ! -d "$HOOKS_SOURCE_DIR" ]; then
|
|
echo -e "${RED}Error: Git hooks source directory not found at $HOOKS_SOURCE_DIR${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Create .git/hooks directory if it doesn't exist
|
|
if [ ! -d "$GIT_HOOKS_DIR" ]; then
|
|
mkdir -p "$GIT_HOOKS_DIR"
|
|
echo -e "${GREEN}Created .git/hooks directory${NC}"
|
|
fi
|
|
|
|
# Function to install a hook
|
|
install_hook() {
|
|
local hook_name=$1
|
|
local source_file="$HOOKS_SOURCE_DIR/$hook_name"
|
|
local target_file="$GIT_HOOKS_DIR/$hook_name"
|
|
|
|
if [ ! -f "$source_file" ]; then
|
|
echo -e "${YELLOW}Skipping $hook_name (not found in source)${NC}"
|
|
return
|
|
fi
|
|
|
|
# Check if hook already exists
|
|
if [ -e "$target_file" ]; then
|
|
if [ -L "$target_file" ]; then
|
|
# It's a symlink, check if it points to our hook
|
|
current_target=$(readlink "$target_file")
|
|
if [ "$current_target" = "$source_file" ]; then
|
|
echo -e "${GREEN}✓${NC} $hook_name already installed"
|
|
return
|
|
else
|
|
echo -e "${YELLOW}Updating $hook_name symlink${NC}"
|
|
rm "$target_file"
|
|
fi
|
|
else
|
|
# It's a regular file, back it up
|
|
backup_file="${target_file}.backup.$(date +%Y%m%d_%H%M%S)"
|
|
echo -e "${YELLOW}Backing up existing $hook_name to $(basename $backup_file)${NC}"
|
|
mv "$target_file" "$backup_file"
|
|
fi
|
|
fi
|
|
|
|
# Create symlink
|
|
ln -s "$source_file" "$target_file"
|
|
echo -e "${GREEN}✓ Installed $hook_name${NC}"
|
|
}
|
|
|
|
# Install available hooks
|
|
echo "Installing git hooks..."
|
|
echo ""
|
|
|
|
install_hook "pre-commit"
|
|
|
|
# Future hooks can be added here:
|
|
# install_hook "pre-push"
|
|
# install_hook "commit-msg"
|
|
# install_hook "prepare-commit-msg"
|
|
|
|
echo ""
|
|
echo -e "${GREEN}Git hooks installation complete!${NC}"
|
|
echo ""
|
|
echo "Installed hooks will:"
|
|
echo " • Run code quality checks before commits"
|
|
echo " • Prevent commits with code standard violations"
|
|
echo ""
|
|
echo "To bypass hooks temporarily (not recommended):"
|
|
echo " git commit --no-verify"
|
|
echo ""
|
|
echo "To uninstall hooks:"
|
|
echo " rm .git/hooks/pre-commit" |