Skip to content

Instantly share code, notes, and snippets.

@scbedd
Created April 11, 2019 18:01
Show Gist options
  • Save scbedd/19a993ead48771170f3fa941524295e4 to your computer and use it in GitHub Desktop.
Save scbedd/19a993ead48771170f3fa941524295e4 to your computer and use it in GitHub Desktop.
Want to get a list of tags from a git repo?
Function Tags-Since([String] $datesSince = "2019-04-01") {
git rev-parse --is-inside-work-tree
if($LastExitCode -ne 0)
{
Write-Host "Please invoke this function from within a git repository folder. Exiting."
exit(1)
}
$allTags = git log --tags --simplify-by-decoration --pretty="format:%ai::%d"
$dateSince = [DateTime]::Parse($datesSince)
$tagObjects = @()
foreach($tagObject in $allTags)
{
$parts = $tagObject.Split("::")
foreach($part in $parts){ $part = $part.Trim() }
$TagRegex = "tag\: (?<tag>[^,)]*)"
$tagList = @()
Select-String $TagRegex -input $parts[1] -AllMatches `
| % { $_.matches } `
| % { $tagList += $_.Groups['tag'].Value }
$tagObjects += New-Object PSObject -Property @{
Date = [DateTime]::Parse($parts[0])
TagList = $tagList
}
}
$filteredTagObjects = $tagObjects | where { $_.TagList.Length -gt 0 -and $_.Date -ge $dateSince}
$filteredTagObjects = $filteredTagObjects | Sort-Object -Property Date -Descending
foreach($tagObj in $filteredTagObjects)
{
foreach($tag in $tagObj.TagList)
{
Write-Host $tag
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment