@@ -123,6 +123,116 @@ function Get-GitLongOptionCompletions {
123123 }
124124}
125125
126+ function Format-GitAliasDefinitionSafe {
127+ param (
128+ [AllowEmptyString ()]
129+ [string ]$Definition
130+ )
131+
132+ if ([string ]::IsNullOrWhiteSpace($Definition )) {
133+ return ' '
134+ }
135+
136+ $definitionLines = $Definition.Trim () -split " `r ?`n " | ForEach-Object {
137+ $rawLine = [string ]$_
138+ $line = $rawLine.TrimEnd ()
139+ if ($rawLine -match " ^`t " ) {
140+ if ($line.Length -ge 1 ) {
141+ return $line.Substring (1 )
142+ }
143+
144+ return ' '
145+ }
146+ if ($rawLine -match ' ^ ' ) {
147+ if ($line.Length -ge 4 ) {
148+ return $line.Substring (4 )
149+ }
150+
151+ return ' '
152+ }
153+
154+ return $line
155+ }
156+
157+ return ($definitionLines -join " `n " )
158+ }
159+
160+ function Get-GitAliasEntries {
161+ $blacklist = @ (
162+ ' Get-Git-CurrentBranch' ,
163+ ' Remove-Alias' ,
164+ ' Format-AliasDefinition' ,
165+ ' Get-Git-Aliases' ,
166+ ' Write-Host-Deprecated' ,
167+ ' Format-GitAliasDefinitionSafe' ,
168+ ' Get-GitAliasEntries'
169+ )
170+
171+ $modulePriority = @ {
172+ ' GitAliases.Extras' = 0
173+ ' git-aliases' = 1
174+ }
175+
176+ $entries = @ ()
177+ $aliasNamePattern = ' ^g[0-9A-Za-z!]+$'
178+ foreach ($moduleName in @ (' GitAliases.Extras' , ' git-aliases' )) {
179+ $commands = Get-Command - Module $moduleName - ErrorAction SilentlyContinue |
180+ Where-Object {
181+ $_.Name -notin $blacklist -and
182+ $_.CommandType -in @ (' Function' , ' Alias' ) -and
183+ $_.Name -match $aliasNamePattern
184+ }
185+
186+ foreach ($command in $commands ) {
187+ $definition = switch ($command.CommandType ) {
188+ ' Alias' { " Alias -> $ ( $command.Definition ) " }
189+ default { Format-GitAliasDefinitionSafe - Definition $command.Definition }
190+ }
191+
192+ if ([string ]::IsNullOrWhiteSpace($definition )) {
193+ continue
194+ }
195+
196+ $entries += [PSCustomObject ]@ {
197+ Name = $command.Name
198+ Definition = $definition
199+ ModuleName = $moduleName
200+ Priority = $modulePriority [$moduleName ]
201+ }
202+ }
203+ }
204+
205+ return $entries |
206+ Sort-Object Priority, Name |
207+ Group-Object Name |
208+ ForEach-Object { $_.Group [0 ] } |
209+ Sort-Object Name
210+ }
211+
212+ function Get-Git-Aliases {
213+ [CmdletBinding ()]
214+ param (
215+ [AllowEmptyString ()]
216+ [string ]$Alias
217+ )
218+
219+ $Alias = if ($null -eq $Alias ) { ' ' } else { $Alias.Trim () }
220+ $aliases = Get-GitAliasEntries
221+
222+ if (-not ([string ]::IsNullOrWhiteSpace($Alias ))) {
223+ $foundAlias = $aliases | Where-Object { $_.Name -eq $Alias } | Select-Object - First 1
224+ if ($null -eq $foundAlias ) {
225+ Write-Error " Alias '$Alias ' not found." - ErrorAction Stop
226+ }
227+
228+ return $foundAlias.Definition
229+ }
230+
231+ return $aliases |
232+ Select-Object Name, ModuleName, Definition |
233+ Format-Table - AutoSize - Wrap
234+ }
235+
126236
127237# --- Custom Git Command Functions ---
128238function UpMerge {
0 commit comments