Skip to content

Commit 5c99410

Browse files
Merge pull request #166 from StartAutomating/ugit-file-diffs
ugit 0.3.9
2 parents 06a67e6 + 84dca72 commit 5c99410

22 files changed

+668
-35
lines changed

.github/workflows/TestAndPublish.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ jobs:
576576
steps:
577577
- name: Check out repository
578578
uses: actions/checkout@v2
579+
- name: GitLogger
580+
uses: GitLogging/GitLoggerAction@main
581+
id: GitLogger
579582
- name: Use PSSVG Action
580583
uses: StartAutomating/PSSVG@main
581584
id: PSSVG

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
## 0.3.9:
2+
3+
* Adding ugit demo (Fixes #163)
4+
* Use-Git: Improving -Confirm (Fixes #165) and -WhatIf (Fixes #162)
5+
* git.log.input
6+
* Adding -NumberOfCommits (#161/#156)
7+
* Adding -SearchPattern (Fixes #158)
8+
* Adding -SearchString (Fixes #157)
9+
* Adding -Statistics (Fixes #155)
10+
* Adding git.branch IsTracked (Fixes #160)
11+
* Extending FileInfo for better git results (Fixes #153) (thanks @ninmonkey)
12+
* Adding ugit.extension formatting (Fixes #164)
13+
* git log formatting - right-aligning CommitMessage (Fixes #152) (thanks @ninmonkey)
14+
* git log .diff FileChange fix (Fixes #151)
15+
* Git Diff ChangeSet Formatting Fix (Fixes #150)
16+
* Updating workflow (Using GitLogger)
17+
18+
---
19+
120
## 0.3.8:
221

322
* Use-Git can now be extended (#140, #97), letting you add PowerShell parameters to any git command

Extensions/Git.Log.Input.UGit.Extension.ps1

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
[Management.Automation.Cmdlet("Use","Git")]
2020
[CmdletBinding(PositionalBinding=$false)]
2121
param(
22+
# The number of entries to get.
23+
[Alias('CommitNumber','N','Number')]
24+
[int]
25+
$NumberOfCommits,
26+
2227
# Gets logs after a given date
2328
[DateTime]
2429
[Alias('Since')]
@@ -43,16 +48,47 @@ $CurrentBranch,
4348
[Parameter(ValueFromPipelineByPropertyName)]
4449
[Alias('ReferenceNumbers','ReferenceNumber','IssueNumbers','WorkItemID','WorkItemIDs')]
4550
[int[]]
46-
$IssueNumber
51+
$IssueNumber,
52+
53+
# If set, will get statistics associated with each change
54+
[Alias('Stat')]
55+
[switch]
56+
$Statistics,
57+
58+
# If provided, will search for specific strings within the change sets of a commit.
59+
# This is especially useful when finding references to or changes to a given function or structure.
60+
[Parameter(ValueFromPipelineByPropertyName)]
61+
[Alias('Search')]
62+
[string]
63+
$SearchString,
64+
65+
# If provided, will search for specific patterns within the change sets of a commit.
66+
# This is especially useful when finding references to or changes to a given function or structure.
67+
[Parameter(ValueFromPipelineByPropertyName)]
68+
[Alias('Pattern')]
69+
[string]
70+
$SearchPattern
4771
)
4872

73+
# If the number of commits was provided, it should come first.
74+
if ($NumberOfCommits) {
75+
'-n'
76+
"$NumberOfCommits"
77+
}
78+
4979
foreach ($dashToDoubleDash in 'after', 'before', 'author') {
5080
if ($PSBoundParameters[$dashToDoubleDash]) {
5181
"--$dashToDoubleDash"
5282
"$($PSBoundParameters[$dashToDoubleDash])"
5383
}
5484
}
5585

86+
foreach ($dashToDoubleDashSwitch in 'Statistics') {
87+
if ($PSBoundParameters[$dashToDoubleDash]) {
88+
"--$dashToDoubleDashSwitch"
89+
}
90+
}
91+
5692
if ($CurrentBranch) {
5793
$headbranch = git remote | git remote show | Select-Object -ExpandProperty HeadBranch
5894
$currentBranchName = git branch | Where-Object IsCurrentBranch
@@ -72,6 +108,15 @@ if ($IssueNumber) {
72108
} else {
73109
"\#$IssueNum\D"
74110
}
75-
}
76-
111+
}
112+
}
113+
114+
if ($SearchString) {
115+
"-S"
116+
$SearchString
117+
}
118+
119+
if ($SearchPattern) {
120+
"-G"
121+
$SearchPattern
77122
}

Formatting/Git.Diff.ChangeSet.Format.ps1

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ Write-FormatView -TypeName Git.Diff.ChangeSet -AsControl -Name Git.Diff.ChangeSe
88
$changeLines = @($_.Changes -split '(?>\r\n|\n)' -ne '')
99
@(foreach ($changeLine in $changeLines) {
1010
[Environment]::NewLine
11-
if ($changeLine.StartsWith('+')) {
12-
. $SetOutputStyle -ForegroundColor Success
13-
$changeLine -replace "[\s\r\n]+$"
14-
. $ClearOutputStyle
11+
if ($changeLine.StartsWith('+')) {
12+
Format-RichText -InputObject ($changeLine -replace "[\s\r\n]+$") -ForegroundColor Success
1513
}
16-
elseif ($changeLine.StartsWith('-')) {
17-
. $SetOutputStyle -ForegroundColor Failure
18-
$changeLine -replace "[\s\r\n]+$"
19-
. $ClearOutputStyle
14+
elseif ($changeLine.StartsWith('-')) {
15+
Format-RichText -InputObject ($changeLine -replace "[\s\r\n]+$") -ForegroundColor Error
2016
}
2117
else {
2218
$changeLine

Formatting/Git.Log.format.ps1

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
Write-FormatView -TypeName Git.Log -Property GitUserName, CommitDate, CommitMessage -Wrap
1+
Write-FormatView -TypeName Git.Log -Property GitUserName, CommitDate, CommitMessage -Wrap -AlignProperty @{
2+
"CommitDate" = "Right"
3+
"CommitMessage" = "Left"
4+
}
25

3-
Write-FormatView -TypeName Git.Log -Property GitUserName, CommitDate, CommitHash, CommitMessage -Wrap -Name IncludeCommitHash
6+
Write-FormatView -TypeName Git.Log -Property GitUserName, CommitDate, CommitHash, CommitMessage -Wrap -Name IncludeCommitHash -AlignProperty @{
7+
"CommitDate" = "Right"
8+
"CommitHash" = "Left"
9+
"CommitMessage" = "Left"
10+
}
411

5-
Write-FormatView -TypeName Git.Merge.Log -Property GitUserName, CommitDate, MergeHash, CommitMessage -Wrap
12+
Write-FormatView -TypeName Git.Merge.Log -Property GitUserName, CommitDate, MergeHash, CommitMessage -Wrap -AlignProperty @{
13+
"CommitDate" = "Right"
14+
"CommitHash" = "Left"
15+
"MergeHash" = "Left"
16+
"CommitMessage" = "Left"
17+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Write-FormatView -TypeName ugit.extension -Property DisplayName, Synopsis -AutoSize
2+
3+
Write-FormatView -TypeName ugit.extension -Property DisplayName, Pattern -Name Pattern -AutoSize
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@{
2+
'GitLog' = 'GitLogs'
3+
'GitDifference' = 'GitDiff'
4+
'Diff' = 'GitDiff'
5+
'Logs' = 'GitLogs'
6+
'GitHistory' = 'GitChanges'
7+
'Changes' = 'GitChanges'
8+
'History' = 'GitChanges'
9+
'HasChanged' = 'GitDirty'
10+
'HasChanges' = 'GitDirty'
11+
'IsUnstaged' = 'GitDirty'
12+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<#
2+
.SYNOPSIS
3+
Get Changes for a given file
4+
.DESCRIPTION
5+
Gets changes from git for a given file. Can provide a timespan, series of numbers, date, or pair of dates.
6+
#>
7+
8+
$byDate = @()
9+
$byNumber = @()
10+
$byTimespan = @()
11+
foreach ($arg in $args) {
12+
if ($arg -as [int] -ne $null) {
13+
$byNumber += $arg -as [int]
14+
}
15+
elseif ($arg -is [object[]]) {
16+
$byNumber += $arg
17+
}
18+
elseif ($arg -as [DateTime]) {
19+
$byDate+= $arg -as [DateTime]
20+
}
21+
elseif (
22+
$arg -as [TimeSpan]
23+
) {
24+
$byTimespan+= $arg -as [TimeSpan]
25+
}
26+
}
27+
28+
Push-Location $this.Directory
29+
30+
31+
32+
if ($byTimespan) {
33+
git log -Since ([DateTime]::Now - $byTimespan[0]) $this.Name
34+
}
35+
elseif ($byDate) {
36+
if ($byDate.Length -gt 1) {
37+
$first, $second = $byDate | Sort-Object
38+
git log -After $second -Before $first $this.Name
39+
} elseif ($byDate.Length -eq 1) {
40+
git log -Since $byDate[0] $this.Name
41+
} else {
42+
throw "Can only list Changes between two dates"
43+
}
44+
}
45+
elseif ($byNumber.Length) {
46+
$maxNumber = $byNumber | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum
47+
$maxNumber = $maxNumber + 1
48+
$anyNegative = @($byNumber -lt 0).Length
49+
50+
if ($anyNegative) {
51+
@(git log $this.Name)[@($byNumber -as [int[]])]
52+
} else {
53+
@(git log -n $maxNumber $this.Name)[@($byNumber -as [int[]])]
54+
}
55+
}
56+
else {
57+
git log $this.Name
58+
}
59+
60+
Pop-Location
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Push-Location $this.Directory
2+
(git log -n 1 $this.Name).Diff()
3+
Pop-Location
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Push-Location $this.Directory
2+
$(git status $this.Name '-s') -as [bool]
3+
Pop-Location

0 commit comments

Comments
 (0)