-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall-hooks.sh
More file actions
executable file
·63 lines (53 loc) · 1.96 KB
/
Copy pathinstall-hooks.sh
File metadata and controls
executable file
·63 lines (53 loc) · 1.96 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
#!/bin/bash
# =============================================================================
# install-hooks.sh
#
# Configures Git to use the versioned hooks in .githooks/.
# Run once after cloning the repository.
#
# Usage:
# ./install-hooks.sh
#
# What it does:
# - Sets core.hooksPath to .githooks so Git picks up the pre-commit hook
# - Makes all scripts in .githooks/ executable
#
# Requirements:
# - git
# - gitleaks (recommended — brew install gitleaks)
# - shellcheck (recommended — brew install shellcheck)
# =============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
print_success() { echo -e "${GREEN}[HOOKS]${NC} $1"; }
print_warning() { echo -e "${YELLOW}[HOOKS]${NC} $1"; }
print_error() { echo -e "${RED}[HOOKS]${NC} $1" >&2; }
# Verify we're inside a git repository
if ! git -C "$SCRIPT_DIR" rev-parse --git-dir > /dev/null 2>&1; then
print_error "Not a git repository: ${SCRIPT_DIR}"
exit 1
fi
# Point Git at the versioned hooks directory
git -C "$SCRIPT_DIR" config core.hooksPath .githooks
print_success "core.hooksPath set to .githooks"
# Ensure all hooks are executable
chmod +x "${SCRIPT_DIR}/.githooks/"*
print_success "Hook permissions set."
# Advisory: check for recommended tools
MISSING_TOOLS=()
for tool in gitleaks shellcheck; do
if ! command -v "$tool" > /dev/null 2>&1; then
MISSING_TOOLS+=("$tool")
fi
done
if [[ ${#MISSING_TOOLS[@]} -gt 0 ]]; then
print_warning "Recommended tools not found: ${MISSING_TOOLS[*]}"
print_warning " Install with: brew install ${MISSING_TOOLS[*]}"
print_warning " The pre-commit hook will still run a built-in fallback for secret scanning,"
print_warning " but gitleaks and shellcheck provide significantly better coverage."
fi
print_success "Git hooks installed. They will run automatically on each commit."