Skip to content

Instantly share code, notes, and snippets.

@Szer
Last active May 13, 2019 11:42
Show Gist options
  • Select an option

  • Save Szer/06cd05e3422f0dbf05e4d87ee65d1a1f to your computer and use it in GitHub Desktop.

Select an option

Save Szer/06cd05e3422f0dbf05e4d87ee65d1a1f to your computer and use it in GitHub Desktop.
Tag cleanup
function CleanupTags {
param([string]$repo)
<#work directory should be repo root#>
cd $repo
git fetch "origin"
git reset --hard origin/master
"getting tags list..."
<#listing all remote branches which were merged into master#>
$tagsToDelete =
git for-each-ref --sort=taggerdate --format '%(refname:short)||%(taggerdate)' refs/tags `
| Select-Object @{ n="Ref"; e={$_.Split("||", [System.StringSplitOptions]::RemoveEmptyEntries)[0]} }, `
@{ n="Date"; e={$_.Split("||", [System.StringSplitOptions]::RemoveEmptyEntries)[1]} } `
| ? { $_.Ref -notlike "superman-ci*" } `
| %{$_.Ref} `
| select -First 10 <#delete this line when go to production#>
workflow DeleteTags {
param([string[]] $tags,
[string] $repo)
foreach -parallel -throttlelimit 10 ($tag in $tags) {
InlineScript {
Set-Location $Using:repo
"working on $Using:tag"
<#delete reference from origin#>
git push --delete origin $Using:tag
}
}
}
DeleteTags -tags $tagsToDelete -repo $repo
}
CleanupTags "C:\dev\superman"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment