From 1e1ff7fd7b60ae47d4bb6fd47f2f98f98a7f859f Mon Sep 17 00:00:00 2001 From: James Brundage <+@noreply.github.com> Date: Fri, 27 Sep 2024 21:21:10 -0700 Subject: [PATCH] feat: git.log.Trailer ( Fixes #305 ) --- Extensions/Git.Log.UGit.Extension.ps1 | 17 +---------------- Types/git.log/Alias.psd1 | 1 + Types/git.log/get_Trailer.ps1 | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 16 deletions(-) create mode 100644 Types/git.log/get_Trailer.ps1 diff --git a/Extensions/Git.Log.UGit.Extension.ps1 b/Extensions/Git.Log.UGit.Extension.ps1 index c4264586..4028a8b5 100644 --- a/Extensions/Git.Log.UGit.Extension.ps1 +++ b/Extensions/Git.Log.UGit.Extension.ps1 @@ -111,22 +111,7 @@ begin { if ($gitLogOut.CommitMessage -match 'into (?.+)$') { $gitLogOut.Destination = $matches.Branch } - } - - if ($gitLogOut.CommitMessage) { - $gitTrailers = [Ordered]@{} - foreach ($commitMessageLine in $gitLogOut.CommitMessage -split '(?>\r\n|\n)') { - if ($commitMessageLine -notmatch '\s{0,}(?\S+):\s(?[\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]]') { diff --git a/Types/git.log/Alias.psd1 b/Types/git.log/Alias.psd1 index a40eb80b..16c1172e 100644 --- a/Types/git.log/Alias.psd1 +++ b/Types/git.log/Alias.psd1 @@ -1,3 +1,4 @@ @{ Notes = 'Note' + Trailers = 'Trailer' } \ No newline at end of file diff --git a/Types/git.log/get_Trailer.ps1 b/Types/git.log/get_Trailer.ps1 new file mode 100644 index 00000000..c96cad85 --- /dev/null +++ b/Types/git.log/get_Trailer.ps1 @@ -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,}(?\S+):\s(?[\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 \ No newline at end of file