26 lines
789 B
PowerShell
26 lines
789 B
PowerShell
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)
|
|
} |