diff --git a/CHANGELOG.md b/CHANGELOG.md index ab92313f..f9f05e52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Extensions/Git.Branch.UGit.Extension.ps1 b/Extensions/Git.Branch.UGit.Extension.ps1 index ca2908e6..b3f36e46 100644 --- a/Extensions/Git.Branch.UGit.Extension.ps1 +++ b/Extensions/Git.Branch.UGit.Extension.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS git branch extension .DESCRIPTION @@ -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 = @() } @@ -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. @@ -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' @@ -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. } diff --git a/Extensions/Git.Checkout.UGit.Extension.ps1 b/Extensions/Git.Checkout.UGit.Extension.ps1 index 02af32d0..c8575a89 100644 --- a/Extensions/Git.Checkout.UGit.Extension.ps1 +++ b/Extensions/Git.Checkout.UGit.Extension.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS git checkout extension .DESCRIPTION @@ -21,15 +21,15 @@ process { } end { - + if ($($gitCheckoutLines) -match "^Switched to a new branch '(?[^']+)'") { [PSCustomObject]@{ BranchName = $matches.b PSTypeName = 'git.checkout.newbranch' GitRoot = $GitRoot } - } - elseif ($gitCheckoutLines -match "Switched to branch '(?[^']+)'") + } + elseif ($gitCheckoutLines -match "Switched to branch '(?[^']+)'") { $gitCheckoutInfo = @{PSTypeName='git.checkout.switchbranch';GitRoot=$GitRoot;GitOutputLines=$gitCheckoutLines;Modified=@()} foreach ($checkoutLine in $gitCheckoutLines) { @@ -39,10 +39,10 @@ end { elseif ($checkoutLine -match '^Your branch') { $gitCheckoutInfo.Status = $checkoutLine } - elseif ($checkoutLine -match '^(?\w)\s+(?\S+)') { + elseif ($checkoutLine -match '^(?\w)\s+(?\S+)') { if ($matches.ct -eq 'M') { $gitCheckoutInfo.modified += (Get-Item $matches.fn -ErrorAction SilentlyContinue) - } + } } } [PSCustomObject]$gitCheckoutInfo @@ -55,7 +55,7 @@ end { } elseif ($checkoutLine -match '^Your branch') { $gitCheckoutInfo.Status = $checkoutLine - } + } } [PSCustomObject]$gitCheckoutInfo } diff --git a/Extensions/Git.Clone.UGit.Extension.ps1 b/Extensions/Git.Clone.UGit.Extension.ps1 index eab4279f..2d45b84f 100644 --- a/Extensions/Git.Clone.UGit.Extension.ps1 +++ b/Extensions/Git.Clone.UGit.Extension.ps1 @@ -1,4 +1,4 @@ -<# +<# .Synopsis git clone extension .Description @@ -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 } @@ -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]} @@ -56,7 +56,7 @@ end { GitRoot = $destPath Directory = Get-Item -Path $destPath GitUrl = $gitUrl - } + } } else { $gitCloneLines } diff --git a/Extensions/Git.Commit.UGit.Extension.ps1 b/Extensions/Git.Commit.UGit.Extension.ps1 index 033434bc..f40e65b4 100644 --- a/Extensions/Git.Commit.UGit.Extension.ps1 +++ b/Extensions/Git.Commit.UGit.Extension.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS git commit extension .DESCRIPTION @@ -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]@{ @@ -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 '^\[(?\S+)\s(?[a-f0-9]+)\]') { + if ($commitLines[$cln] -match '^\[(?\S+)\s(?[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. diff --git a/Extensions/Git.Diff.UGit.Extension.ps1 b/Extensions/Git.Diff.UGit.Extension.ps1 index b1384188..863bf14d 100644 --- a/Extensions/Git.Diff.UGit.Extension.ps1 +++ b/Extensions/Git.Diff.UGit.Extension.ps1 @@ -1,4 +1,4 @@ -<# +<# .Synopsis Diff Extension .Description @@ -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(?[0-9a-f]+)..(?[0-9a-f]+)') { $diffObject.FromHash, $diffObject.ToHash = $Matches.fromhash, $Matches.tohash @@ -36,7 +51,7 @@ begin { if ($diffRange) { $diffObject.ChangeSet += [PSCustomObject]$diffRange } - + $extendedHeader = $outputLine -replace '^@@[^@]+@@' -replace '^\s+' $diffRange = [Ordered]@{ PSTypeName='git.diff.range'; @@ -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 } @@ -71,7 +86,7 @@ begin { } -process { +process { if ("$gitOut" -like 'diff*' -and $lines) { OutDiff $lines.ToArray() $lines.Clear() diff --git a/Extensions/Git.FileOutput.UGit.Extension.ps1 b/Extensions/Git.FileOutput.UGit.Extension.ps1 index 02d373f0..a35617aa 100644 --- a/Extensions/Git.FileOutput.UGit.Extension.ps1 +++ b/Extensions/Git.FileOutput.UGit.Extension.ps1 @@ -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 diff --git a/Extensions/Git.Init.UGit.Extension.ps1 b/Extensions/Git.Init.UGit.Extension.ps1 index 7a780426..777372e8 100644 --- a/Extensions/Git.Init.UGit.Extension.ps1 +++ b/Extensions/Git.Init.UGit.Extension.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS git init extension .DESCRIPTION @@ -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 } } diff --git a/Extensions/Git.Log.UGit.Extension.ps1 b/Extensions/Git.Log.UGit.Extension.ps1 index fd5959fb..1f61c4aa 100644 --- a/Extensions/Git.Log.UGit.Extension.ps1 +++ b/Extensions/Git.Log.UGit.Extension.ps1 @@ -5,12 +5,12 @@ Outputs git log as objects. .Example # Get all logs - git log | + git log | # until the first merged pull request Where-Object -Not Merged .Example # Get a single log entry - git log -n 1 | + git log -n 1 | # and see what the log object can do. Get-Member .Example @@ -19,11 +19,11 @@ # Group them by the author Group-Object GitUserEmail -NoElement | # sort them by count - Sort-Object Count -Descending + Sort-Object Count -Descending .Example # Get all logs git log | - # Group them by day of week + # Group them by day of week Group-Object { $_.CommitDate.DayOfWeek } -NoElement .Example # Get all logs @@ -71,7 +71,7 @@ begin { if (-not $OutputLines) { return } $gitLogMatch = $Git_Log.Match($OutputLines -join [Environment]::NewLine) if (-not $gitLogMatch.Success) { return } - + $gitLogOut = [Ordered]@{PSTypeName='git.log';GitArgument=$gitArgument} if ($gitCommand -like '*--merges*') { $gitLogOut.PSTypeName = 'git.merge.log' @@ -82,7 +82,7 @@ begin { $gitLogOut[$group.Name] = $group.Value } else { $gitLogOut[$group.Name] = @( $gitLogOut[$group.Name] ) + $group.Value - } + } } $gitLogOut.Remove("HexDigits") if ($gitLogOut.CommitDate) { @@ -91,7 +91,7 @@ begin { if ($gitLogOut.CommitMessage) { $gitLogOut.CommitMessage = $gitLogOut.CommitMessage.Trim() } - if ($gitLogOut.MergeHash -and + if ($gitLogOut.MergeHash -and $gitLogOut.CommitMessage -notmatch '^merge branch') { $script:LogChangesMerged = $true if ($gitLogOut.CommitMessage -match '^Merge pull request \#(?\d+)') { @@ -100,7 +100,7 @@ begin { if ($gitLogOut.CommitMessage -match 'from[\r\n\s]{0,}(?\S+)') { $gitLogOut.Source = $matches.Src } - } + } elseif ( $gitLogOut.MergeHash ) { @@ -111,7 +111,7 @@ begin { $gitLogOut.Destination = $matches.Branch } } - + $gitLogOut.Merged = $script:LogChangesMerged $gitLogOut.GitRoot = $GitRoot [PSCustomObject]$gitLogOut @@ -120,10 +120,10 @@ begin { process { - + if ("$gitOut" -like 'Commit*' -and $lines) { OutGitLog $lines - + $lines = @() } $lines += "$gitOut" diff --git a/Extensions/Git.Mv.UGit.Extension.ps1 b/Extensions/Git.Mv.UGit.Extension.ps1 index a5d90c44..5ce3a1c4 100644 --- a/Extensions/Git.Mv.UGit.Extension.ps1 +++ b/Extensions/Git.Mv.UGit.Extension.ps1 @@ -1,4 +1,4 @@ -<# +<# .Synopsis Git Move Extension .Description @@ -14,7 +14,7 @@ param( ) begin { - $moveLines = @() + $moveLines = @() } process { @@ -26,17 +26,17 @@ end { return $moveLines } - # Take all non-dashed arguments to git. + # Take all non-dashed arguments to git. $cmd, # The first is 'mv' - $source, # The second is the source + $source, # The second is the source $dest, # The third is the detination. $null = # (ignore anything else) $gitArgument -notlike '-*' if (-not (Test-Path $dest)) { return $moveLines } - $destItem = Get-Item $dest -ErrorAction SilentlyContinue - @(if ($destItem -is [IO.DirectoryInfo]) { + $destItem = Get-Item $dest -ErrorAction SilentlyContinue + @(if ($destItem -is [IO.DirectoryInfo]) { $destItem = Get-Item (Join-Path $destItem $source) $destItem } elseif ($destItem) { diff --git a/Extensions/Git.Pull.UGit.Extension.ps1 b/Extensions/Git.Pull.UGit.Extension.ps1 index 399dbc85..12019036 100644 --- a/Extensions/Git.Pull.UGit.Extension.ps1 +++ b/Extensions/Git.Pull.UGit.Extension.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS git pull extension .DESCRIPTION @@ -28,8 +28,8 @@ end { [PSCustomObject]@{UpToDate=$true;GitRoot=$GitRoot;PSTypeName='git.pull.no.update'} } elseif ($pullLines -match '^Fast-forward$' -or $pullLines -match "'(?[^']+)'\s{1}strategy\.$") { - - $gitPullOut = + + $gitPullOut = if ($pullLines -match '^Fast-forward$') { @{PSTypeName='git.pull.fastforward';GitRoot=$gitRoot;Changes=@();NewFiles=@()} } else { @@ -44,9 +44,9 @@ end { } break } - } + } } - + foreach ($pl in $pullLines) { if ($pl -match '^From http') { $null, $gitPullOut.GitUrl = $pl -split ' ' @@ -66,34 +66,34 @@ end { $gitPullOut.LastCommitHash = $matches.o $gitPullOut.CommitHash = $matches.n } - elseif ($pl -match '^\s\d+') # If the line starts with a space and digits - { + elseif ($pl -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 ($linePart in $pl -split ',' -replace '[\s\w\(\)-[\d]]') { - - if ($linePart.Contains('+')) { + + if ($linePart.Contains('+')) { # If the part contains +, it's insertions. $gitPullout.Insertions = $linePart -replace '\+' -as [int] - } - elseif ($linePart.Contains('-')) + } + elseif ($linePart.Contains('-')) { # If the part contains -, it's deletions. $gitPullout.Deletions = $linePart -replace '\-' -as [int] - } + } else { # Otherwise, its the file change count. $gitPullout.FilesChanged = $linePart -as [int] } - } + } } elseif ($pl -match 'create\smode\s(?\d+)\s(?\S+)') { $gitPullOut.NewFiles += $matches.FilePath } - + if ($pl -like ' *|*') { $nameOfFile, $fileChanges = $pl -split '\|' - $nameOfFile = $nameOfFile -replace '^\s+' -replace '\s+$' + $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 @@ -108,8 +108,8 @@ end { } } $gitPullOut.NewFiles = @(foreach ($nf in $gitPullOut.NewFiles) { - - try { Get-Item (Join-Path $gitPullOut.GitRoot $nf ) -ErrorAction SilentlyContinue } catch { $null } + + try { Get-Item (Join-Path $gitPullOut.GitRoot $nf ) -ErrorAction SilentlyContinue } catch { $null } }) $gitPullOut.GitOutputLines = $pullLines [PSCustomObject]$gitPullOut diff --git a/Extensions/Git.Push.UGit.Extension.ps1 b/Extensions/Git.Push.UGit.Extension.ps1 index 38521a5a..390f90d4 100644 --- a/Extensions/Git.Push.UGit.Extension.ps1 +++ b/Extensions/Git.Push.UGit.Extension.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS git push .DESCRIPTION @@ -28,7 +28,7 @@ end { $IsFirst = ($pushLines -match $pushFirstCommitRegex) -as [bool] $IsUpdate = ($pushLines -match $pushCommitHashRegex) -as [bool] # If the push has no lines with a commit hash and is not an update - if (-not ($IsFirst -or $IsUpdate)) { + if (-not ($IsFirst -or $IsUpdate)) { $pushLines # output directly. return } @@ -36,14 +36,14 @@ end { if ($IsUpdate) { # Create a hashtable to store output $pushOutput = [Ordered]@{PSTypeName='git.push.info'} - + foreach ($pl in $pushLines) { if ($pl -match '^To http') { $to, $GitUrl = $pl -split ' ' # Pick out the url from the line starting with To http $pushOutput.GitUrl = $GitUrl -join ' ' } - + if ($pl -match $pushCommitHashRegex) { # The line with the commit hash has the prior hash and the current has $pushOutput.LastCommitHash = $matches.o diff --git a/Extensions/Git.RefLog.UGit.Extension.ps1 b/Extensions/Git.RefLog.UGit.Extension.ps1 index 54f8a4a4..8b29daaf 100644 --- a/Extensions/Git.RefLog.UGit.Extension.ps1 +++ b/Extensions/Git.RefLog.UGit.Extension.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS git reflog .DESCRIPTION @@ -35,5 +35,5 @@ end { $refExtract.GitRoot = $GitRoot $refExtract.PSTypeName = 'Git.Reference.Log' [PSCustomObject]$refExtract - } + } } \ No newline at end of file diff --git a/Extensions/Git.Rm.UGit.Extension.ps1 b/Extensions/Git.Rm.UGit.Extension.ps1 index 3b6db587..bdbfc56a 100644 --- a/Extensions/Git.Rm.UGit.Extension.ps1 +++ b/Extensions/Git.Rm.UGit.Extension.ps1 @@ -1,4 +1,4 @@ -<# +<# .Synopsis Git Remove Extension .Description @@ -12,7 +12,7 @@ param( ) begin { - $removeLines = @() + $removeLines = @() } process { @@ -37,6 +37,6 @@ end { } } else { $line - } - } + } + } } diff --git a/Extensions/Git.Shortlog.UGit.Extension.ps1 b/Extensions/Git.Shortlog.UGit.Extension.ps1 index 7d3b4400..becb1156 100644 --- a/Extensions/Git.Shortlog.UGit.Extension.ps1 +++ b/Extensions/Git.Shortlog.UGit.Extension.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS git shortlog extension .DESCRIPTION @@ -54,8 +54,8 @@ end { $shortLogExtract.Commits = @() $shortLogExtract.GitRoot = $GitRoot $shortLogExtract.PSTypeName = 'Git.Shortlog' - $currentCommitter = $shortLogExtract - } elseif ($currentCommitter -and + $currentCommitter = $shortLogExtract + } elseif ($currentCommitter -and $shortlogLine -match $CommitMessageLineRegex) { $currentCommitter.Commits += $matches.CommitMessage } diff --git a/Extensions/Git.Stash.UGit.Extension.ps1 b/Extensions/Git.Stash.UGit.Extension.ps1 index 89174a5b..1d36aa62 100644 --- a/Extensions/Git.Stash.UGit.Extension.ps1 +++ b/Extensions/Git.Stash.UGit.Extension.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS git stash extension .DESCRIPTION @@ -24,13 +24,13 @@ end { # If we don't know how to handle output, we want to output normally. # So keep track if we know. $stashOutputHandled = $false - + # If the command is stash show --patch, if ($GitCommand -match 'stash show(?:\s\d+)? -(?>p|-patch)') { - # the diff extension will actually be handling things. + # the diff extension will actually be handling things. return } - + # Create a base output object $gitStashOut = [Ordered]@{ GitRoot = $GitRoot @@ -60,7 +60,7 @@ end { if ($stashLine -eq 'No local changes to save') { # return a 'git.stash.nothing' object. return [PSCustomObject]([Ordered]@{ - PSTypeName = 'git.stash.nothing' + PSTypeName = 'git.stash.nothing' } + $gitStashOut) } @@ -89,7 +89,7 @@ end { PSTypeName = 'git.stash.entry' Number = [int]0 Message = $matches.Message - } + $gitStashOut) + } + $gitStashOut) } # If we are popping or applying a stash @@ -97,7 +97,7 @@ end { # The first line contains the branch name if ($stashLineNumber -eq 1) { # (in the last word). - $gitStashOut.BranchName = @($stashLine -split ' ' -ne '')[-1] + $gitStashOut.BranchName = @($stashLine -split ' ' -ne '')[-1] } # Everything else returns like git status. # use certain lines to indicate we are changing phases @@ -107,7 +107,7 @@ end { continue } if ($stashLine -like "Changes to be committed:*") { - + $inPhase = 'Staged' continue } @@ -127,7 +127,7 @@ end { # Lines that start with whitespace tell us what files were applied if ($stashLine -match '^\s+' -and $inPhase) { $trimmedLine = $stashLine.Trim() - $changeType = + $changeType = # The changetype will be in parenthesis if ( $trimmedLine -match "^([\w\s]+):") { $matches.1 @@ -145,7 +145,7 @@ end { Path = $changePath File = Get-Item -ErrorAction SilentlyContinue -Path $changePath } - } + } } } @@ -156,7 +156,7 @@ end { Number = [int]$matches.Number CommitHash = $matches.CommitHash } - + # If the command was 'git stash drop' if ($GitCommand -match '^git stash drop') { # return the drop info @@ -166,7 +166,7 @@ end { } else { # Otherwise, add this to the gitStashOutput. $gitStashOut.Dropped = [PSCustomObject]([Ordered]@{ - PSTypeName = 'git.stash.drop' + PSTypeName = 'git.stash.drop' } + $dropInfo) } } diff --git a/Extensions/Git.Status.UGit.Extension.ps1 b/Extensions/Git.Status.UGit.Extension.ps1 index 5daf72fa..fb5e09c5 100644 --- a/Extensions/Git.Status.UGit.Extension.ps1 +++ b/Extensions/Git.Status.UGit.Extension.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS git status extension .DESCRIPTION @@ -18,7 +18,7 @@ begin { <# If any of these parameters are used, we will skip processing. #> - $SkipIf = 'porcelain' -join '|' + $SkipIf = 'porcelain' -join '|' if ($gitCommand -match "\s-(?>$SkipIf)") { break } $statusLines = @() @@ -43,7 +43,7 @@ end { for ($sln = 0; $sln -lt $statusLines.Length; $sln++) { if ($sln -eq 0) { - $gitStatusOut.BranchName = @($statusLines[$sln] -split ' ' -ne '')[-1] + $gitStatusOut.BranchName = @($statusLines[$sln] -split ' ' -ne '')[-1] continue } if ($statusLines[$sln] -like '*not staged for commit:*') { @@ -58,7 +58,7 @@ end { $inPhase = 'Untracked' continue } - + if ($sln -eq 1 -and -not $inPhase) { $gitStatusOut.Status = $statusLines[$sln] continue @@ -67,7 +67,7 @@ end { if ($statusLines[$sln] -match '^\s+\(') { continue } if ($statusLines[$sln] -match '^\s+' -and $inPhase) { $trimmedLine = $statusLines[$sln].Trim() - $changeType = + $changeType = if ( $trimmedLine -match "^([\w\s]+):") { $matches.1 } else { @@ -83,7 +83,7 @@ end { File = Get-Item -ErrorAction SilentlyContinue -Path $changePath } } - + } } diff --git a/Formatting/Git.Pull.Format.ps1 b/Formatting/Git.Pull.Format.ps1 index 81d065ec..c51420e9 100644 --- a/Formatting/Git.Pull.Format.ps1 +++ b/Formatting/Git.Pull.Format.ps1 @@ -44,7 +44,7 @@ Write-FormatView -TypeName Git.Pull.FastForward, Git.Pull.Strategy -Action { Write-FormatViewExpression -Newline Write-FormatViewExpression -ScriptBlock { " $($_.FilesChanged) files changed" - } -ForegroundColor verbose + } -ForegroundColor verbose -If { $_.Changes } Write-FormatViewExpression -If { $_.Insertions } -ScriptBlock { diff --git a/Get-UGitExtension.ps1 b/Get-UGitExtension.ps1 index cacfb871..a6fcc3dc 100644 --- a/Get-UGitExtension.ps1 +++ b/Get-UGitExtension.ps1 @@ -1,4 +1,4 @@ -#region Piecemeal [ 0.3.5 ] : Easy Extensible Plugins for PowerShell +#region Piecemeal [ 0.3.7 ] : Easy Extensible Plugins for PowerShell # Install-Module Piecemeal -Scope CurrentUser # Import-Module Piecemeal -Force # Install-Piecemeal -ExtensionModule 'ugit' -ExtensionModuleAlias 'git' -ExtensionNoun 'UGitExtension' -ExtensionTypeName 'ugit.extension' -OutputPath '.\Get-UGitExtension.ps1' @@ -420,7 +420,7 @@ function Get-UGitExtension } } elseif ($attr -is [Management.Automation.ValidatePatternAttribute]) { - $matched = [Regex]::new($attr.RegexPattern, $attr.Options, [Timespan]::FromSeconds(1)).Match($ValidateInput) + $matched = [Regex]::new($attr.RegexPattern, $attr.Options, [Timespan]::FromSeconds(1)).Match("$ValidateInput") if (-not $matched.Success) { if ($allValid) { if ($ErrorActionPreference -eq 'ignore') { @@ -604,11 +604,20 @@ function Get-UGitExtension $params = @{} $mappedParams = [Ordered]@{} # Create a collection of mapped parameters # Walk thru each parameter of this command - foreach ($myParam in $paramSet.Parameters) { + :nextParameter foreach ($myParam in $paramSet.Parameters) { # If the parameter is ValueFromPipeline if ($myParam.ValueFromPipeline) { + $potentialPSTypeNames = @($myParam.Attributes.PSTypeName) -ne '' + if ($potentialPSTypeNames) { + foreach ($potentialTypeName in $potentialPSTypeNames) { + if ($potentialTypeName -and $InputObject.pstypenames -contains $potentialTypeName) { + $mappedParams[$myParam.Name] = $params[$myParam.Name] = $InputObject + continue nextParameter + } + } + } # and we have an input object - if ($null -ne $inputObject -and + elseif ($null -ne $inputObject -and ( # of the exact type $myParam.ParameterType -eq $inputObject.GetType() -or @@ -927,5 +936,5 @@ function Get-UGitExtension } } } -#endregion Piecemeal [ 0.3.5 ] : Easy Extensible Plugins for PowerShell +#endregion Piecemeal [ 0.3.7 ] : Easy Extensible Plugins for PowerShell diff --git a/README.md b/README.md index 1e8b9a6e..8090492e 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,7 @@ It will attempt to locate any output specified by -o and return it as a file or ~~~PowerShell # Get all logs - git log | + git log | # until the first merged pull request Where-Object -Not Merged ~~~ @@ -228,7 +228,7 @@ It will attempt to locate any output specified by -o and return it as a file or ~~~PowerShell # Get a single log entry - git log -n 1 | + git log -n 1 | # and see what the log object can do. Get-Member ~~~ @@ -251,7 +251,7 @@ It will attempt to locate any output specified by -o and return it as a file or ~~~PowerShell # Get all logs git log | - # Group them by day of week + # Group them by day of week Group-Object { $_.CommitDate.DayOfWeek } -NoElement ~~~ diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index fd1b3bb6..1074ac75 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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) diff --git a/docs/Git.Log-Extension.md b/docs/Git.Log-Extension.md index 597f03cc..fd4b410f 100644 --- a/docs/Git.Log-Extension.md +++ b/docs/Git.Log-Extension.md @@ -14,7 +14,7 @@ Outputs git log as objects. #### EXAMPLE 1 ```PowerShell # Get all logs -git log | +git log | # until the first merged pull request Where-Object -Not Merged ``` @@ -22,7 +22,7 @@ git log | #### EXAMPLE 2 ```PowerShell # Get a single log entry -git log -n 1 | +git log -n 1 | # and see what the log object can do. Get-Member ``` @@ -41,7 +41,7 @@ git log | ```PowerShell # Get all logs git log | - # Group them by day of week + # Group them by day of week Group-Object { $_.CommitDate.DayOfWeek } -NoElement ``` diff --git a/docs/README.md b/docs/README.md index 16526853..39d72bac 100644 --- a/docs/README.md +++ b/docs/README.md @@ -218,7 +218,7 @@ It will attempt to locate any output specified by -o and return it as a file or ~~~PowerShell # Get all logs - git log | + git log | # until the first merged pull request Where-Object -Not Merged ~~~ @@ -228,7 +228,7 @@ It will attempt to locate any output specified by -o and return it as a file or ~~~PowerShell # Get a single log entry - git log -n 1 | + git log -n 1 | # and see what the log object can do. Get-Member ~~~ @@ -251,7 +251,7 @@ It will attempt to locate any output specified by -o and return it as a file or ~~~PowerShell # Get all logs git log | - # Group them by day of week + # Group them by day of week Group-Object { $_.CommitDate.DayOfWeek } -NoElement ~~~ diff --git a/ugit.format.ps1xml b/ugit.format.ps1xml index cf4b99a7..b87f09c8 100644 --- a/ugit.format.ps1xml +++ b/ugit.format.ps1xml @@ -1548,6 +1548,9 @@ $BackgroundColor @(& ${ugit_Format-RichText} -ForegroundColor 'verbose' -NoClear) -join '' + + $_.Changes + " $($_.FilesChanged) files changed" diff --git a/ugit.psd1 b/ugit.psd1 index 0d9add42..add59a9f 100644 --- a/ugit.psd1 +++ b/ugit.psd1 @@ -1,5 +1,5 @@ @{ - ModuleVersion = '0.3.1' + ModuleVersion = '0.3.2' RootModule = 'ugit.psm1' FormatsToProcess = 'ugit.format.ps1xml' TypesToProcess = 'ugit.types.ps1xml' @@ -15,7 +15,15 @@ PrivateData = @{ Tags = 'PowerShell', 'git' ProjectURI = 'https://github.com/StartAutomating/ugit' LicenseURI = 'https://github.com/StartAutomating/ugit/blob/main/LICENSE' + BuildModule = @('EZOut', 'Piecemeal', 'PipeScript') ReleaseNotes = @' +## 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)