Skip to content

Commit fae43e6

Browse files
Merge pull request #146 from StartAutomating/ugit-updates
ugit 0.3.8
2 parents 952108d + 4d7d0f5 commit fae43e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1009
-344
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
## 0.3.8:
2+
3+
* Use-Git can now be extended (#140, #97), letting you add PowerShell parameters to any git command
4+
* Initial input extensions
5+
* git.clone.input (#141) (--progress is inferred so Write-Progress happens automagically)
6+
* git.log.input (#142) (Added -Before/-After/-Author/-CurrentBranch)
7+
* git.commit.input (#144) (Added -Message/-Body/-Title/-Trailer)
8+
* Other Improvements:
9+
* git log will not process --pretty/--format (Fixes #143)
10+
* git log now supports .Trailers (Fixes #112)
11+
* git remote formatting improved (Fixes #145)
12+
* git remote now works for multiple remotes (Fixes #136)
13+
* Updated logo (#139)
14+
15+
---
16+
117
## 0.3.7:
218

319
* git remote
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<#
2+
.SYNOPSIS
3+
Git Clone extended input
4+
.DESCRIPTION
5+
Extends the input for git clone.
6+
7+
By default, if --progress is not found, it will be added to any git clone.
8+
.EXAMPLE
9+
git clone https://github.com/MDN/content.git # This is a big repo. Progress bars will be very welcome.
10+
#>
11+
[ValidatePattern('^git clone')]
12+
[Management.Automation.Cmdlet("Use","Git")]
13+
[CmdletBinding(PositionalBinding=$false)]
14+
param(
15+
)
16+
17+
if ($gitArgument -notcontains '--progress') {
18+
'--progress'
19+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<#
2+
.SYNOPSIS
3+
Git Commit Input
4+
.DESCRIPTION
5+
Makes Git Commit easier to use from PowerShell by providing parameters for the -Message, -Title, -Body, and -Trailers
6+
.EXAMPLE
7+
git commit -Title "Fixing Something"
8+
.EXAMPLE
9+
git commit -Title "Changing Stuff" -Trailers @{"Co-Authored-By"="SOMEONE ELSE <[email protected]>"}
10+
#>
11+
[ValidatePattern('^git commit')]
12+
[Management.Automation.Cmdlet('Use','Git')]
13+
[CmdletBinding(PositionalBinding=$false)]
14+
param(
15+
# The message used for the commit
16+
[string]
17+
$Message,
18+
19+
# The title of the commit. If -Message is also provided, this will become part of the -Body
20+
[string]
21+
$Title,
22+
23+
# The body of the commit.
24+
[string]
25+
$Body,
26+
27+
# Any git trailers to add to the commit.
28+
# git trailers are key-value pairs you can use to associate metadata with a commit.
29+
# As this uses --trailer, this requires git version 2.33 or greater.
30+
[Alias('Trailer','CommitMetadata','GitMetadata')]
31+
[Collections.IDictionary]
32+
$Trailers,
33+
34+
# If set, will amend an existing commit.
35+
[switch]
36+
$Amend
37+
)
38+
39+
40+
41+
if ($Message) {
42+
"-m"
43+
$message
44+
}
45+
46+
if ($Title) {
47+
"-m"
48+
$title
49+
}
50+
51+
if ($Body) {
52+
"-m"
53+
$body
54+
}
55+
56+
if ($Trailers) {
57+
foreach ($kv in $Trailers.GetEnumerator()) {
58+
foreach ($val in $kv.Value) {
59+
"--trailer=$($kv.Key -replace ':','_colon_' -replace '\s', '-')=$val"
60+
}
61+
}
62+
}
63+
64+
if ($amend) {
65+
"--amend"
66+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<#
2+
.SYNOPSIS
3+
git log input
4+
.DESCRIPTION
5+
Extends the parameters for git log, making it easier to use from PowerShell.
6+
7+
Allows timeframe parameters to be tab-completed:
8+
* After/Since become --after
9+
* Before/Until become --before
10+
* Author/Committer become --author
11+
12+
Adds -CurrentBranch, which gives the changes between the upstream branch and the current branch.
13+
14+
Also adds -IssueNumber, which searchers for commits that reference particular issues.
15+
.EXAMPLE
16+
git log -CurrentBranch
17+
#>
18+
[ValidatePattern('^git log')]
19+
[Management.Automation.Cmdlet("Use","Git")]
20+
[CmdletBinding(PositionalBinding=$false)]
21+
param(
22+
# Gets logs after a given date
23+
[DateTime]
24+
[Alias('Since')]
25+
$After,
26+
27+
# Gets before a given date
28+
[DateTime]
29+
[Alias('Until')]
30+
$Before,
31+
32+
# Gets lof from a given author or committer
33+
[Alias('Committer')]
34+
[string]
35+
$Author,
36+
37+
# If set, will get all changes between the upstream branch and the current branch.
38+
[Alias('UpstreamDelta','ThisBranch')]
39+
[switch]
40+
$CurrentBranch,
41+
42+
# One or more issue numbers. Providing an issue number of 0 will find all log entries that reference an issue.
43+
[Parameter(ValueFromPipelineByPropertyName)]
44+
[Alias('ReferenceNumbers','ReferenceNumber','IssueNumbers','WorkItemID','WorkItemIDs')]
45+
[int[]]
46+
$IssueNumber
47+
)
48+
49+
foreach ($dashToDoubleDash in 'after', 'before', 'author') {
50+
if ($PSBoundParameters[$dashToDoubleDash]) {
51+
"--$dashToDoubleDash"
52+
"$($PSBoundParameters[$dashToDoubleDash])"
53+
}
54+
}
55+
56+
if ($CurrentBranch) {
57+
$headbranch = git remote | git remote show | Select-Object -ExpandProperty HeadBranch
58+
$currentBranchName = git branch | Where-Object IsCurrentBranch
59+
if ($currentBranchName -ne $headbranch) {
60+
"$headbranch..$currentBranchName"
61+
} else {
62+
Write-Warning "On $headBranch"
63+
}
64+
}
65+
66+
if ($IssueNumber) {
67+
"--perl-regexp"
68+
foreach ($IssueNum in $IssueNumber) {
69+
'--grep'
70+
if ($IssueNum -eq 0) {
71+
'\#\d+\D'
72+
} else {
73+
"\#$IssueNum\D"
74+
}
75+
}
76+
77+
}

Extensions/Git.Log.UGit.Extension.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ begin {
113113
}
114114
}
115115

116+
if ($gitLogOut.CommitMessage) {
117+
$gitTrailers = [Ordered]@{}
118+
foreach ($commitMessageLine in $gitLogOut.CommitMessage -split '(?>\r\n|\n)') {
119+
if ($commitMessageLine -notmatch '\s{0,}(?<k>\S+):\s(?<v>[\s\S]+$)') {
120+
continue
121+
}
122+
if (-not $gitTrailers[$matches.k]) {
123+
$gitTrailers[$matches.k] = $matches.v
124+
} else {
125+
$gitTrailers[$matches.k] = @($gitTrailers[$matches.k]) + $v
126+
}
127+
}
128+
$gitLogOut.Trailers = $gitTrailers
129+
}
130+
116131
if ($GitArgument -contains '--shortstat' -or $GitArgument -contains '--stat') {
117132
foreach ($linePart in $OutputLines[-2] -split ',' -replace '[\s\w\(\)-[\d]]') {
118133
if ($linePart.Contains('+')) {
@@ -167,6 +182,9 @@ begin {
167182

168183

169184
process {
185+
if ($gitCommand -match '--(?>pretty|format)') {
186+
continue
187+
}
170188

171189
if ("$gitOut" -like 'Commit*' -and $lines) {
172190
OutGitLog $lines

Extensions/Git.Remote.UGit.Extension.ps1

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,32 @@ end {
3535
switch -Regex ($gitCommand) {
3636
'git remote\s{0,}$' {
3737
# With no other parameters, it returns the remote name.
38-
return [PSCustomObject][Ordered]@{
39-
PSTypename = 'git.remote.name'
40-
RemoteName = $remoteLines -join ' ' -replace '\s'
41-
GitRoot = $gitRoot
38+
foreach ($remoteLine in $remoteLines) {
39+
if (-not $remoteLine.Trim()) {
40+
continue
41+
}
42+
[PSCustomObject][Ordered]@{
43+
PSTypename = 'git.remote.name'
44+
RemoteName = $remoteLine -join ' ' -replace '\s'
45+
GitRoot = $gitRoot
46+
}
4247
}
4348
}
4449
'git remote get-url (?<RemoteName>\S+)\s{0,}$' {
45-
# With get-url, it returns the URL
46-
return [PSCustomObject][Ordered]@{
47-
PSTypename = 'git.remote.url'
48-
RemoteName = $matches.RemoteName
49-
RemoteUrl = $remoteLines -join ' ' -replace '\s'
50-
GitOutputLines = $remoteLines
51-
GitRoot = $gitRoot
52-
}
50+
51+
foreach ($remoteline in $remoteLines) {
52+
if (-not $remoteLine.Trim()) {
53+
continue
54+
}
55+
# With get-url, it returns the URL
56+
return [PSCustomObject][Ordered]@{
57+
PSTypename = 'git.remote.url'
58+
RemoteName = $matches.RemoteName
59+
RemoteUrl = $remoteLines -join ' ' -replace '\s'
60+
GitOutputLines = $remoteLines
61+
GitRoot = $gitRoot
62+
}
63+
}
5364
}
5465
'git remote show (?<RemoteName>\S+)\s{0,}$' {
5566
# With show, it returns _a lot_ of stuff. We want to track:

Formatting/Git.Remote.format.ps1

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,24 @@ Write-FormatView -TypeName Git.Remote.Show -Action {
2020
[Environment]::NewLine + (' ' * 4)
2121
)
2222
}
23-
Write-FormatViewExpression -Newline
24-
Write-FormatViewExpression -Text ' Remote Branches:'
25-
Write-FormatViewExpression -Newline
26-
Write-FormatViewExpression -ControlName GitRemoteBranchList -Property RemoteBranches
27-
Write-FormatViewExpression -Newline
28-
Write-FormatViewExpression -Text ' Local Branches:'
29-
Write-FormatViewExpression -Newline
30-
Write-FormatViewExpression -ControlName GitRemoteBranchList -Property LocalBranches
31-
Write-FormatViewExpression -Text ' Tracked Upstreams:'
32-
Write-FormatViewExpression -Newline
33-
Write-FormatViewExpression -ControlName GitRemoteBranchList -Property TrackedUpstreams
34-
Write-FormatViewExpression -Newline
23+
Write-FormatViewExpression -If { $_.RemoteBranches } -ScriptBlock {
24+
[Environment]::NewLine + ' Remote Branches:' + [Environment]::NewLine
25+
}
26+
27+
Write-FormatViewExpression -If { $_.RemoteBranches } -ControlName GitRemoteBranchList -Property RemoteBranches
28+
29+
Write-FormatViewExpression -If { $_.LocalBranches } -ScriptBlock {
30+
[Environment]::NewLine + ' Local Branches:' + [Environment]::NewLine
31+
}
32+
33+
Write-FormatViewExpression -If { $_.LocalBranches } -ControlName GitRemoteBranchList -Property LocalBranches
34+
35+
36+
Write-FormatViewExpression -If { $_.TrackedUpstreams } -ScriptBlock {
37+
[Environment]::NewLine + ' Tracked Upstreams:' + [Environment]::NewLine
38+
}
39+
40+
Write-FormatViewExpression -If { $_.TrackedUpstreams } -ControlName GitRemoteBranchList -Property TrackedUpstreams
3541
}
3642

3743
Write-FormatView -TypeName n/a -Name GitRemoteBranchList -AsControl -Action {

0 commit comments

Comments
 (0)