Skip to content

Commit

Permalink
Merge pull request #124 from StartAutomating/ugit-updates
Browse files Browse the repository at this point in the history
ugit 0.3.6
  • Loading branch information
StartAutomating authored Feb 8, 2023
2 parents 430dca4 + 97f3ebb commit aebf58a
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 7 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 0.3.6:

* git log
* Supporting --stat (Fixes #123)
* Supporting --shortstat (Fixes #102)
* Adding .GitOutputLines (Fixes #122)
* git diff
* Fixing subdirectory issue (Fixes #121)

---

## 0.3.5:

* Use-Git: Fixing pipeline behavior for non-file input (Fixes #119)
Expand Down
10 changes: 5 additions & 5 deletions Extensions/Git.Diff.UGit.Extension.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ begin {
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.From, $diffObject.To = $outputLine -replace '^diff --git' -split '\s[ab]/' -ne ''
$fromPath = if ($diffObject.From) { Join-Path $gitRoot $diffObject.From }
$toPath = if ($diffObject.To) { Join-Path $gitRoot $diffObject.To }
if ($toPath -and (Test-Path $toPath)) {
$diffObject.File = Get-Item $toPath
} elseif (Test-Path $fromPath) {
} elseif ($fromPath -and (Test-Path $fromPath)) {
$diffObject.File = Get-Item $fromPath
}
}
Expand Down
47 changes: 46 additions & 1 deletion Extensions/Git.Log.UGit.Extension.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ param(
)

begin {
# TODO: Support git log --shortstat (#102)
# TODO: Support git log trailers (#112)
$script:LogChangesMerged = $false
$Git_Log = [Regex]::new(@'
Expand Down Expand Up @@ -114,6 +113,52 @@ begin {
}
}

if ($GitArgument -contains '--shortstat' -or $GitArgument -contains '--stat') {
foreach ($linePart in $OutputLines[-2] -split ',' -replace '[\s\w\(\)-[\d]]') {
if ($linePart.Contains('+')) {
# If the part contains +, it's insertions.
$gitLogOut.Insertions = $linePart -replace '\+' -as [int]
}
elseif ($linePart.Contains('-'))
{
# If the part contains -, it's deletions.
$gitLogOut.Deletions = $linePart -replace '\-' -as [int]
}
else
{
# Otherwise, its the file change count.
$gitLogOut.FilesChanged = $linePart -as [int]
}
}
if (-not $gitLogOut.Deletions) {
$gitLogOut.Deletions = 0
}
if (-not $gitLogOut.Insertions) {
$gitLogOut.Insertions = 0
}
}

if ($gitArgument -contains '--stat') {
$gitLogOut.Changes = @()
foreach ($outLine in $OutputLines) {
if ($outLine -notlike ' *|*') { continue }
$nameOfFile, $fileChanges = $outLine -split '\|'
$nameOfFile = $nameOfFile -replace '^\s+' -replace '\s+$'
$match = [Regex]::Match($fileChanges, "(?<c>\d+)\s(?<i>\+{0,})(?<d>\-{0,})")
$linesChanged = $match.Groups["c"].Value -as [int]
$linesInserted = $match.Groups["i"].Length
$linesDeleted = $match.Groups["d"].Length
$gitLogOut.Changes +=
[PSCustomObject][Ordered]@{
FilePath = $nameOfFile
LinesChanged = $linesChanged
LinesInserted = $linesInserted
LinesDeleted = $linesDeleted
}
}
}

$gitLogOut.GitOutputLines = $OutputLines
$gitLogOut.Merged = $script:LogChangesMerged
$gitLogOut.GitRoot = $GitRoot
[PSCustomObject]$gitLogOut
Expand Down
11 changes: 11 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 0.3.6:

* git log
* Supporting --stat (Fixes #123)
* Supporting --shortstat (Fixes #102)
* Adding .GitOutputLines (Fixes #122)
* git diff
* Fixing subdirectory issue (Fixes #121)

---

## 0.3.5:

* Use-Git: Fixing pipeline behavior for non-file input (Fixes #119)
Expand Down
13 changes: 12 additions & 1 deletion ugit.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
ModuleVersion = '0.3.5'
ModuleVersion = '0.3.6'
RootModule = 'ugit.psm1'
FormatsToProcess = 'ugit.format.ps1xml'
TypesToProcess = 'ugit.types.ps1xml'
Expand All @@ -17,6 +17,17 @@ PrivateData = @{
LicenseURI = 'https://github.com/StartAutomating/ugit/blob/main/LICENSE'
BuildModule = @('EZOut', 'Piecemeal', 'PipeScript')
ReleaseNotes = @'
## 0.3.6:
* git log
* Supporting --stat (Fixes #123)
* Supporting --shortstat (Fixes #102)
* Adding .GitOutputLines (Fixes #122)
* git diff
* Fixing subdirectory issue (Fixes #121)
---
## 0.3.5:
* Use-Git: Fixing pipeline behavior for non-file input (Fixes #119)
Expand Down

0 comments on commit aebf58a

Please sign in to comment.