All checks were successful
Build ptprnt / build (push) Successful in 3m47s
Reviewed-on: moritz/ptouch-prnt#17
97 lines
2.5 KiB
Bash
Executable File
97 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# Install git hooks for ptouch-prnt repository
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Get the root directory of the git repository
|
|
ROOT_DIR=$(git rev-parse --show-toplevel 2>/dev/null)
|
|
|
|
if [ -z "$ROOT_DIR" ]; then
|
|
echo -e "${RED}Error: Not in a git repository${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
HOOKS_SOURCE_DIR="$ROOT_DIR/hooks"
|
|
HOOKS_TARGET_DIR="$ROOT_DIR/.git/hooks"
|
|
|
|
echo "Installing git hooks..."
|
|
echo " Source: $HOOKS_SOURCE_DIR"
|
|
echo " Target: $HOOKS_TARGET_DIR"
|
|
echo ""
|
|
|
|
# Check if hooks directory exists
|
|
if [ ! -d "$HOOKS_SOURCE_DIR" ]; then
|
|
echo -e "${RED}Error: Hooks source directory not found: $HOOKS_SOURCE_DIR${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if .git/hooks directory exists
|
|
if [ ! -d "$HOOKS_TARGET_DIR" ]; then
|
|
echo -e "${RED}Error: Git hooks directory not found: $HOOKS_TARGET_DIR${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Install each hook
|
|
installed_count=0
|
|
for hook_file in "$HOOKS_SOURCE_DIR"/*; do
|
|
# Skip the install script itself
|
|
if [[ "$(basename "$hook_file")" == "install_hooks.sh" ]]; then
|
|
continue
|
|
fi
|
|
|
|
# Skip if not a file
|
|
if [ ! -f "$hook_file" ]; then
|
|
continue
|
|
fi
|
|
|
|
hook_name=$(basename "$hook_file")
|
|
target_file="$HOOKS_TARGET_DIR/$hook_name"
|
|
|
|
# Check if hook already exists
|
|
if [ -f "$target_file" ]; then
|
|
echo -e "${YELLOW}Warning: Hook already exists: $hook_name${NC}"
|
|
read -p " Overwrite? (y/N) " -n 1 -r
|
|
echo
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
echo " Skipped: $hook_name"
|
|
continue
|
|
fi
|
|
fi
|
|
|
|
# Copy and make executable
|
|
cp "$hook_file" "$target_file"
|
|
chmod +x "$target_file"
|
|
echo -e "${GREEN}✓${NC} Installed: $hook_name"
|
|
((installed_count++))
|
|
done
|
|
|
|
echo ""
|
|
if [ $installed_count -eq 0 ]; then
|
|
echo -e "${YELLOW}No hooks were installed${NC}"
|
|
else
|
|
echo -e "${GREEN}Successfully installed $installed_count hook(s)${NC}"
|
|
fi
|
|
|
|
# Verify update_copyright.sh exists and is executable
|
|
if [ -f "$ROOT_DIR/scripts/update_copyright.sh" ]; then
|
|
if [ ! -x "$ROOT_DIR/scripts/update_copyright.sh" ]; then
|
|
echo ""
|
|
echo -e "${YELLOW}Making update_copyright.sh executable...${NC}"
|
|
chmod +x "$ROOT_DIR/scripts/update_copyright.sh"
|
|
echo -e "${GREEN}✓${NC} update_copyright.sh is now executable"
|
|
fi
|
|
else
|
|
echo ""
|
|
echo -e "${YELLOW}Warning: scripts/update_copyright.sh not found${NC}"
|
|
echo " The pre-commit hook requires this script to function properly"
|
|
fi
|
|
|
|
echo ""
|
|
echo "Hook installation complete!"
|