Last active
May 17, 2018 17:04
-
-
Save chestercodes/7636ba878692f442f956 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
write-error "probably best to not execute" | |
exit 1 | |
cd C:\Dev\Abide\Abide.Digby | |
$archiveFolderName = "z-archive" | |
$oldUnmergedBranches = New-Object System.Collections.ArrayList | |
foreach($branch in git branch -r --no-merged master ) | |
{ | |
if($branch.Contains( "-> origin/master") -eq $false -and ($branch.Contains("$archiveFolderName/") -eq $false) ) | |
{ | |
$lastCommitDateStr = git log --pretty=format:"%aD" -1 $branch.Trim() | |
$lastCommitDate = [DateTime]::Parse($lastCommitDateStr) | |
#Write-Host "Last commit was on $lastCommitDate" | |
if($lastCommitDate -lt (Get-Date).AddMonths(-6) ) | |
{ | |
$oldUnmergedBranches.Add($branch.Trim()) | |
} | |
} | |
} | |
$oldUnmergedBranches.Sort() | |
Write-Host "Going to rename these branches:" | |
foreach($b in $oldUnmergedBranches){ | |
"$b" | |
} | |
$yesOrSomethingElse = Read-Host -Prompt "Enter 'y' to archive branches" | |
if($yesOrSomethingElse.ToLower() -ne "y") | |
{ | |
return | |
} | |
$askToProceed = $true | |
foreach($oldWhole in $oldUnmergedBranches){ | |
$branchName = $oldWhole.Replace("origin/", "") | |
$newBranchName = "$archiveFolderName/$branchName" | |
"Archiving branch $branchName" | |
if($askToProceed){ | |
$yesOrSomethingElse = Read-Host -Prompt "proceed?" | |
if($yesOrSomethingElse.ToLower() -ne "y") | |
{ | |
return | |
} | |
} | |
"running git push origin origin/$branchName`:refs/heads/$newBranchName :$branchName" | |
"git push origin origin/$branchName`:refs/heads/$newBranchName :$branchName" | |
if($askToProceed) | |
{ | |
$yesOrSomethingElse = Read-Host -Prompt "Want to let rip?" | |
if($yesOrSomethingElse.ToLower() -eq "y") | |
{ | |
$askToProceed = $false | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment