-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-hooks.sh
More file actions
49 lines (41 loc) Β· 1.59 KB
/
setup-hooks.sh
File metadata and controls
49 lines (41 loc) Β· 1.59 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
#!/bin/sh
# setup-hooks.sh - installs Git hooks for auto-regenerating docs
HOOKS_DIR=".git/hooks"
echo "π§ Setting up Git hooks in $HOOKS_DIR ..."
if [ ! -d "$HOOKS_DIR" ]; then
echo "β No .git directory found. Run this script from the repo root after git init/clone."
exit 1
fi
# Pre-commit hook
cat > "$HOOKS_DIR/pre-commit" << 'EOF'
#!/bin/sh
echo "π Running pre-commit hook: regenerating docs/DEPLOYMENT.pdf..."
make docs || { echo "β Failed to regenerate docs/DEPLOYMENT.pdf"; exit 1; }
git add docs/DEPLOYMENT.pdf
echo "β
docs/DEPLOYMENT.pdf updated and staged"
EOF
# Post-merge hook
cat > "$HOOKS_DIR/post-merge" << 'EOF'
#!/bin/sh
CHANGED_FILES=$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)
if echo "$CHANGED_FILES" | grep -q "docs/DEPLOYMENT.md"; then
echo "π DEPLOYMENT.md changed, regenerating PDF..."
make docs || { echo "β Failed to regenerate docs/DEPLOYMENT.pdf"; exit 1; }
echo "β
docs/DEPLOYMENT.pdf updated after merge"
else
echo "βΉοΈ DEPLOYMENT.md not changed, skipping PDF regeneration"
fi
EOF
# Post-checkout hook
cat > "$HOOKS_DIR/post-checkout" << 'EOF'
#!/bin/sh
if [ -f docs/DEPLOYMENT.md ]; then
echo "π Checking out branch with DEPLOYMENT.md, regenerating PDF..."
make docs || { echo "β Failed to regenerate docs/DEPLOYMENT.pdf"; exit 1; }
echo "β
docs/DEPLOYMENT.pdf updated after checkout"
else
echo "βΉοΈ No DEPLOYMENT.md found in this branch, skipping PDF regeneration"
fi
EOF
chmod +x "$HOOKS_DIR/pre-commit" "$HOOKS_DIR/post-merge" "$HOOKS_DIR/post-checkout"
echo "β
Git hooks installed successfully"