ps/Modules/Cole.PowerShell.Developer/Public/Get-GitBranchNames.ps1

26 lines
789 B
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function Get-GitBranchNames {
<#
.SYNOPSIS
Get the branch names for a given repository path, if it is a repository
.PARAMETER Path
The file path to check. Can be presumed as the current folder.
#>
param(
$Path = ((Get-Location).Path)
)
$return = @()
$Path = (Find-GitRepoRootFromPath -Path $Path)
$branches = (Get-ChildItem -Path (Join-Path -Path $Path -ChildPath ".git\refs\heads" -Resolve) -Recurse -File).FullName
foreach($branch in $branches) {
# This could be rooted _under_ heads by several folders
# It might be faster to Read-GitConfig and look at branch.name but filesystems are usually pretty fast
$return += ($branch -split 'heads')[1].Substring(1).Replace('\','/')
}
return ($return | Sort-Object)
}