-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean_branches.ps1
More file actions
31 lines (24 loc) · 794 Bytes
/
clean_branches.ps1
File metadata and controls
31 lines (24 loc) · 794 Bytes
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
param(
[switch][Alias("h")] $Help, # include to display the help message and then exit
[switch][Alias("Test", "t")] $TestRun # test-run, don't create merge
)
if($Help){
# call the Get-Help
Get-Help $MyInvocation.MyCommand.Path
exit 0
}
if($TestRun){
"-------- TEST RUN STARTING: --------" | Write-Host -ForegroundColor "yellow"
}
$branchOutput = git branch -a -vv
$branchesToDelete = $branchOutput | Select-String -Pattern '\s*(\S+)\s+\S+\s+\[.*: gone\]' | ForEach-Object { $_.Matches.Groups[1].Value }
if($TestRun){
$branchesToDelete | Write-Host
"Test Run Exiting" | Write-Host -ForegroundColor "green"
exit 0
}
$branchesToDelete | ForEach-Object {
$branchName = $_
Write-Host "Deleting branch : $branchName"
git branch -D $branchName
}