Skip to content

Commit

Permalink
Merge pull request #146 from StartAutomating/ugit-updates
Browse files Browse the repository at this point in the history
ugit 0.3.8
  • Loading branch information
StartAutomating authored Mar 29, 2023
2 parents 952108d + 4d7d0f5 commit fae43e6
Show file tree
Hide file tree
Showing 41 changed files with 1,009 additions and 344 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## 0.3.8:

* Use-Git can now be extended (#140, #97), letting you add PowerShell parameters to any git command
* Initial input extensions
* git.clone.input (#141) (--progress is inferred so Write-Progress happens automagically)
* git.log.input (#142) (Added -Before/-After/-Author/-CurrentBranch)
* git.commit.input (#144) (Added -Message/-Body/-Title/-Trailer)
* Other Improvements:
* git log will not process --pretty/--format (Fixes #143)
* git log now supports .Trailers (Fixes #112)
* git remote formatting improved (Fixes #145)
* git remote now works for multiple remotes (Fixes #136)
* Updated logo (#139)

---

## 0.3.7:

* git remote
Expand Down
19 changes: 19 additions & 0 deletions Extensions/Git.Clone.Input.UGit.Extension.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<#
.SYNOPSIS
Git Clone extended input
.DESCRIPTION
Extends the input for git clone.
By default, if --progress is not found, it will be added to any git clone.
.EXAMPLE
git clone https://github.com/MDN/content.git # This is a big repo. Progress bars will be very welcome.
#>
[ValidatePattern('^git clone')]
[Management.Automation.Cmdlet("Use","Git")]
[CmdletBinding(PositionalBinding=$false)]
param(
)

if ($gitArgument -notcontains '--progress') {
'--progress'
}
66 changes: 66 additions & 0 deletions Extensions/Git.Commit.Input.UGit.Extension.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<#
.SYNOPSIS
Git Commit Input
.DESCRIPTION
Makes Git Commit easier to use from PowerShell by providing parameters for the -Message, -Title, -Body, and -Trailers
.EXAMPLE
git commit -Title "Fixing Something"
.EXAMPLE
git commit -Title "Changing Stuff" -Trailers @{"Co-Authored-By"="SOMEONE ELSE <[email protected]>"}
#>
[ValidatePattern('^git commit')]
[Management.Automation.Cmdlet('Use','Git')]
[CmdletBinding(PositionalBinding=$false)]
param(
# The message used for the commit
[string]
$Message,

# The title of the commit. If -Message is also provided, this will become part of the -Body
[string]
$Title,

# The body of the commit.
[string]
$Body,

# Any git trailers to add to the commit.
# git trailers are key-value pairs you can use to associate metadata with a commit.
# As this uses --trailer, this requires git version 2.33 or greater.
[Alias('Trailer','CommitMetadata','GitMetadata')]
[Collections.IDictionary]
$Trailers,

# If set, will amend an existing commit.
[switch]
$Amend
)



if ($Message) {
"-m"
$message
}

if ($Title) {
"-m"
$title
}

if ($Body) {
"-m"
$body
}

if ($Trailers) {
foreach ($kv in $Trailers.GetEnumerator()) {
foreach ($val in $kv.Value) {
"--trailer=$($kv.Key -replace ':','_colon_' -replace '\s', '-')=$val"
}
}
}

if ($amend) {
"--amend"
}
77 changes: 77 additions & 0 deletions Extensions/Git.Log.Input.UGit.Extension.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<#
.SYNOPSIS
git log input
.DESCRIPTION
Extends the parameters for git log, making it easier to use from PowerShell.
Allows timeframe parameters to be tab-completed:
* After/Since become --after
* Before/Until become --before
* Author/Committer become --author
Adds -CurrentBranch, which gives the changes between the upstream branch and the current branch.
Also adds -IssueNumber, which searchers for commits that reference particular issues.
.EXAMPLE
git log -CurrentBranch
#>
[ValidatePattern('^git log')]
[Management.Automation.Cmdlet("Use","Git")]
[CmdletBinding(PositionalBinding=$false)]
param(
# Gets logs after a given date
[DateTime]
[Alias('Since')]
$After,

# Gets before a given date
[DateTime]
[Alias('Until')]
$Before,

# Gets lof from a given author or committer
[Alias('Committer')]
[string]
$Author,

# If set, will get all changes between the upstream branch and the current branch.
[Alias('UpstreamDelta','ThisBranch')]
[switch]
$CurrentBranch,

# One or more issue numbers. Providing an issue number of 0 will find all log entries that reference an issue.
[Parameter(ValueFromPipelineByPropertyName)]
[Alias('ReferenceNumbers','ReferenceNumber','IssueNumbers','WorkItemID','WorkItemIDs')]
[int[]]
$IssueNumber
)

foreach ($dashToDoubleDash in 'after', 'before', 'author') {
if ($PSBoundParameters[$dashToDoubleDash]) {
"--$dashToDoubleDash"
"$($PSBoundParameters[$dashToDoubleDash])"
}
}

if ($CurrentBranch) {
$headbranch = git remote | git remote show | Select-Object -ExpandProperty HeadBranch
$currentBranchName = git branch | Where-Object IsCurrentBranch
if ($currentBranchName -ne $headbranch) {
"$headbranch..$currentBranchName"
} else {
Write-Warning "On $headBranch"
}
}

if ($IssueNumber) {
"--perl-regexp"
foreach ($IssueNum in $IssueNumber) {
'--grep'
if ($IssueNum -eq 0) {
'\#\d+\D'
} else {
"\#$IssueNum\D"
}
}

}
18 changes: 18 additions & 0 deletions Extensions/Git.Log.UGit.Extension.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ begin {
}
}

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]]') {
if ($linePart.Contains('+')) {
Expand Down Expand Up @@ -167,6 +182,9 @@ begin {


process {
if ($gitCommand -match '--(?>pretty|format)') {
continue
}

if ("$gitOut" -like 'Commit*' -and $lines) {
OutGitLog $lines
Expand Down
35 changes: 23 additions & 12 deletions Extensions/Git.Remote.UGit.Extension.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,32 @@ end {
switch -Regex ($gitCommand) {
'git remote\s{0,}$' {
# With no other parameters, it returns the remote name.
return [PSCustomObject][Ordered]@{
PSTypename = 'git.remote.name'
RemoteName = $remoteLines -join ' ' -replace '\s'
GitRoot = $gitRoot
foreach ($remoteLine in $remoteLines) {
if (-not $remoteLine.Trim()) {
continue
}
[PSCustomObject][Ordered]@{
PSTypename = 'git.remote.name'
RemoteName = $remoteLine -join ' ' -replace '\s'
GitRoot = $gitRoot
}
}
}
'git remote get-url (?<RemoteName>\S+)\s{0,}$' {
# With get-url, it returns the URL
return [PSCustomObject][Ordered]@{
PSTypename = 'git.remote.url'
RemoteName = $matches.RemoteName
RemoteUrl = $remoteLines -join ' ' -replace '\s'
GitOutputLines = $remoteLines
GitRoot = $gitRoot
}

foreach ($remoteline in $remoteLines) {
if (-not $remoteLine.Trim()) {
continue
}
# With get-url, it returns the URL
return [PSCustomObject][Ordered]@{
PSTypename = 'git.remote.url'
RemoteName = $matches.RemoteName
RemoteUrl = $remoteLines -join ' ' -replace '\s'
GitOutputLines = $remoteLines
GitRoot = $gitRoot
}
}
}
'git remote show (?<RemoteName>\S+)\s{0,}$' {
# With show, it returns _a lot_ of stuff. We want to track:
Expand Down
30 changes: 18 additions & 12 deletions Formatting/Git.Remote.format.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@ Write-FormatView -TypeName Git.Remote.Show -Action {
[Environment]::NewLine + (' ' * 4)
)
}
Write-FormatViewExpression -Newline
Write-FormatViewExpression -Text ' Remote Branches:'
Write-FormatViewExpression -Newline
Write-FormatViewExpression -ControlName GitRemoteBranchList -Property RemoteBranches
Write-FormatViewExpression -Newline
Write-FormatViewExpression -Text ' Local Branches:'
Write-FormatViewExpression -Newline
Write-FormatViewExpression -ControlName GitRemoteBranchList -Property LocalBranches
Write-FormatViewExpression -Text ' Tracked Upstreams:'
Write-FormatViewExpression -Newline
Write-FormatViewExpression -ControlName GitRemoteBranchList -Property TrackedUpstreams
Write-FormatViewExpression -Newline
Write-FormatViewExpression -If { $_.RemoteBranches } -ScriptBlock {
[Environment]::NewLine + ' Remote Branches:' + [Environment]::NewLine
}

Write-FormatViewExpression -If { $_.RemoteBranches } -ControlName GitRemoteBranchList -Property RemoteBranches

Write-FormatViewExpression -If { $_.LocalBranches } -ScriptBlock {
[Environment]::NewLine + ' Local Branches:' + [Environment]::NewLine
}

Write-FormatViewExpression -If { $_.LocalBranches } -ControlName GitRemoteBranchList -Property LocalBranches


Write-FormatViewExpression -If { $_.TrackedUpstreams } -ScriptBlock {
[Environment]::NewLine + ' Tracked Upstreams:' + [Environment]::NewLine
}

Write-FormatViewExpression -If { $_.TrackedUpstreams } -ControlName GitRemoteBranchList -Property TrackedUpstreams
}

Write-FormatView -TypeName n/a -Name GitRemoteBranchList -AsControl -Action {
Expand Down
Loading

0 comments on commit fae43e6

Please sign in to comment.