Skip to content

Commit 53292ff

Browse files
Merge pull request #55 from StartAutomating/ugitShortlogAndBugfixes
Ugit shortlog and bugfixes
2 parents ec70e83 + 5f6fb01 commit 53292ff

23 files changed

+718
-167
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.2.1:
2+
* Adding support for git shortlog (#48)
3+
* Adding .GitRoot to git reflog (#53)
4+
* Extension documentation cleanup (#54)
5+
---
6+
17
## 0.2.0:
28
* Adding support for git reflog (#51)
39
---

Extensions/Git.Branch.UGit.Extension.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
Where-Object BranchName -NotIn 'main', 'master' | # and the name is not either main or master
1212
git branch -d # then attempt to delete the branch.
1313
#>
14-
# It's an extension for Out-Git
15-
[Management.Automation.Cmdlet("Out","Git")]
16-
# when the pattern is "git branch"
17-
[ValidatePattern("^git branch",Options='IgnoreCase')]
14+
[Management.Automation.Cmdlet("Out","Git")] # It's an extension for Out-Git
15+
[ValidatePattern("^git branch",Options='IgnoreCase')] # when the pattern is "git branch"
1816
[OutputType('git.branch', 'git.branch.deleted','git.branch.detail')]
1917
param()
2018

Extensions/Git.Diff.UGit.Extension.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
.Description
55
Outputs git diff entries as objects
66
#>
7-
# It extends Out-Git
8-
[Management.Automation.Cmdlet("Out","Git")]
9-
# when the pattern is "git diff"
10-
[ValidatePattern("^git diff",Options='IgnoreCase')]
7+
[Management.Automation.Cmdlet("Out","Git")] # It extends Out-Git
8+
[ValidatePattern("^git diff",Options='IgnoreCase')] # when the pattern is "git diff"
119
[OutputType('Git.Diff','Git.Diff.ChangeSet')]
1210
param()
1311

Extensions/Git.FileOutput.UGit.Extension.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
.EXAMPLE
99
git archive -o My.zip
1010
#>
11-
# It's an extension for Out-Git
12-
[Management.Automation.Cmdlet("Out","Git")]
13-
# that is run when the switch -o is used.
14-
[ValidatePattern("-o\s{0}")]
11+
[Management.Automation.Cmdlet("Out","Git")] # It's an extension for Out-Git
12+
[ValidatePattern("-o\s{0}")] # that is run when the switch -o is used.
1513
param(
1614
)
1715

Extensions/Git.Log.UGit.Extension.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
.EXAMPLE
1111
git log | Group-Object { $_.CommitDate.DayOfWeek } -NoElement
1212
#>
13-
# It's an extension for Out-Git
14-
[Management.Automation.Cmdlet("Out","Git")]
15-
# when the pattern is "git log"
16-
[ValidatePattern("^git log",Options='IgnoreCase')]
13+
[Management.Automation.Cmdlet("Out","Git")] # It's an extension for Out-Git
14+
[ValidatePattern("^git log",Options='IgnoreCase')] # when the pattern is "git log"
1715
param(
1816
)
1917

Extensions/Git.RefLog.UGit.Extension.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ end {
3232
$matched = $refLogLine -match $refLogRegex
3333
$refExtract = [Ordered]@{} + $matches
3434
$refExtract.Remove(0)
35+
$refExtract.GitRoot = $GitRoot
3536
$refExtract.PSTypeName = 'Git.Reference.Log'
3637
[PSCustomObject]$refExtract
3738
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<#
2+
.SYNOPSIS
3+
git shortlog extension
4+
.DESCRIPTION
5+
Outputs git shortlog as objects
6+
.EXAMPLE
7+
git shortlog # Get a shortlog
8+
.EXAMPLE
9+
git shortlog --email # Get a shortlog with email information
10+
.EXAMPLE
11+
git shortlog --summary # Get a shortlog summary
12+
.EXAMPLE
13+
git shortlog --sumary --email # Get a shortlog summary, with email.
14+
#>
15+
[Management.Automation.Cmdlet("Out","Git")] # It's an extension for Out-Git
16+
[ValidatePattern("^git shortlog",Options='IgnoreCase')] # when the pattern is "git branch"
17+
param()
18+
19+
begin {
20+
$shortlogLines = @()
21+
22+
$SummaryLineRegex = [Regex]::new(@'
23+
^\s{1,}(?<Count>\d+)\s{1,}(?<Name>[^\<]+)(?:\<(?<Email>[^\>]+)\>){0,1}$
24+
'@,'IgnoreCase,IgnorePatternWhitespace')
25+
26+
$CommitterLineRegex = [Regex]::new(@'
27+
^(?<Name>\S[^\<\()]+)(?:\<(?<Email>[^\>]+)\>){0,1}\s{0,}\((?<Count>\d+)\)\:$
28+
'@,'IgnoreCase,IgnorePatternWhitespace')
29+
30+
$CommitMessageLineRegex = [Regex]::new('^\s{4,}(?<CommitMessage>.+)$')
31+
}
32+
33+
process {
34+
$shortlogLines += $gitOut
35+
}
36+
37+
end {
38+
$currentCommitter = $null
39+
$hadSummaries = $false
40+
foreach ($shortLogLine in $shortlogLines) {
41+
if ($shortLogLine -match $SummaryLineRegex) {
42+
$hadSummaries = $true
43+
$shortLogExtract = [Ordered]@{} + $matches
44+
$shortLogExtract.Remove(0)
45+
$shortLogExtract.GitRoot = $GitRoot
46+
$shortLogExtract.PSTypeName = 'Git.Shortlog.Summary'
47+
[PSCustomObject]$shortLogExtract
48+
} elseif ($shortlogLine -match $CommitterLineRegex) {
49+
if ($currentCommitter) {
50+
[PSCustomObject]$currentCommitter
51+
}
52+
$shortLogExtract = [Ordered]@{} + $matches
53+
$shortLogExtract.Remove(0)
54+
$shortLogExtract.Commits = @()
55+
$shortLogExtract.GitRoot = $GitRoot
56+
$shortLogExtract.PSTypeName = 'Git.Shortlog'
57+
$currentCommitter = $shortLogExtract
58+
} elseif ($currentCommitter -and
59+
$shortlogLine -match $CommitMessageLineRegex) {
60+
$currentCommitter.Commits += $matches.CommitMessage
61+
}
62+
}
63+
64+
if ($currentCommitter) {
65+
[PSCustomObject]$currentCommitter
66+
} elseif (-not $hadSummaries) {
67+
$shortlogLines
68+
}
69+
}

Formatting/Git.Reference.Log.format.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ Write-FormatView -TypeName Git.Reference.Log -Property Name, '#', Hash, Command,
77
'#' = 'Left'
88
Command ='Right'
99
Message = 'Left'
10-
}
10+
} -GroupByProperty GitRoot
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Write-FormatView -TypeName Git.Shortlog.Summary -Action {
2+
Write-FormatViewExpression -ScriptBlock {
3+
' ' * 4
4+
}
5+
Write-FormatViewExpression -ScriptBlock {
6+
$_.Count.ToString().PadLeft(3, ' ')
7+
} -ForegroundColor Verbose
8+
Write-FormatViewExpression -ScriptBlock {
9+
' ' * 2
10+
}
11+
Write-FormatViewExpression -Property Name
12+
Write-FormatViewExpression -If { $_.Email } -ScriptBlock { ' <' + $_.Email + '>' }
13+
} -GroupByProperty GitRoot
14+

Formatting/Git.Shortlog.format.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Write-FormatView -TypeName 'Git.Shortlog' -Action {
2+
Write-FormatViewExpression -Property name -ForegroundColor Success
3+
Write-FormatViewExpression -If { $_.Email } -ScriptBlock {
4+
" < " + $_.Email + ' >'
5+
} -ForegroundColor Warning
6+
Write-FormatViewExpression -ScriptBlock {
7+
' (' + $_.Count + '):'
8+
} -ForegroundColor Verbose
9+
Write-FormatViewExpression -ScriptBlock {
10+
$lineAndIndent = [Environment]::Newline + (' ' * 4)
11+
$lineAndIndent + $(@(
12+
$_.Commits
13+
) -join $lineAndIndent)
14+
}
15+
} -GroupByProperty GitRoot

0 commit comments

Comments
 (0)