CURRENT_BRANCH=$(git branch --show-current)
if [ "$CURRENT_BRANCH" = "main" ] || [ "$CURRENT_BRANCH" = "master" ]; then
echo "❌ WORKFLOW VIOLATION: Cannot commit directly to main."
echo ""
echo "Required: Create a feature branch first"
echo "Remediation:"
echo " 1. Create branch: git checkout -b feat/your-feature"
echo " 2. Commit on feature branch"
echo " 3. Create PR when ready"
echo ""
echo "If this is an emergency, use: git commit --no-verify"
echo "(But this should be extremely rare)"
exit 1
fi
STAGED_FILES=$(git diff --cached --name-only)
ISSUE_FILES=$(echo "$STAGED_FILES" | grep -E '^issues/[^/]+/(todo|in_progress|done)/.*\.md$' || true)
WORK_FILES=$(echo "$STAGED_FILES" | grep -vE '^issues/' || true)
if [ -n "$WORK_FILES" ] && [ -n "$ISSUE_FILES" ]; then
MOVING_TO_IN_PROGRESS=$(echo "$ISSUE_FILES" | grep '/in_progress/' || true)
if [ -z "$MOVING_TO_IN_PROGRESS" ]; then
echo "⚠️ WARNING: Staging work files together with issue files"
echo " Ensure issue move to in_progress/ was committed before work files"
echo ""
fi
fi
if [ -n "$WORK_FILES" ]; then
for issue_dir in issues/*/todo/; do
if [ -d "$issue_dir" ]; then
TODO_ISSUES=$(find "$issue_dir" -name "*.md" -type f 2>/dev/null | head -1)
if [ -n "$TODO_ISSUES" ]; then
STAGED_ISSUE_MOVE=$(echo "$ISSUE_FILES" | grep '/in_progress/' || true)
if [ -z "$STAGED_ISSUE_MOVE" ]; then
echo "⚠️ WARNING: Committing work files but issue may still be in todo/"
echo " Ensure issue was moved to in_progress/ and committed first"
echo " Issue files found in: $issue_dir"
echo ""
fi
fi
fi
done
fi
STAGED_COUNT=$(echo "$STAGED_FILES" | wc -l | tr -d ' ')
if [ "$STAGED_COUNT" -gt 20 ]; then
echo "⚠️ WARNING: Many files staged ($STAGED_COUNT files)"
echo " This might indicate use of 'git add -A' or 'git add .'"
echo " Consider using explicit file paths: git add <specific-file>"
echo ""
fi
exit 0