|
1 | 1 | #!/bin/bash |
| 2 | +# Pre-commit hook for Deep-MI website |
| 3 | +# Install: cp scripts/pre-commit.sh .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit |
2 | 4 |
|
3 | | -exit 0 |
4 | | -echo "✓ All pre-commit checks passed!" |
5 | | -echo "" |
| 5 | +set -e |
6 | 6 |
|
| 7 | +echo "Running pre-commit checks..." |
| 8 | + |
| 9 | +# Check if validation scripts exist |
| 10 | +if [ ! -f "scripts/validate_yaml.rb" ] || [ ! -f "scripts/validate_posts.sh" ]; then |
| 11 | + echo "⚠️ Validation scripts not found. Skipping validation." |
| 12 | + exit 0 |
7 | 13 | fi |
8 | | - read |
9 | | - echo "Press Enter to continue anyway, or Ctrl+C to abort." |
10 | | - echo "Consider optimizing images before committing." |
| 14 | + |
| 15 | +# Validate YAML files |
| 16 | +echo "→ Validating YAML files..." |
| 17 | +if ! ./scripts/validate_yaml.rb; then |
11 | 18 | echo "" |
12 | | - echo "$large_files" |
13 | | - echo "⚠️ Warning: Large files detected:" |
14 | | -if [ -n "$large_files" ]; then |
| 19 | + echo "✗ YAML validation failed!" |
| 20 | + echo " Fix the errors above before committing." |
| 21 | + exit 1 |
| 22 | +fi |
15 | 23 |
|
16 | | -done) |
17 | | - fi |
18 | | - fi |
19 | | - echo "$file ($(($size / 1024))KB)" |
20 | | - if [ $size -gt 1048576 ]; then # 1MB |
21 | | - size=$(wc -c < "$file") |
22 | | - if [ -f "$file" ]; then |
23 | | -large_files=$(git diff --cached --name-only --diff-filter=ACM | while read file; do |
24 | | -echo "→ Checking for large files..." |
| 24 | +# Validate posts |
25 | 25 | echo "" |
26 | | -# Check for large files |
27 | | -
|
28 | | -fi |
29 | | - exit 1 |
30 | | - echo " Fix the errors above before committing." |
31 | | - echo "✗ Post validation failed!" |
32 | | - echo "" |
33 | | -if ! ./scripts/validate_posts.sh; then |
34 | 26 | echo "→ Validating posts..." |
35 | | -echo "" |
36 | | -# Validate posts |
37 | | -
|
38 | | -fi |
39 | | - exit 1 |
40 | | - echo " Fix the errors above before committing." |
41 | | - echo "✗ YAML validation failed!" |
| 27 | +if ! ./scripts/validate_posts.sh; then |
42 | 28 | echo "" |
43 | | -if ! ./scripts/validate_yaml.rb; then |
44 | | -echo "→ Validating YAML files..." |
45 | | -# Validate YAML files |
46 | | -
|
| 29 | + echo "✗ Post validation failed!" |
| 30 | + echo " Fix the errors above before committing." |
| 31 | + exit 1 |
47 | 32 | fi |
48 | | - exit 0 |
49 | | - echo "⚠️ Validation scripts not found. Skipping validation." |
50 | | -if [ ! -f "scripts/validate_yaml.rb" ] || [ ! -f "scripts/validate_posts.sh" ]; then |
51 | | -# Check if validation scripts exist |
52 | 33 |
|
53 | | -echo "Running pre-commit checks..." |
| 34 | +# Check for large files |
| 35 | +echo "" |
| 36 | +echo "→ Checking for large files..." |
| 37 | +large_files=$(git diff --cached --name-only --diff-filter=ACM | while read file; do |
| 38 | + if [ -f "$file" ]; then |
| 39 | + size=$(wc -c < "$file") |
| 40 | + if [ $size -gt 1048576 ]; then # 1MB |
| 41 | + echo "$file ($(($size / 1024))KB)" |
| 42 | + fi |
| 43 | + fi |
| 44 | +done) |
54 | 45 |
|
55 | | -set -e |
| 46 | +if [ -n "$large_files" ]; then |
| 47 | + echo "⚠️ Warning: Large files detected:" |
| 48 | + echo "$large_files" |
| 49 | + echo "" |
| 50 | + echo "Consider optimizing images before committing." |
| 51 | + echo "Press Enter to continue anyway, or Ctrl+C to abort." |
| 52 | + read |
| 53 | +fi |
56 | 54 |
|
57 | | -# Install: cp scripts/pre-commit.sh .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit |
58 | | -# Pre-commit hook for Deep-MI website |
| 55 | +echo "" |
| 56 | +echo "✓ All pre-commit checks passed!" |
| 57 | +exit 0 |
0 commit comments