summarylogtreecommitdiffstats
path: root/verify_git_hygiene.sh
blob: d9f5478567915a1013a0a2801fe571ca3de2019a (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
# Git Hygiene Verification Guard
# Updated: Explicitly allows lmstudio.png, verifies exclusion of src/ and pkg/ from history and staged index

echo "=== Git Hygiene Verification Guard ==="
echo ""

# Color codes
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[1;33m"
NC="\033[0m"

FAIL=0

# Check 1: Verify lmstudio.png is NOT ignored (explicitly allowed)
echo "Check 1: Verifying lmstudio.png is tracked/allowed..."
if git ls-files lmstudio.png 2>/dev/null | grep -q "lmstudio.png"; then
    echo -e "${GREEN}✓ PASSED: lmstudio.png is tracked${NC}"
elif ! git check-ignore lmstudio.png 2>/dev/null; then
    echo -e "${GREEN}✓ PASSED: lmstudio.png is not ignored${NC}"
else
    echo -e "${YELLOW}⚠ WARNING: lmstudio.png appears to be in .gitignore${NC}"
fi
echo ""

# Check 2: Verify src/ folder is NOT in git history
echo "Check 2: Verifying src/ folder is NOT in git history..."
SRC_IN_HISTORY=$(git log --all --full-history --name-only --format="" -- 'src/' 2>/dev/null | wc -l)
if [ "$SRC_IN_HISTORY" -gt 0 ]; then
    echo -e "${RED}✗ FAILED: src/ folder found in git history${NC}"
    FAIL=1
else
    echo -e "${GREEN}✓ PASSED: src/ folder is clean from history${NC}"
fi
echo ""

# Check 3: Verify pkg/ folder is NOT in git history
echo "Check 3: Verifying pkg/ folder is NOT in git history..."
PKG_IN_HISTORY=$(git log --all --full-history --name-only --format="" -- 'pkg/' 2>/dev/null | wc -l)
if [ "$PKG_IN_HISTORY" -gt 0 ]; then
    echo -e "${RED}✗ FAILED: pkg/ folder found in git history${NC}"
    FAIL=1
else
    echo -e "${GREEN}✓ PASSED: pkg/ folder is clean from history${NC}"
fi
echo ""

# Check 4: Verify src/ folder is NOT in staged index
echo "Check 4: Verifying src/ folder is NOT in staged index..."
SRC_STAGED=$(git diff --cached --name-only -- 'src/' 2>/dev/null | wc -l)
if [ "$SRC_STAGED" -gt 0 ]; then
    echo -e "${RED}✗ FAILED: src/ folder has staged files${NC}"
    git diff --cached --name-only -- 'src/'
    FAIL=1
else
    echo -e "${GREEN}✓ PASSED: src/ folder is clean from staged index${NC}"
fi
echo ""

# Check 5: Verify pkg/ folder is NOT in staged index
echo "Check 5: Verifying pkg/ folder is NOT in staged index..."
PKG_STAGED=$(git diff --cached --name-only -- 'pkg/' 2>/dev/null | wc -l)
if [ "$PKG_STAGED" -gt 0 ]; then
    echo -e "${RED}✗ FAILED: pkg/ folder has staged files${NC}"
    git diff --cached --name-only -- 'pkg/'
    FAIL=1
else
    echo -e "${GREEN}✓ PASSED: pkg/ folder is clean from staged index${NC}"
fi
echo ""

# Check 6: Verify no AppImages or packages are staged
echo "Check 6: Verifying NO binary extensions are staged..."
BINARY_STAGED=$(git diff --cached --name-only | grep -E "\.(AppImage|zst|tar\.gz)$" | wc -l)
if [ "$BINARY_STAGED" -gt 0 ]; then
    echo -e "${RED}✗ FAILED: Binary files are staged!${NC}"
    git diff --cached --name-only | grep -E "\.(AppImage|zst|tar\.gz)$"
    FAIL=1
else
    echo -e "${GREEN}✓ PASSED: No binary extensions staged${NC}"
fi
echo ""

# Check 7: Review staged changes
echo "Check 7: Reviewing staged changes summary..."
git diff --cached --stat
echo ""

# Final result
echo "=== Verification Summary ==="
if [ "$FAIL" -eq 0 ]; then
    echo -e "${GREEN}✓ All hygiene checks PASSED${NC}"
    echo "Repository is ready for commit."
    exit 0
else
    echo -e "${RED}✗ Some hygiene checks FAILED${NC}"
    echo "Please fix the issues before committing."
    exit 1
fi