Skip to content

Commit 3ef2e15

Browse files
Copilotjosecelano
andcommitted
feat: [#121] add git pre-commit hook installation script and workflow integration
Co-authored-by: josecelano <[email protected]>
1 parent aa93795 commit 3ef2e15

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

.github/workflows/copilot-setup-steps.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ jobs:
5050
run: |
5151
# Verify all tools are installed correctly
5252
target/release/dependency-installer check
53+
54+
- name: Install Git pre-commit hooks
55+
run: |
56+
./scripts/install-git-hooks.sh

scripts/install-git-hooks.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Install Git hooks for this repository.
4+
# This script creates a symbolic link from .git/hooks/pre-commit to scripts/pre-commit.sh
5+
6+
set -e
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
10+
HOOK_SOURCE="$REPO_ROOT/scripts/pre-commit.sh"
11+
HOOK_TARGET="$REPO_ROOT/.git/hooks/pre-commit"
12+
13+
echo "Installing Git hooks..."
14+
15+
# Check if .git directory exists
16+
if [ ! -d "$REPO_ROOT/.git" ]; then
17+
echo "Error: .git directory not found. Are you in a Git repository?"
18+
exit 1
19+
fi
20+
21+
# Check if source script exists
22+
if [ ! -f "$HOOK_SOURCE" ]; then
23+
echo "Error: Pre-commit script not found at $HOOK_SOURCE"
24+
exit 1
25+
fi
26+
27+
# Create hooks directory if it doesn't exist
28+
mkdir -p "$REPO_ROOT/.git/hooks"
29+
30+
# Remove existing hook if present
31+
if [ -e "$HOOK_TARGET" ]; then
32+
echo "Removing existing pre-commit hook..."
33+
rm "$HOOK_TARGET"
34+
fi
35+
36+
# Create symbolic link to pre-commit script
37+
echo "Creating symbolic link to scripts/pre-commit.sh..."
38+
ln -s "$HOOK_SOURCE" "$HOOK_TARGET"
39+
40+
# Verify the hook is executable
41+
if [ ! -x "$HOOK_SOURCE" ]; then
42+
echo "Warning: Making scripts/pre-commit.sh executable..."
43+
chmod +x "$HOOK_SOURCE"
44+
fi
45+
46+
echo ""
47+
echo "✓ Git hooks installed successfully"
48+
echo ""
49+
echo "The pre-commit hook is now linked to ./scripts/pre-commit.sh"
50+
echo "Any changes to scripts/pre-commit.sh will automatically affect the Git hook."

0 commit comments

Comments
 (0)