the-custodian/tools/push_repo_classifications.sh

45 lines
1 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# Push unpushed .repo-classification.yaml commits across local ecosystem repos.
set -euo pipefail
HOME_REPOS="${HOME}"
PUSHED=0
SKIPPED=0
FAILED=0
FAILED_NAMES=()
for dir in "$HOME_REPOS"/*/; do
[ -d "$dir/.git" ] || continue
[ -f "$dir/.repo-classification.yaml" ] || continue
name=$(basename "$dir")
cd "$dir"
if ! git rev-parse --abbrev-ref HEAD >/dev/null 2>&1; then
continue
fi
branch=$(git rev-parse --abbrev-ref HEAD)
ahead=$(git rev-list --count "@{u}..HEAD" 2>/dev/null || echo "no-upstream")
if [ "$ahead" = "no-upstream" ] || [ "$ahead" = "0" ]; then
SKIPPED=$((SKIPPED + 1))
continue
fi
echo "Pushing $name ($branch, $ahead commit(s))..."
if git push origin "$branch" 2>&1; then
PUSHED=$((PUSHED + 1))
else
FAILED=$((FAILED + 1))
FAILED_NAMES+=("$name")
fi
done
echo ""
echo "Summary: pushed=$PUSHED skipped=$SKIPPED failed=$FAILED"
if [ "${#FAILED_NAMES[@]}" -gt 0 ]; then
echo "Failed:"
printf ' %s\n' "${FAILED_NAMES[@]}"
exit 1
fi