-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcleanup-branches.sh
More file actions
executable file
·106 lines (90 loc) · 2.71 KB
/
cleanup-branches.sh
File metadata and controls
executable file
·106 lines (90 loc) · 2.71 KB
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
101
102
103
104
105
106
#!/bin/bash
# Script to delete merged branches from the remote repository
# Run this script after verifying that all branches have been merged into main
# Verify we're running with bash
if [ -z "$BASH_VERSION" ]; then
echo "Error: This script requires bash. Please run with: bash cleanup-branches.sh"
exit 1
fi
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# List of branches to delete
branches=(
"copilot/add-qualweb-scanner-support"
"copilot/allow-engine-specification"
"copilot/consolidate-branches-into-main"
"copilot/fix-browser-launch-error"
"copilot/fix-browser-launch-error-again"
"copilot/fix-frame-detached-error"
"copilot/fix-issue-from-actions-run"
"copilot/fix-protocol-error-connection-closed"
"copilot/fix-puppeteer-connection-error"
"copilot/fix-syntax-error-in-script"
"copilot/investigate-scan-issue-41"
"copilot/merge-and-cleanup-branches"
"copilot/prepend-scan-title"
"copilot/review-report-analysis-changes"
"copilot/update-readme-instructions"
)
echo -e "${YELLOW}Branch Cleanup Script${NC}"
echo "This script will delete the following remote branches:"
echo ""
for branch in "${branches[@]}"; do
echo " - $branch"
done
echo ""
echo -e "${YELLOW}Warning: This action cannot be undone!${NC}"
echo -e "All work from these branches has been merged into main."
echo ""
read -p "Are you sure you want to continue? (yes/no): " confirm
if [ "$confirm" != "yes" ]; then
echo -e "${RED}Aborted.${NC}"
exit 1
fi
echo ""
echo -e "${GREEN}Starting branch cleanup...${NC}"
echo ""
deleted_count=0
failed_count=0
failed_branches=()
for branch in "${branches[@]}"; do
echo -n "Deleting $branch... "
# Capture both stdout and stderr to show errors if deletion fails
error_output=$(git push origin --delete "$branch" 2>&1)
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo -e "${GREEN}✓${NC}"
((deleted_count++))
else
echo -e "${RED}✗${NC}"
((failed_count++))
failed_branches+=("$branch")
# Show the error message for troubleshooting
echo " Error: $error_output"
fi
done
echo ""
echo "Cleanup complete!"
echo -e "${GREEN}Successfully deleted: $deleted_count${NC}"
if [ $failed_count -gt 0 ]; then
echo -e "${RED}Failed to delete: $failed_count${NC}"
echo ""
echo "Failed branches:"
for branch in "${failed_branches[@]}"; do
echo " - $branch"
done
echo ""
echo "These branches may have already been deleted or you may lack permissions."
fi
echo ""
echo "Pruning local remote-tracking branches..."
git fetch --prune
echo ""
echo -e "${GREEN}All done!${NC}"
echo ""
echo "Note: If you have local copies of these branches, you can delete them with:"
echo " git branch -D <branch-name>"