Skip to content

Commit

Permalink
Merge pull request #95 from StartAutomating/ugit-changes
Browse files Browse the repository at this point in the history
ugit 0.3.2
  • Loading branch information
StartAutomating committed Nov 29, 2022
2 parents 5a045da + 4e23ace commit bbd1313
Show file tree
Hide file tree
Showing 25 changed files with 177 additions and 128 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.3.2:

* git diff now includes .File and .GitRoot (Fixes #93)
* git pull no longer includes 'files changed' when no files change (Fixes #92)

---

## 0.3.1:

* git help --all now returns as objects (Fixes #88)
Expand Down
20 changes: 10 additions & 10 deletions Extensions/Git.Branch.UGit.Extension.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<#
<#
.SYNOPSIS
git branch extension
.DESCRIPTION
Expand All @@ -20,7 +20,7 @@ begin {
<#
If any of these parameters are used, we will skip processing.
#>
$SkipIf = 'm', 'c', 'column','format', 'show-current' -join '|'
$SkipIf = 'm', 'c', 'column','format', 'show-current' -join '|'
if ($gitCommand -match "\s-(?>$SkipIf)") { continue }
$allBranches = @()
}
Expand All @@ -44,7 +44,7 @@ process {

# Current branches will start with an asterisk. Convert this to a boolean.
$IsCurrentBranch = ("$gitOut" -match '^\*\s' -as [bool])

# If the -verbose flag was passed, we have more information in a more predictable fashion.
if ($gitCommand -match '\s-(?:v|-verbose)'){
# The branch name and hash are each separated by spaces. Everything else is a commit message.
Expand All @@ -57,12 +57,12 @@ process {
CommitMessage = $lastCommitMessage -join ' '
IsCurrentBranch = $IsCurrentBranch
GitRoot = $GitRoot
}
}
} else {
# If verbose wasn't passed, the branchname is any whitepsace.
# If remotes were passed, then they may start with origin. We can replace this.
$branchName = "$gitOut" -replace '^[\s\*]+' -replace '^origin/'

# Add the output to the list of all branches
$allBranches += [PSCustomObject][Ordered]@{
PSTypeName = 'git.branch'
Expand All @@ -71,19 +71,19 @@ process {
GitRoot = $GitRoot
}
}
# If the user passed their own --sort parameter,
# If the user passed their own --sort parameter,
if ($gitCommand -match '\s--sort') {
$allBranches[-1] # don't sort for them and output the branch,
$allBranches = @() # and reset the list of all branches.
}
}
}

end {
# If no --sort was passed,
$allBranches |
# If no --sort was passed,
$allBranches |
Sort-Object @{ # then put the current branch first
Expression='IsCurrentBranch'
Descending=$true
},
},
BranchName # and sort the rest alphabetically.
}
14 changes: 7 additions & 7 deletions Extensions/Git.Checkout.UGit.Extension.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<#
<#
.SYNOPSIS
git checkout extension
.DESCRIPTION
Expand All @@ -21,15 +21,15 @@ process {
}

end {

if ($($gitCheckoutLines) -match "^Switched to a new branch '(?<b>[^']+)'") {
[PSCustomObject]@{
BranchName = $matches.b
PSTypeName = 'git.checkout.newbranch'
GitRoot = $GitRoot
}
}
elseif ($gitCheckoutLines -match "Switched to branch '(?<b>[^']+)'")
}
elseif ($gitCheckoutLines -match "Switched to branch '(?<b>[^']+)'")
{
$gitCheckoutInfo = @{PSTypeName='git.checkout.switchbranch';GitRoot=$GitRoot;GitOutputLines=$gitCheckoutLines;Modified=@()}
foreach ($checkoutLine in $gitCheckoutLines) {
Expand All @@ -39,10 +39,10 @@ end {
elseif ($checkoutLine -match '^Your branch') {
$gitCheckoutInfo.Status = $checkoutLine
}
elseif ($checkoutLine -match '^(?<ct>\w)\s+(?<fn>\S+)') {
elseif ($checkoutLine -match '^(?<ct>\w)\s+(?<fn>\S+)') {
if ($matches.ct -eq 'M') {
$gitCheckoutInfo.modified += (Get-Item $matches.fn -ErrorAction SilentlyContinue)
}
}
}
}
[PSCustomObject]$gitCheckoutInfo
Expand All @@ -55,7 +55,7 @@ end {
}
elseif ($checkoutLine -match '^Your branch') {
$gitCheckoutInfo.Status = $checkoutLine
}
}
}
[PSCustomObject]$gitCheckoutInfo
}
Expand Down
8 changes: 4 additions & 4 deletions Extensions/Git.Clone.UGit.Extension.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<#
<#
.Synopsis
git clone extension
.Description
Expand Down Expand Up @@ -29,7 +29,7 @@ process {
$dest = $matches.dest
$progressMsg = $matches.0
if (-not $progId) {
$progId = Get-Random
$progId = Get-Random
}
Write-Progress $progressMsg " " -Id $ProgId
}
Expand All @@ -47,7 +47,7 @@ end {
Write-Progress $progressMsg "$status $($matches.c) / $($matches.t)" -Completed -Id $ProgId
}


