flea/commit-all.sh
ruberoid 18d8f59673
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Доабвил скрипт автокоммита субмодулей. #7
2025-10-16 17:52:31 +04:00

92 lines
2.5 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Check if commit message is provided
if [ -z "$1" ]; then
echo "Error: Commit message is required"
echo "Usage: ./commit-all.sh \"Your commit message\""
exit 1
fi
COMMIT_MSG="$1"
# Get list of submodules
SUBMODULES=$(git config --file .gitmodules --get-regexp path | awk '{ print $2 }')
if [ -z "$SUBMODULES" ]; then
echo "No submodules found in this repository"
exit 0
fi
echo "🚀 Starting commit and push for all submodules..."
echo "📝 Commit message: $COMMIT_MSG"
echo ""
# Counter for tracking results
SUCCESS_COUNT=0
FAILED_COUNT=0
SKIPPED_COUNT=0
# Iterate through each submodule
for submodule in $SUBMODULES; do
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📦 Processing submodule: $submodule"
if [ ! -d "$submodule" ]; then
echo "⚠️ Warning: Submodule directory not found, skipping..."
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
continue
fi
cd "$submodule" || {
echo "❌ Failed to enter directory $submodule"
FAILED_COUNT=$((FAILED_COUNT + 1))
cd - > /dev/null
continue
}
# Check if there are any changes
if [ -z "$(git status --porcelain)" ]; then
echo " No changes to commit, skipping..."
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
cd - > /dev/null
continue
fi
# Add all changes
echo " → git add -A"
git add -A
# Commit changes
echo " → git commit"
if git commit -m "$COMMIT_MSG"; then
# Push to main branch
echo " → git push origin main"
if git push origin main; then
echo "✅ Successfully committed and pushed"
SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
else
echo "❌ Failed to push"
FAILED_COUNT=$((FAILED_COUNT + 1))
fi
else
echo "❌ Failed to commit"
FAILED_COUNT=$((FAILED_COUNT + 1))
fi
cd - > /dev/null
echo ""
done
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📊 Summary:"
echo " ✅ Success: $SUCCESS_COUNT"
echo " ❌ Failed: $FAILED_COUNT"
echo " ⏭️ Skipped: $SKIPPED_COUNT"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if [ $FAILED_COUNT -gt 0 ]; then
exit 1
fi
exit 0