-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-git-hooks.sh
executable file
·48 lines (37 loc) · 1.53 KB
/
setup-git-hooks.sh
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
#!/bin/bash
# Script to install Git hooks for cringe.live
# Determines if this is a submodule and installs hooks accordingly
set -e # Exit on any error
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
HOOKS_SOURCE_DIR="$SCRIPT_DIR/.githooks"
MAIN_GIT_DIR="$SCRIPT_DIR/.git"
echo "Setting up Git hooks for cringe.live..."
# Check if this is a submodule by looking for .git file instead of directory
if [ -f "$MAIN_GIT_DIR" ]; then
echo "Detected Git submodule."
# Extract the path to the actual .git directory from the .git file
PARENT_GIT_DIR=$(cat "$MAIN_GIT_DIR" | sed -n 's/gitdir: //p')
if [[ "$PARENT_GIT_DIR" == /* ]]; then
# Absolute path
GIT_HOOKS_DIR="$PARENT_GIT_DIR/hooks"
else
# Relative path, make it absolute
GIT_HOOKS_DIR="$SCRIPT_DIR/$PARENT_GIT_DIR/hooks"
fi
echo "Git hooks directory: $GIT_HOOKS_DIR"
else
echo "Detected standalone Git repository."
GIT_HOOKS_DIR="$MAIN_GIT_DIR/hooks"
echo "Git hooks directory: $GIT_HOOKS_DIR"
fi
# Ensure hooks directory exists
mkdir -p "$GIT_HOOKS_DIR"
# Install pre-commit hook
echo "Installing pre-commit hook..."
cp "$HOOKS_SOURCE_DIR/pre-commit" "$GIT_HOOKS_DIR/pre-commit"
chmod +x "$GIT_HOOKS_DIR/pre-commit"
# Configure Git to use our hooks directory
echo "Configuring Git to use hooks directory..."
git config core.hooksPath "$GIT_HOOKS_DIR"
echo "Git hooks setup complete!"
echo "The generate_related_posts.py script will now run automatically when committing changes to Markdown files."