if ($dest) {
$destPath = Join-Path $pwd $dest
$gitUrl = $gitArgument | Where-Object { $_ -like '*.git' -and $_ -as [uri]}
Expand All @@ -56,7 +56,7 @@ end {
GitRoot = $destPath
Directory = Get-Item -Path $destPath
GitUrl = $gitUrl
}
}
} else {
$gitCloneLines
}
Expand Down
30 changes: 15 additions & 15 deletions Extensions/Git.Commit.UGit.Extension.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<#
<#
.SYNOPSIS
git commit extension
.DESCRIPTION
Expand Down Expand Up @@ -26,8 +26,8 @@ end {
# If it doesn't look like the commit lines had a commit hash, output them directly
if (-not ($commitLines -match '[a-f0-9]+\]')) {
$commitLines
}
else
}
else
{
# Otherwise initialize commit information
$commitInfo = [Ordered]@{
Expand All @@ -40,33 +40,33 @@ end {
# and walk over each line in the commit output.
for ($cln = 0; $cln -lt $commitLines.Length; $cln++) {
# If the line has the branch name and hash
if ($commitLines[$cln] -match '^\[(?<n>\S+)\s(?<h>[a-f0-9]+)\]') {
if ($commitLines[$cln] -match '^\[(?<n>\S+)\s(?<h>[a-f0-9]+)\]') {
$commitInfo.BranchName = $matches.n # set .BranchName,
$commitInfo.CommitHash = $matches.h # set .CommitHash
$commitInfo.CommitHash = $matches.h # set .CommitHash
$commitInfo.CommitMessage = # and set .CommitMessage to the rest of the line.
$commitLines[$cln] -replace '^\[[^\]]+\]\s+'
$commitLines[$cln] -replace '^\[[^\]]+\]\s+'
}
elseif ($commitLines[$cln] -match '^\s\d+') # If the line starts with a space and digits
{
elseif ($commitLines[$cln] -match '^\s\d+') # If the line starts with a space and digits
{
# It's the summary. Split it on commas and remove most of the rest of the text.
foreach ($commitLinePart in $commitLines[$cln] -split ',' -replace '[\s\w\(\)-[\d]]') {
if ($commitLinePart.Contains('+')) {

if ($commitLinePart.Contains('+')) {
# If the part contains +, it's insertions.
$commitInfo.Insertions = $commitLinePart -replace '\+' -as [int]
}
elseif ($commitLinePart.Contains('-'))
}
elseif ($commitLinePart.Contains('-'))
{
# If the part contains -, it's deletions.
$commitInfo.Deletions = $commitLinePart -replace '\-' -as [int]
}
}
else
{
# Otherwise, its the file change count.
$commitInfo.FilesChanged = $commitLinePart -as [int]
}
}
}
}
}
elseif ($commitInfo.BranchName) # Otherwise, if we already know the branch name
{
# add the line to the commit message.
Expand Down
29 changes: 22 additions & 7 deletions Extensions/Git.Diff.UGit.Extension.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<#
<#
.Synopsis
Diff Extension
.Description
Expand All @@ -10,21 +10,36 @@
param()

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


if (-not $OutputLines) { return }
$outputLineCount = 0
$diffRange = $null
$diffObject = [Ordered]@{PSTypeName='git.diff';ChangeSet=@();GitOutputLines = $OutputLines;Binary=$false}

$diffObject = [Ordered]@{
PSTypeName='git.diff'
ChangeSet=@()
GitOutputLines = $OutputLines
Binary=$false
GitRoot = $gitRoot
}

foreach ($outputLine in $OutputLines) {
$outputLineCount++
if ($outputLineCount -eq 1) {
$diffObject.From, $diffObject.To = $outputLine -replace '^diff --git ' -split '[ab]/' -ne ''
$fromPath = Join-Path $gitRoot $diffObject.From
$toPath = Join-Path $gitRoot $diffObject.To
if (Test-Path $toPath) {
$diffObject.File = Get-Item $toPath
} elseif (Test-Path $fromPath) {
$diffObject.File = Get-Item $fromPath
}
}
if (-not $diffRange -and $outputline -match 'index\s(?<fromhash>[0-9a-f]+)..(?<tohash>[0-9a-f]+)') {
$diffObject.FromHash, $diffObject.ToHash = $Matches.fromhash, $Matches.tohash
Expand All @@ -36,7 +51,7 @@ begin {
if ($diffRange) {
$diffObject.ChangeSet += [PSCustomObject]$diffRange
}

$extendedHeader = $outputLine -replace '^@@[^@]+@@' -replace '^\s+'
$diffRange = [Ordered]@{
PSTypeName='git.diff.range';
Expand All @@ -47,7 +62,7 @@ begin {
$diffRange.LineStart,
$diffRange.LineCount,
$diffRange.NewLineStart,
$diffRange.NewLineCount =
$diffRange.NewLineCount =
@($outputLine -replace '\s' -split '[-@+]' -ne '' -split ',')[0..3] -as [int[]]
continue
}
Expand All @@ -71,7 +86,7 @@ begin {
}


process {
process {
if ("$gitOut" -like 'diff*' -and $lines) {
OutDiff $lines.ToArray()
$lines.Clear()
Expand Down
4 changes: 2 additions & 2 deletions Extensions/Git.FileOutput.UGit.Extension.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<#
<#
.Synopsis
Git FileOutput Extension
.Description
This extension runs on any command that includes the argument -o, followed by a single space.
When the command is finished, this will attempt to file the argument provided after -o, and return it as a file.
.EXAMPLE
git archive -o My.zip
Expand Down
4 changes: 2 additions & 2 deletions Extensions/Git.Init.UGit.Extension.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<#
<#
.SYNOPSIS
git init extension
.DESCRIPTION
Expand All @@ -15,7 +15,7 @@ begin {
<#
If any of these parameters are used, we will skip processing.
#>
$SkipIf = 'q', '-quiet' -join '|'
$SkipIf = 'q', '-quiet' -join '|'
if ($gitCommand -match "\s-(?>$SkipIf)") { break }
}

Expand Down
Loading

0 comments on commit bbd1313

Please sign in to comment.