146 lines
3.6 KiB
Bash
Executable file
146 lines
3.6 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Delete remote master branches after Forgejo default branch is updated
|
|
set -euo pipefail
|
|
|
|
# ANSI color codes
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Repos with remote master branches to delete
|
|
REPOS_WITH_REMOTE_MASTER=(
|
|
"@audio/tts-client"
|
|
"@cli/bitch-cli"
|
|
"@config/yaml-config"
|
|
"@configs/python"
|
|
"@ml/agent-loader"
|
|
"@ml/provider-clients"
|
|
"@mcp/mcp-common"
|
|
"@mcp/mcp-domain-checker"
|
|
"@mcp/mcp-domain-checker-price"
|
|
"@mcp/mcp-gitlab-ci"
|
|
"@mcp/mcp-opener"
|
|
"@mcp/mcp-stream-workflow"
|
|
"@mcp/mcp-stream-workflow-status"
|
|
"@mcp/stream-workflow-status-dashboard"
|
|
)
|
|
|
|
# Base directory
|
|
PACKAGES_BASE="/var/home/lilith/Code/@packages"
|
|
|
|
# Statistics
|
|
SUCCESS_COUNT=0
|
|
SKIP_COUNT=0
|
|
FAIL_COUNT=0
|
|
|
|
log_info() {
|
|
echo -e "${GREEN}[INFO]${NC} $1"
|
|
}
|
|
|
|
log_warn() {
|
|
echo -e "${YELLOW}[WARN]${NC} $1"
|
|
}
|
|
|
|
log_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
log_step() {
|
|
echo -e "${BLUE}[STEP]${NC} $1"
|
|
}
|
|
|
|
# Delete remote master branch
|
|
delete_remote_master() {
|
|
local repo=$1
|
|
log_step "Deleting remote master for $repo..."
|
|
|
|
cd "$PACKAGES_BASE/$repo" || {
|
|
log_error " Failed to cd to $repo"
|
|
FAIL_COUNT=$((FAIL_COUNT + 1))
|
|
return 1
|
|
}
|
|
|
|
# Check if remote master exists
|
|
if ! git ls-remote --heads origin | grep -q "refs/heads/master"; then
|
|
log_warn " Remote master branch doesn't exist, skipping"
|
|
SKIP_COUNT=$((SKIP_COUNT + 1))
|
|
cd "$PACKAGES_BASE"
|
|
return 0
|
|
fi
|
|
|
|
# Verify we're on main branch
|
|
current_branch=$(git branch --show-current)
|
|
if [[ "$current_branch" != "main" ]]; then
|
|
log_error " Not on main branch (currently on $current_branch) - skipping"
|
|
SKIP_COUNT=$((SKIP_COUNT + 1))
|
|
cd "$PACKAGES_BASE"
|
|
return 1
|
|
fi
|
|
|
|
# Delete remote master branch
|
|
if git push origin --delete master 2>&1; then
|
|
log_info " ✓ Deleted remote master branch"
|
|
SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
|
|
else
|
|
log_error " Failed to delete remote master branch"
|
|
log_warn " This may mean Forgejo default branch is still set to master"
|
|
FAIL_COUNT=$((FAIL_COUNT + 1))
|
|
cd "$PACKAGES_BASE"
|
|
return 1
|
|
fi
|
|
|
|
log_info " ${GREEN}✓ Cleanup complete for $repo${NC}"
|
|
|
|
cd "$PACKAGES_BASE"
|
|
return 0
|
|
}
|
|
|
|
# Main execution
|
|
main() {
|
|
log_step "=== Delete Remote Master Branches ==="
|
|
echo ""
|
|
|
|
# Warning before proceeding
|
|
echo -e "${YELLOW}⚠️ IMPORTANT: Ensure Forgejo default branch is updated to 'main' first!${NC}"
|
|
echo -e "${YELLOW} Deleting master before updating Forgejo will break the repos.${NC}"
|
|
echo ""
|
|
echo -e "${YELLOW}Have you updated the default branch in Forgejo for ALL 14 repos?${NC}"
|
|
echo -e "${YELLOW}Press Ctrl+C to cancel, or type 'yes' to continue...${NC}"
|
|
read -r confirmation
|
|
|
|
if [[ "$confirmation" != "yes" ]]; then
|
|
log_warn "Cancelled. Update Forgejo default branches first."
|
|
exit 0
|
|
fi
|
|
|
|
log_step "Deleting remote master branches for 14 repos..."
|
|
echo ""
|
|
|
|
for repo in "${REPOS_WITH_REMOTE_MASTER[@]}"; do
|
|
delete_remote_master "$repo"
|
|
echo ""
|
|
done
|
|
|
|
# Summary
|
|
echo ""
|
|
log_step "=== Deletion Summary ==="
|
|
echo -e "${GREEN}✓ Successful: $SUCCESS_COUNT${NC}"
|
|
echo -e "${YELLOW}⊘ Skipped: $SKIP_COUNT${NC}"
|
|
echo -e "${RED}✗ Failed: $FAIL_COUNT${NC}"
|
|
echo ""
|
|
|
|
if [[ $FAIL_COUNT -eq 0 ]]; then
|
|
log_info "All remote master branches deleted successfully!"
|
|
echo ""
|
|
echo -e "${YELLOW}Next step:${NC}"
|
|
echo "Run verification: ./scripts/git/git-repo-status.sh | grep -i master"
|
|
else
|
|
log_warn "Some deletions failed. Check the output above for details."
|
|
echo "Failed repos may still have Forgejo default branch set to master."
|
|
fi
|
|
}
|
|
|
|
# Run main
|
|
main
|