Skip to content

Commit bbd1313

Browse files
Merge pull request #95 from StartAutomating/ugit-changes
ugit 0.3.2
2 parents 5a045da + 4e23ace commit bbd1313

25 files changed

+177
-128
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.3.2:
2+
3+
* git diff now includes .File and .GitRoot (Fixes #93)
4+
* git pull no longer includes 'files changed' when no files change (Fixes #92)
5+
6+
---
7+
18
## 0.3.1:
29

310
* git help --all now returns as objects (Fixes #88)

Extensions/Git.Branch.UGit.Extension.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<#
1+
<#
22
.SYNOPSIS
33
git branch extension
44
.DESCRIPTION
@@ -20,7 +20,7 @@ begin {
2020
<#
2121
If any of these parameters are used, we will skip processing.
2222
#>
23-
$SkipIf = 'm', 'c', 'column','format', 'show-current' -join '|'
23+
$SkipIf = 'm', 'c', 'column','format', 'show-current' -join '|'
2424
if ($gitCommand -match "\s-(?>$SkipIf)") { continue }
2525
$allBranches = @()
2626
}
@@ -44,7 +44,7 @@ process {
4444

4545
# Current branches will start with an asterisk. Convert this to a boolean.
4646
$IsCurrentBranch = ("$gitOut" -match '^\*\s' -as [bool])
47-
47+
4848
# If the -verbose flag was passed, we have more information in a more predictable fashion.
4949
if ($gitCommand -match '\s-(?:v|-verbose)'){
5050
# The branch name and hash are each separated by spaces. Everything else is a commit message.
@@ -57,12 +57,12 @@ process {
5757
CommitMessage = $lastCommitMessage -join ' '
5858
IsCurrentBranch = $IsCurrentBranch
5959
GitRoot = $GitRoot
60-
}
60+
}
6161
} else {
6262
# If verbose wasn't passed, the branchname is any whitepsace.
6363
# If remotes were passed, then they may start with origin. We can replace this.
6464
$branchName = "$gitOut" -replace '^[\s\*]+' -replace '^origin/'
65-
65+
6666
# Add the output to the list of all branches
6767
$allBranches += [PSCustomObject][Ordered]@{
6868
PSTypeName = 'git.branch'
@@ -71,19 +71,19 @@ process {
7171
GitRoot = $GitRoot
7272
}
7373
}
74-
# If the user passed their own --sort parameter,
74+
# If the user passed their own --sort parameter,
7575
if ($gitCommand -match '\s--sort') {
7676
$allBranches[-1] # don't sort for them and output the branch,
7777
$allBranches = @() # and reset the list of all branches.
78-
}
78+
}
7979
}
8080

8181
end {
82-
# If no --sort was passed,
83-
$allBranches |
82+
# If no --sort was passed,
83+
$allBranches |
8484
Sort-Object @{ # then put the current branch first
8585
Expression='IsCurrentBranch'
8686
Descending=$true
87-
},
87+
},
8888
BranchName # and sort the rest alphabetically.
8989
}

Extensions/Git.Checkout.UGit.Extension.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<#
1+
<#
22
.SYNOPSIS
33
git checkout extension
44
.DESCRIPTION
@@ -21,15 +21,15 @@ process {
2121
}
2222

2323
end {
24-
24+
2525
if ($($gitCheckoutLines) -match "^Switched to a new branch '(?<b>[^']+)'") {
2626
[PSCustomObject]@{
2727
BranchName = $matches.b
2828
PSTypeName = 'git.checkout.newbranch'
2929
GitRoot = $GitRoot
3030
}
31-
}
32-
elseif ($gitCheckoutLines -match "Switched to branch '(?<b>[^']+)'")
31+
}
32+
elseif ($gitCheckoutLines -match "Switched to branch '(?<b>[^']+)'")
3333
{
3434
$gitCheckoutInfo = @{PSTypeName='git.checkout.switchbranch';GitRoot=$GitRoot;GitOutputLines=$gitCheckoutLines;Modified=@()}
3535
foreach ($checkoutLine in $gitCheckoutLines) {
@@ -39,10 +39,10 @@ end {
3939
elseif ($checkoutLine -match '^Your branch') {
4040
$gitCheckoutInfo.Status = $checkoutLine
4141
}
42-
elseif ($checkoutLine -match '^(?<ct>\w)\s+(?<fn>\S+)') {
42+
elseif ($checkoutLine -match '^(?<ct>\w)\s+(?<fn>\S+)') {
4343
if ($matches.ct -eq 'M') {
4444
$gitCheckoutInfo.modified += (Get-Item $matches.fn -ErrorAction SilentlyContinue)
45-
}
45+
}
4646
}
4747
}
4848
[PSCustomObject]$gitCheckoutInfo
@@ -55,7 +55,7 @@ end {
5555
}
5656
elseif ($checkoutLine -match '^Your branch') {
5757
$gitCheckoutInfo.Status = $checkoutLine
58-
}
58+
}
5959
}
6060
[PSCustomObject]$gitCheckoutInfo
6161
}

