-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicrosoft.PowerShell_profile.ps1
34 lines (30 loc) · 1.28 KB
/
Microsoft.PowerShell_profile.ps1
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
function Check-Branch-Remote{
$branchesRemotes = git ls-remote
$branchesLocais = git branch
$branchAtual = git rev-parse --abbrev-ref HEAD
$branchesFixos = "develop", "master", "qa"
$branchesParaRemover = @()
ForEach ($branchLocal in $branchesLocais) {
$branchLocal = $branchLocal.Trim().replace("* ", "")
$contemBranch = 0
ForEach($branchRemoto in $branchesRemotes){
if ($branchRemoto.contains($branchLocal)){
$contemBranch = 1;
}
}
if ($contemBranch.Equals(0) -And $branchLocal -notcontains $branchAtual.Trim() -And $branchesFixos -notcontains $branchLocal){
$branchesParaRemover += $branchLocal.Trim()
}
}
echo "======================================================"
echo "Foram encontrados $($branchesParaRemover.Length) branches para remover localmente."
echo "======================================================"
ForEach($branchRemover in $branchesParaRemover){
$resposta = Read-Host "Deseja remover localmente o branch $($branchRemover)? (S\N)"
if ($resposta.ToUpper().Equals("S")){
git branch --delete $branchRemover
echo ""
}
}
}
Set-Alias -Name clean-branches -Value Check-Branch-Remote