|
1 | | -#!/bin/bash |
2 | | - |
3 | | -# Setup Git hooks for OpenMapView |
4 | | -# This script installs a pre-commit hook that checks code formatting and copyright headers |
5 | | - |
6 | | -HOOKS_DIR=".git/hooks" |
7 | | -HOOK_FILE="$HOOKS_DIR/pre-commit" |
8 | | - |
9 | | -# Check if .git directory exists |
10 | | -if [ ! -d ".git" ]; then |
11 | | - echo "Error: .git directory not found. Run this script from the repository root." |
12 | | - exit 1 |
13 | | -fi |
14 | | - |
15 | | -# Create hooks directory if it doesn't exist |
16 | | -mkdir -p "$HOOKS_DIR" |
17 | | - |
18 | | -# Create pre-commit hook |
19 | | -cat > "$HOOK_FILE" << 'EOF' |
20 | | -#!/bin/bash |
21 | | -
|
22 | | -echo "Running pre-commit checks..." |
23 | | -echo "" |
24 | | -
|
25 | | -# Check code formatting |
26 | | -echo "1. Checking code formatting..." |
27 | | -./scripts/check-format.sh > /dev/null 2>&1 |
28 | | -
|
29 | | -if [ $? -ne 0 ]; then |
30 | | - echo "" |
31 | | - echo "Code formatting check failed!" |
32 | | - echo "Run './gradlew spotlessApply' to fix formatting issues." |
33 | | - echo "" |
34 | | - exit 1 |
35 | | -fi |
36 | | -
|
37 | | -echo " Code formatting: OK" |
38 | | -
|
39 | | -# Check copyright headers |
40 | | -echo "2. Checking copyright headers..." |
41 | | -./scripts/check-copyright.sh > /dev/null 2>&1 |
42 | | -
|
43 | | -if [ $? -ne 0 ]; then |
44 | | - echo "" |
45 | | - echo "Copyright header check failed!" |
46 | | - echo "Run './gradlew spotlessApply' to fix issues." |
47 | | - echo "" |
48 | | - exit 1 |
49 | | -fi |
50 | | -
|
51 | | -echo " Copyright headers: OK" |
52 | | -echo "" |
53 | | -echo "All pre-commit checks passed!" |
54 | | -EOF |
55 | | - |
56 | | -# Make hook executable |
57 | | -chmod +x "$HOOK_FILE" |
58 | | - |
59 | | -echo "Git hooks installed successfully!" |
60 | | -echo "" |
61 | | -echo "Pre-commit hook will now:" |
62 | | -echo " - Check code formatting before each commit" |
63 | | -echo " - Check copyright headers on all Kotlin files" |
64 | | -echo " - Block commits if issues are found" |
65 | | -echo " - Prompt to run './gradlew spotlessApply' to fix issues" |
66 | | -echo "" |
67 | | -echo "To bypass the hook (not recommended), use: git commit --no-verify" |
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Setup Git hooks for OpenMapView |
| 4 | +# This script installs a pre-commit hook that checks code formatting and copyright headers |
| 5 | + |
| 6 | +HOOKS_DIR=".git/hooks" |
| 7 | +HOOK_FILE="$HOOKS_DIR/pre-commit" |
| 8 | + |
| 9 | +# Check if .git directory exists |
| 10 | +if [ ! -d ".git" ]; then |
| 11 | + echo "Error: .git directory not found. Run this script from the repository root." |
| 12 | + exit 1 |
| 13 | +fi |
| 14 | + |
| 15 | +# Create hooks directory if it doesn't exist |
| 16 | +mkdir -p "$HOOKS_DIR" |
| 17 | + |
| 18 | +# Create pre-commit hook |
| 19 | +cat > "$HOOK_FILE" << 'EOF' |
| 20 | +#!/bin/bash |
| 21 | +
|
| 22 | +echo "Running pre-commit checks..." |
| 23 | +echo "" |
| 24 | +
|
| 25 | +# Check code formatting |
| 26 | +echo "1. Checking code formatting..." |
| 27 | +./scripts/check-format.sh > /dev/null 2>&1 |
| 28 | +
|
| 29 | +if [ $? -ne 0 ]; then |
| 30 | + echo "" |
| 31 | + echo "Code formatting check failed!" |
| 32 | + echo "Run './gradlew spotlessApply' to fix formatting issues." |
| 33 | + echo "" |
| 34 | + exit 1 |
| 35 | +fi |
| 36 | +
|
| 37 | +echo " Code formatting: OK" |
| 38 | +
|
| 39 | +# Check copyright headers |
| 40 | +echo "2. Checking copyright headers..." |
| 41 | +./scripts/check-copyright.sh > /dev/null 2>&1 |
| 42 | +
|
| 43 | +if [ $? -ne 0 ]; then |
| 44 | + echo "" |
| 45 | + echo "Copyright header check failed!" |
| 46 | + echo "Run './gradlew spotlessApply' to fix issues." |
| 47 | + echo "" |
| 48 | + exit 1 |
| 49 | +fi |
| 50 | +
|
| 51 | +echo " Copyright headers: OK" |
| 52 | +echo "" |
| 53 | +echo "All pre-commit checks passed!" |
| 54 | +EOF |
| 55 | + |
| 56 | +# Make hook executable |
| 57 | +chmod +x "$HOOK_FILE" |
| 58 | + |
| 59 | +echo "Git hooks installed successfully!" |
| 60 | +echo "" |
| 61 | +echo "Pre-commit hook will now:" |
| 62 | +echo " - Check code formatting before each commit" |
| 63 | +echo " - Check copyright headers on all Kotlin files" |
| 64 | +echo " - Block commits if issues are found" |
| 65 | +echo " - Prompt to run './gradlew spotlessApply' to fix issues" |
| 66 | +echo "" |
| 67 | +echo "To bypass the hook (not recommended), use: git commit --no-verify" |
0 commit comments