Extensions/Git.Clone.UGit.Extension.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<#
1+
<#
22
.Synopsis
33
git clone extension
44
.Description
@@ -29,7 +29,7 @@ process {
2929
$dest = $matches.dest
3030
$progressMsg = $matches.0
3131
if (-not $progId) {
32-
$progId = Get-Random
32+
$progId = Get-Random
3333
}
3434
Write-Progress $progressMsg " " -Id $ProgId
3535
}
@@ -47,7 +47,7 @@ end {
4747
Write-Progress $progressMsg "$status $($matches.c) / $($matches.t)" -Completed -Id $ProgId
4848
}
4949

50-
50+
5151
if ($dest) {
5252
$destPath = Join-Path $pwd $dest
5353
$gitUrl = $gitArgument | Where-Object { $_ -like '*.git' -and $_ -as [uri]}
@@ -56,7 +56,7 @@ end {
5656
GitRoot = $destPath
5757
Directory = Get-Item -Path $destPath
5858
GitUrl = $gitUrl
59-
}
59+
}
6060
} else {
6161
$gitCloneLines
6262
}

Extensions/Git.Commit.UGit.Extension.ps1

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<#
1+
<#
22
.SYNOPSIS
33
git commit extension
44
.DESCRIPTION
@@ -26,8 +26,8 @@ end {
2626
# If it doesn't look like the commit lines had a commit hash, output them directly
2727
if (-not ($commitLines -match '[a-f0-9]+\]')) {
2828
$commitLines
29-
}
30-
else
29+
}
30+
else
3131
{
3232
# Otherwise initialize commit information
3333
$commitInfo = [Ordered]@{
@@ -40,33 +40,33 @@ end {
4040
# and walk over each line in the commit output.
4141
for ($cln = 0; $cln -lt $commitLines.Length; $cln++) {
4242
# If the line has the branch name and hash
43-
if ($commitLines[$cln] -match '^\[(?<n>\S+)\s(?<h>[a-f0-9]+)\]') {
43+
if ($commitLines[$cln] -match '^\[(?<n>\S+)\s(?<h>[a-f0-9]+)\]') {
4444
$commitInfo.BranchName = $matches.n # set .BranchName,
45-
$commitInfo.CommitHash = $matches.h # set .CommitHash
45+
$commitInfo.CommitHash = $matches.h # set .CommitHash
4646
$commitInfo.CommitMessage = # and set .CommitMessage to the rest of the line.
47-
$commitLines[$cln] -replace '^\[[^\]]+\]\s+'
47+
$commitLines[$cln] -replace '^\[[^\]]+\]\s+'
4848
}
49-
elseif ($commitLines[$cln] -match '^\s\d+') # If the line starts with a space and digits
50-
{
49+
elseif ($commitLines[$cln] -match '^\s\d+') # If the line starts with a space and digits
50+
{
5151
# It's the summary. Split it on commas and remove most of the rest of the text.
5252
foreach ($commitLinePart in $commitLines[$cln] -split ',' -replace '[\s\w\(\)-[\d]]') {
53-
54-
if ($commitLinePart.Contains('+')) {
53+
54+
if ($commitLinePart.Contains('+')) {
5555
# If the part contains +, it's insertions.
5656
$commitInfo.Insertions = $commitLinePart -replace '\+' -as [int]
57-
}
58-
elseif ($commitLinePart.Contains('-'))
57+
}
58+
elseif ($commitLinePart.Contains('-'))
5959
{
6060
# If the part contains -, it's deletions.
6161
$commitInfo.Deletions = $commitLinePart -replace '\-' -as [int]
62-
}
62+
}
6363
else
6464
{
6565
# Otherwise, its the file change count.
6666
$commitInfo.FilesChanged = $commitLinePart -as [int]
6767
}
68-
}
69-
}
68+
}
69+
}
7070
elseif ($commitInfo.BranchName) # Otherwise, if we already know the branch name
7171
{
7272
# add the line to the commit message.

Extensions/Git.Diff.UGit.Extension.ps1

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<#
1+
<#
22
.Synopsis
33
Diff Extension
44
.Description
@@ -10,21 +10,36 @@
1010
param()
1111

1212
begin {
13-
# Diff messages are spread across many lines, so we need to keep track of them.
13+
# Diff messages are spread across many lines, so we need to keep track of them.
1414
$lines = [Collections.Queue]::new()
1515
$allDiffLines = [Collections.Queue]::new()
1616
function OutDiff {
1717
param([string[]]$OutputLines)
1818

19-
19+
2020
if (-not $OutputLines) { return }
2121
$outputLineCount = 0
2222
$diffRange = $null
23-
$diffObject = [Ordered]@{PSTypeName='git.diff';ChangeSet=@();GitOutputLines = $OutputLines;Binary=$false}
23+
24+
$diffObject = [Ordered]@{
25+
PSTypeName='git.diff'
26+
ChangeSet=@()
27+
GitOutputLines = $OutputLines
28+
Binary=$false
29+
GitRoot = $gitRoot
30+
}
31+
2432
foreach ($outputLine in $OutputLines) {
2533
$outputLineCount++
2634
if ($outputLineCount -eq 1) {
2735
$diffObject.From, $diffObject.To = $outputLine -replace '^diff --git ' -split '[ab]/' -ne ''
36+
$fromPath = Join-Path $gitRoot $diffObject.From
37+
$toPath = Join-Path $gitRoot $diffObject.To
38+
if (Test-Path $toPath) {
39+
$diffObject.File = Get-Item $toPath
40+
} elseif (Test-Path $fromPath) {
41+
$diffObject.File = Get-Item $fromPath
42+
}
2843
}
2944
if (-not $diffRange -and $outputline -match 'index\s(?<fromhash>[0-9a-f]+)..(?<tohash>[0-9a-f]+)') {
3045
$diffObject.FromHash, $diffObject.ToHash = $Matches.fromhash, $Matches.tohash
@@ -36,7 +51,7 @@ begin {
3651
if ($diffRange) {
3752
$diffObject.ChangeSet += [PSCustomObject]$diffRange
3853
}
39-
54+
4055
$extendedHeader = $outputLine -replace '^@@[^@]+@@' -replace '^\s+'
4156
$diffRange = [Ordered]@{
4257
PSTypeName='git.diff.range';
@@ -47,7 +62,7 @@ begin {
4762
$diffRange.LineStart,
4863
$diffRange.LineCount,
4964
$diffRange.NewLineStart,
50-
$diffRange.NewLineCount =
65+
$diffRange.NewLineCount =
5166
@($outputLine -replace '\s' -split '[-@+]' -ne '' -split ',')[0..3] -as [int[]]
5267
continue
5368
}
@@ -71,7 +86,7 @@ begin {
7186
}
7287

7388

74-
process {
89+
process {
7590
if ("$gitOut" -like 'diff*' -and $lines) {
7691
OutDiff $lines.ToArray()
7792
$lines.Clear()

Extensions/Git.FileOutput.UGit.Extension.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<#
1+
<#
22
.Synopsis
33
Git FileOutput Extension
44
.Description
55
This extension runs on any command that includes the argument -o, followed by a single space.
6-
6+
77
When the command is finished, this will attempt to file the argument provided after -o, and return it as a file.
88
.EXAMPLE
99
git archive -o My.zip

Extensions/Git.Init.UGit.Extension.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<#
1+
<#
22
.SYNOPSIS
33
git init extension
44
.DESCRIPTION
@@ -15,7 +15,7 @@ begin {
1515
<#
1616
If any of these parameters are used, we will skip processing.
1717
#>
18-
$SkipIf = 'q', '-quiet' -join '|'
18+
$SkipIf = 'q', '-quiet' -join '|'
1919
if ($gitCommand -match "\s-(?>$SkipIf)") { break }
2020
}
2121

0 commit comments

Comments
 (0)