Skip to content

Commit 9aae806

Browse files
committed
fix pre-commit hook script
1 parent ab0942a commit 9aae806

1 file changed

Lines changed: 44 additions & 45 deletions

File tree

scripts/pre-commit.sh

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,57 @@
11
#!/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
24

3-
exit 0
4-
echo "✓ All pre-commit checks passed!"
5-
echo ""
5+
set -e
66

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
713
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
1118
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
1523

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
2525
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
3426
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
4228
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
4732
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
5233

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)
5445
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
5654
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

Comments
 (0)