-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathdelete-merged-branches.ps1
More file actions
269 lines (246 loc) · 8.19 KB
/
Copy pathdelete-merged-branches.ps1
File metadata and controls
269 lines (246 loc) · 8.19 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<#
.SYNOPSIS
Delete remote branches that are fully merged into origin/main.
.DESCRIPTION
Generated 2026-05-12 from `git branch -r --merged origin/main`.
Default is DRY-RUN: prints `git push --delete` commands without running
them. Pass -Execute to actually delete the branches on origin.
Branches are grouped into three tiers so you can review and run
selectively:
Tier 1: 2017 + 2022-era long tail (117 branches) - safest
Tier 2: 4-11 month-old stale (5 branches)
Tier 3: Active-era, < 30 days old (8 branches) - opt-in only
Tier 3 is OFF by default because some of those branches may still be
in flight even though their commits are reachable from main (e.g.,
branches that were merged but you haven't deleted yet because you're
still iterating on follow-ups).
.PARAMETER Execute
Actually run the deletions. Without this switch, only prints what
would happen.
.PARAMETER IncludeActiveEra
Include Tier 3 (active-era branches). Off by default.
.PARAMETER SkipTier1
Skip the 2017 + 2022 long tail.
.PARAMETER SkipTier2
Skip the 4-11 month-old stale branches.
.EXAMPLE
.\delete-merged-branches.ps1
Dry-run Tier 1 + Tier 2. Recommended first step.
.EXAMPLE
.\delete-merged-branches.ps1 -Execute
Actually delete Tier 1 + Tier 2 (122 branches).
.EXAMPLE
.\delete-merged-branches.ps1 -SkipTier1
Dry-run only Tier 2.
.EXAMPLE
.\delete-merged-branches.ps1 -Execute -IncludeActiveEra
Delete all 130 merged branches (Tiers 1, 2, and 3).
.NOTES
Squash-merged PRs will NOT appear here. `--merged` only catches
branches whose original commits are reachable from main; squash-merge
creates new SHAs, so the source branch looks "unmerged" to git even
though its diff has landed.
#>
[CmdletBinding()]
param(
[switch]$Execute,
[switch]$IncludeActiveEra,
[switch]$SkipTier1,
[switch]$SkipTier2
)
# ---------------------------------------------------------------------------
# Tier 1: 2017 + 2022 long tail (117 branches)
# All older than 1.5 years. Hooks/themes/properties/docs experimentation
# era, plus a couple of 2017 cycle-grammar attempts.
# ---------------------------------------------------------------------------
$Tier1 = @(
'ActiveAndTerminalState',
'AddHistoryAndCircularBuffer',
'AddHooksToReadme',
'AddInlineStylesToResolver',
'AddKitchenSinkBenchmark',
'AddShootout',
'AddUnicodeTestsForLabels',
'AllowHooksToChangeData',
'AllowsOverrideInCompiler',
'ApiAllActionHook',
'ApiEntryHooks',
'ApiExitHooks',
'ApiForcedTransitionHook',
'ApiGlobalNamedHooks',
'ApiStandardTransitionHook',
'AttemptInterRepoGhaThroughCurl',
'AttemptInterRepoGhaThroughCurl2',
'AttemptToCaptureTestResults',
'AttemptToCorrectQualityDrop',
'AttemptToCorrectQualityDrop2',
'AttemptToFixAstral',
'BoldTheme',
'BrowserFieldAndWhatAreSmTutScratch',
'BumpCloc',
'BumpTsAndTooling',
'BumpTypedocAndBumpCiNodeVersion',
'BundleEs6Export',
'CleanUpTsConfig',
'CleanupStuff',
'CyclesAndStripes',
'DisplayText',
'DocArrUniqP',
'DocCss',
'DocFromSm',
'DocIsFinalAndStateIsFinal',
'DocStubs',
'Doc_Action_Transition_ForceTransition',
'Doc_Actions_ListStatesHavingAction',
'Doc_ListEdges_ListTransitions_ListEntrances_ListExits',
'Doc_State_States_HasState',
'DocumentArrowDirection',
'ErrorObject',
'ExportFieldsForCdnPkg',
'ExposeColors',
'ExposeShapes',
'ExposeThemesAndDirections',
'ExtensionUpdates',
'FinalizeDenoSupport',
'FinishComparisonMatrix',
'FirstStepsToOperatorAfter',
'Fix1259PossibleDataLoss',
'FixActionsOnActionlessStates',
'FixCarryProblemInTimers',
'FixChangelogAndAddCommunityPage',
'FluentAllActionHook',
'FluentEntryHooks',
'FluentExitHooks',
'FluentGlobalNamedHooks',
'FluentTransitionHooks',
'GateOffBranchDeploy',
'GateOffBranchDeploy2',
'HookActionsConvenienceApi',
'HookAllTransitions',
'HooksConvenienceApi',
'ImproveBenchmark',
'ImproveDocumentationLayout',
'ImproveErrorsAndCreateInstanceNamesAndMakeFrom',
'ImproveFlagGatingHooks',
'ImproveGhActionsParallelism',
'IntroducingTheKitchenSinkDragon',
'LanguageReference',
'MissingModuleTypeInPackage',
'MoreComparisonChart',
'MoreDocumentation',
'MoreShootout',
'MoreStabsAtTweeting',
'MoreTryingToFixTwitterTweeter',
'MovingToAbstractHooks',
'NewGraphicAssets',
'PostHooks',
'PreventArrangeOfNonNodes',
'Properties',
'PropertiesInGrammar',
'PropertiesSupportStringDefaults',
'PullArrowsOutIntoModules',
'PullCompilerOutIntoModule',
'PullThemesOutIntoModule',
'PutClocMetricsInReadme',
'ReAddNode11and12',
'ReattemptDenoSupport',
'ReintroduceDisplayText',
'RemoveNode11and12FromGhActions',
'RemoveYmlEcho',
'RenameParserAlready',
'RequiredProperties',
'Serialize',
'SetHooksWithExplicitAction',
'SetInitialState',
'SpinUpThemes',
'StartStateRefining',
'StartTweetingInGha',
'StillMoreShootout',
'StrictProp',
'SupportForStartAndEndStateStyling',
'SynonymDoForAction',
'SynonymGoForTransition',
'ToolClocForReadme',
'TrimTweet',
'TryBenchingWithBenny',
'TwitterStepAndLineRunRatio',
'UnifyTransitionAndAction',
'UnifyTransitionAndForceTransition',
'UpdateTsAndTypeDocAndTsEslintPlugins',
'UpdateWorkflowNodeVersions',
'allows_override',
'attempt-bump-jssm-viz',
'next_data',
'uses_forced_transitions'
)
# ---------------------------------------------------------------------------
# Tier 2: 4-11 month-old stale (5 branches)
# Older than current iteration, newer than the long tail.
# ---------------------------------------------------------------------------
$Tier2 = @(
'AddAfterHooks',
'ModernizeRollup',
'VersionCheckDeserialize_1010',
'add-claude-github-actions-1769662812820',
'types-fixes-2'
)
# ---------------------------------------------------------------------------
# Tier 3: Active-era, < 30 days (7 branches) - OPT-IN
# These are recent. Even though `git branch --merged` says their commits
# are on main, you may still be iterating on follow-up work. Review each.
# ---------------------------------------------------------------------------
$Tier3 = @(
'DescribeAndRepairGrammar', # 22 hours ago
'EmbraceJssmViz', # 8 days ago
'GetSeriousAboutStochastics', # 13 hours ago
'SwitchToSwc', # 8 days ago
'fix/duplicate-gamma-jsnumericliteral', # 8 days ago
'worktree-agent-a1ccd7b21aa5d435d', # 9 hours ago
'worktree-agent-a8f7f97a2228b321b' # 9 hours ago
)
function Remove-RemoteBranch {
param([string]$Branch)
if ($Execute) {
Write-Host " Deleting origin/$Branch" -ForegroundColor Yellow
git push origin --delete $Branch
if (-not $?) {
Write-Host " ! Failed (continuing)" -ForegroundColor Red
}
} else {
Write-Host " [dry-run] git push origin --delete $Branch" -ForegroundColor Cyan
}
}
function Invoke-Tier {
param(
[string]$Name,
[string[]]$Branches,
[string]$Color = 'Green'
)
Write-Host ""
Write-Host "=== $Name ($($Branches.Count) branches) ===" -ForegroundColor $Color
foreach ($b in $Branches) {
Remove-RemoteBranch -Branch $b
}
}
$mode = if ($Execute) { 'EXECUTE' } else { 'DRY-RUN' }
Write-Host ""
Write-Host "Mode: $mode" -ForegroundColor $(if ($Execute) { 'Red' } else { 'Cyan' })
$total = 0
if (-not $SkipTier1) {
Invoke-Tier -Name 'Tier 1: 2017 + 2022 long tail' -Branches $Tier1
$total += $Tier1.Count
}
if (-not $SkipTier2) {
Invoke-Tier -Name 'Tier 2: 4-11 month stale' -Branches $Tier2
$total += $Tier2.Count
}
if ($IncludeActiveEra) {
Invoke-Tier -Name 'Tier 3: Active-era (OPT-IN)' -Branches $Tier3 -Color 'Yellow'
$total += $Tier3.Count
}
$verb = if ($Execute) { 'deleted' } else { 'would delete' }
Write-Host ""
Write-Host "Total: $verb $total branches." -ForegroundColor Magenta
if (-not $Execute) {
Write-Host "Re-run with -Execute to actually delete." -ForegroundColor Cyan
}