diff --git a/CHANGELOG.md b/CHANGELOG.md index de885f38..7ff7bc08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Extensions/Git.Diff.UGit.Extension.ps1 b/Extensions/Git.Diff.UGit.Extension.ps1 index 0885285a..78a846fa 100644 --- a/Extensions/Git.Diff.UGit.Extension.ps1 +++ b/Extensions/Git.Diff.UGit.Extension.ps1 @@ -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 } } diff --git a/Extensions/Git.Log.UGit.Extension.ps1 b/Extensions/Git.Log.UGit.Extension.ps1 index e974f6c7..b09cf6b9 100644 --- a/Extensions/Git.Log.UGit.Extension.ps1 +++ b/Extensions/Git.Log.UGit.Extension.ps1 @@ -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(@' @@ -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, "(?\d+)\s(?\+{0,})(?\-{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 diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index df4fe149..bcedbf8f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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) diff --git a/ugit.psd1 b/ugit.psd1 index 3ae3966a..0544c1ed 100644 --- a/ugit.psd1 +++ b/ugit.psd1 @@ -1,5 +1,5 @@ @{ - ModuleVersion = '0.3.5' + ModuleVersion = '0.3.6' RootModule = 'ugit.psm1' FormatsToProcess = 'ugit.format.ps1xml' TypesToProcess = 'ugit.types.ps1xml' @@ -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)