-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup-git-hooks.sh
More file actions
executable file
·76 lines (62 loc) · 1.95 KB
/
setup-git-hooks.sh
File metadata and controls
executable file
·76 lines (62 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# Setup script for code-rag-mcp git hooks
set -e
echo "🪝 code-rag-mcp Git Hooks Setup"
echo "================================"
echo ""
# Check if we're in a git repository
if [ ! -d ".git" ]; then
echo "❌ Error: Not a git repository"
echo " Run this script from your project root (where .git/ is located)"
exit 1
fi
REPO_ROOT=$(git rev-parse --show-toplevel)
HOOKS_DIR="$REPO_ROOT/.git/hooks"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "📂 Repository: $REPO_ROOT"
echo "🔧 Hooks directory: $HOOKS_DIR"
echo ""
# Function to install a hook
install_hook() {
local hook_name=$1
local source_file="$SCRIPT_DIR/git-hooks/$hook_name"
local target_file="$HOOKS_DIR/$hook_name"
if [ ! -f "$source_file" ]; then
echo "⚠️ Hook template not found: $source_file"
return 1
fi
# Backup existing hook if present
if [ -f "$target_file" ]; then
echo "📦 Backing up existing $hook_name to ${hook_name}.backup"
cp "$target_file" "$target_file.backup"
fi
# Copy and make executable
cp "$source_file" "$target_file"
chmod +x "$target_file"
echo "✅ Installed: $hook_name"
}
echo "Installing hooks..."
echo ""
# Install post-commit hook
install_hook "post-commit"
# Install post-merge hook
install_hook "post-merge"
echo ""
echo "🎉 Git hooks installed successfully!"
echo ""
echo "📝 Installed hooks:"
echo " - post-commit: Re-indexes files after each commit"
echo " - post-merge: Re-indexes files after pull/merge"
echo ""
echo "💡 How it works:"
echo " 1. You commit/merge code changes"
echo " 2. Hook detects modified files"
echo " 3. Creates .code-rag-pending-reindex marker"
echo " 4. MCP server processes re-indexing on next startup/check"
echo ""
echo "⚙️ Configuration:"
echo " Edit config.yaml to adjust:"
echo " - file_extensions: Which files to index"
echo " - code_paths: Which directories to watch"
echo ""
echo "✨ Ready! Try making a commit to test it out."