blob: 5deb6479e1d6da025629f8313469049a510e6772 (
plain)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
{{define "deleteScriptPreamble"}}#!/bin/bash
# Gitsyncer - Delete Abandoned Branches Script
# Generated on: {{.GeneratedAt}}
# Total branches to delete: {{.TotalAbandoned}} regular + {{.TotalIgnored}} ignored = {{.TotalBranches}} total
#
# ⚠️ WARNING: This script will permanently delete branches!
# Review carefully before executing.
#
# Usage:
# bash {{.ScriptBaseName}} # Delete branches (with confirmation)
# bash {{.ScriptBaseName}} --dry-run # Preview what will be deleted
# bash {{.ScriptBaseName}} --review # Review diffs before deletion
# bash {{.ScriptBaseName}} --review-full # Review full diffs
# Parse command line arguments
MODE="delete"
if [[ "$1" == "--dry-run" ]]; then
MODE="dry-run"
elif [[ "$1" == "--review" ]]; then
MODE="review"
elif [[ "$1" == "--review-full" ]]; then
MODE="review-full"
fi
# Color codes for better readability
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Helper function to execute or print commands
execute_cmd() {
if [[ "$MODE" == "dry-run" ]]; then
echo " [DRY RUN] $@"
else
echo " Executing: $@"
"$@"
fi
}
# Function to find main/master branch
find_main_branch() {
if git rev-parse --verify main >/dev/null 2>&1; then
echo "main"
elif git rev-parse --verify master >/dev/null 2>&1; then
echo "master"
else
echo ""
fi
}
# Function to review branch diff
review_branch() {
local branch="$1"
local main_branch="$2"
local last_commit="$3"
local branch_type="$4"
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${YELLOW}Branch:${NC} $branch ${PURPLE}[$branch_type]${NC}"
echo -e "${YELLOW}Last commit:${NC} $last_commit"
echo -e "${YELLOW}Comparing against:${NC} $main_branch"
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
# Check if branch exists locally
if ! git rev-parse --verify "$branch" >/dev/null 2>&1; then
echo -e "${RED}⚠️ Branch '$branch' not found locally${NC}"
return
fi
echo -e "${GREEN}📊 Diff statistics:${NC}"
git diff --stat "$main_branch"..."$branch"
echo
echo -e "${GREEN}📝 Commits in this branch:${NC}"
git log --oneline --graph "$main_branch".."$branch" | head -20
if [[ "$MODE" == "review-full" ]]; then
echo
echo -e "${GREEN}🔍 Full diff:${NC}"
git diff "$main_branch"..."$branch"
fi
echo
}
# Main script logic
case "$MODE" in
"dry-run")
echo "🔍 DRY RUN MODE - No branches will be deleted"
echo
;;
"review"|"review-full")
echo -e "${CYAN}🔍 Gitsyncer - Abandoned Branch Review${NC}"
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "Found ${YELLOW}{{.TotalBranches}}${NC} abandoned branches to review"
echo
;;
"delete")
echo "⚠️ This script will delete {{.TotalBranches}} abandoned branches across {{.RepositoryCount}} repositories."
read -p "Are you sure you want to continue? (yes/no): " confirm
if [[ "$confirm" != "yes" ]]; then
echo "Aborted."
exit 0
fi
echo
;;
esac
{{end}}
{{define "deleteScriptFooter"}}echo
echo "✅ Script completed!"
case "$MODE" in
"dry-run")
echo "This was a dry run. No branches were deleted."
echo "To actually delete branches, run: bash {{.ScriptBaseName}}"
;;
"review"|"review-full")
echo "Review completed. No branches were deleted."
echo "To delete branches, run: bash {{.ScriptBaseName}}"
;;
"delete")
echo "All abandoned branches have been deleted."
;;
esac
{{end}}
|