Skip to content

Commit

Permalink
feat: git.log.Trailer ( Fixes #305 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Sep 28, 2024
1 parent a1fdc55 commit 1e1ff7f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
17 changes: 1 addition & 16 deletions Extensions/Git.Log.UGit.Extension.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,7 @@ begin {
if ($gitLogOut.CommitMessage -match 'into (?<Branch>.+)$') {
$gitLogOut.Destination = $matches.Branch
}
}

if ($gitLogOut.CommitMessage) {
$gitTrailers = [Ordered]@{}
foreach ($commitMessageLine in $gitLogOut.CommitMessage -split '(?>\r\n|\n)') {
if ($commitMessageLine -notmatch '\s{0,}(?<k>\S+):\s(?<v>[\s\S]+$)') {
continue
}
if (-not $gitTrailers[$matches.k]) {
$gitTrailers[$matches.k] = $matches.v
} else {
$gitTrailers[$matches.k] = @($gitTrailers[$matches.k]) + $v
}
}
$gitLogOut.Trailers = $gitTrailers
}
}

if ($GitArgument -contains '--shortstat' -or $GitArgument -contains '--stat') {
foreach ($linePart in $OutputLines[-2] -split ',' -replace '[\s\w\(\)-[\d]]') {
Expand Down
1 change: 1 addition & 0 deletions Types/git.log/Alias.psd1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@{
Notes = 'Note'
Trailers = 'Trailer'
}
23 changes: 23 additions & 0 deletions Types/git.log/get_Trailer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<#
.SYNOPSIS
Gets the trailer of a commit
.DESCRIPTION
Gets the trailers of a commit. Git trailers are key-value pairs that are appended to the end of a commit message.
.LINK
https://git-scm.com/docs/git-interpret-trailers
#>

$lineNumber = 0
$gitTrailers = [Ordered]@{}
foreach ($commitMessageLine in $this.CommitMessage -split '(?>\r\n|\n)') {
$lineNumber++
if ($commitMessageLine -notmatch '\s{0,}(?<k>\S+):\s(?<v>[\s\S]+$)' -or $lineNumber -eq 1) {
continue
}
if (-not $gitTrailers[$matches.k]) {
$gitTrailers[$matches.k] = $matches.v
} else {
$gitTrailers[$matches.k] = @($gitTrailers[$matches.k]) + $v
}
}
return $gitTrailers

0 comments on commit 1e1ff7f

Please sign in to comment.