diff --git a/CHANGELOG.md b/CHANGELOG.md index 06cf0449..f34773fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 0.4.2: + +* git blame support (#192, #193, #199, #201) +* Use-Git will write to Verbose, not warning, when a directory is not a repository (#198, #204) +* ugit PSA improvements (#189, #205, #206, #207) + +--- + ## 0.4.1: * New Git Command Support: diff --git a/Extensions/Git.Blame.Input.ugit.extension.ps1 b/Extensions/Git.Blame.Input.ugit.extension.ps1 new file mode 100644 index 00000000..edda0c03 --- /dev/null +++ b/Extensions/Git.Blame.Input.ugit.extension.ps1 @@ -0,0 +1,50 @@ +<# +.SYNOPSIS + Extends git blame's parameters +.DESCRIPTION + Extends the parameters for git blame. +#> +[ValidatePattern('^git blame')] +[Management.Automation.Cmdlet("Use","Git")] +[CmdletBinding(PositionalBinding=$false)] +param( +# The line number (and relative offset) +[Parameter(ValueFromPipelineByPropertyName)] +[int[]] +$LineNumber, + +# The blame pattern to look for. +[Parameter(ValueFromPipelineByPropertyName)] +[string[]] +$Pattern +) + +process { + + # All git of these git blame parameters need to be after the input object: + foreach ($gitArgToBe in @( + if ($LineNumber) { # If a -LineNumber was provided + # turn each pair into a range + for ($LineNumberNumber = 0; $LineNumberNumber -lt $LineNumber.Length; $LineNumberNumber++) { + "-L" # (this will be specified by git blame's real parameter, '-L') + "$( + if ($LineNumberNumber -lt ($LineNumber.Length - 1)) { + "$($lineNumber[$LineNumberNumber]),$($lineNumber[$LineNumberNumber + 1])" + } else { + # if there was only one of a pair, only grab that line. + "$($lineNumber[$LineNumberNumber]),1" + } + )" + } + } + + if ($Pattern) { # If a -Pattern was provided + foreach ($linePattern in $pattern) { + "-L" # this also becomes '-L' in git blame + "$linePattern" + } + } + )) { + $gitArgToBe | Add-Member NoteProperty AfterInput $true -Force -PassThru + } +} diff --git a/Extensions/Git.Blame.UGit.extension.ps1 b/Extensions/Git.Blame.UGit.extension.ps1 new file mode 100644 index 00000000..9b2f7be7 --- /dev/null +++ b/Extensions/Git.Blame.UGit.extension.ps1 @@ -0,0 +1,61 @@ +<# +.SYNOPSIS + Parses git blame output +.DESCRIPTION + Parses the output of git blame. +.EXAMPLE + git blame ugit.psd1 +#> +[Management.Automation.Cmdlet("Out","Git")] # It's an extension for Out-Git +[ValidatePattern("^u?git blame",Options='IgnoreCase')] # when the pattern is "git blame" +param() + +begin { + $gitBlameOutput = @() + $blameHeaderPattern = @( + '(?[0-9a-f]{8})\s' + + # If your filename contains parenthesis, this may not work, and you'll only have yourself to blame. + '(?:(?[\S-[\(]]+)\s)?' + + '\((?.+?)\)' + ) -join '' + $blameRevision = @($gitCommand -split '\s' -notmatch '^--')[-1] +} + +process { + $gitBlameOutput += $gitout +} + +end { + $blameObjects = @( + foreach ($gitBlameLine in $gitBlameOutput) { + if ($gitBlameLine -notmatch $blameHeaderPattern) { continue } + $lineContent = $gitBlameLine -replace $blameHeaderPattern + $commitMatch = [Ordered]@{} + $matches + $whoWhenWhat = $commitMatch.WhoWhenWhat -split '\s+' + + [PSCustomObject][Ordered]@{ + PSTypeName = 'git.blame' + CommitHash = $commitMatch.CommitHash + CommitDate = ($whoWhenWhat[-4..-2] -join ' ') -as [DateTime] + Line = $whoWhenWhat[-1] + File = $matches.File + Revision = $blameRevision + Content = $lineContent + GitRoot = $GitRoot + Author = $whoWhenWhat[0..$( + ($whoWhenWhat.Length - 5) + )] -join ' ' + GitOutputLines = $gitBlameLine + } + } + ) + + if ($blameObjects) { + $blameObjects + } else { + $gitBlameOutput + } +} + diff --git a/README.md b/README.md index acc7b637..635b1a87 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,13 @@ Get-UGitExtension is built using [Piecemeal](https://github.com/StartAutomating/ ugit comes packed with many examples. You might want to try giving some of these a try. +### Git.Blame Example 1 + + +~~~PowerShell + git blame ugit.psd1 +~~~ + ### Git.Branch Example 1 @@ -392,6 +399,9 @@ You might want to try giving some of these a try. Most extensions handle output from a single git command. +* [Git Blame](docs/Git.Blame-Extension.md) + + * [Git Branch](docs/Git.Branch-Extension.md) @@ -472,6 +482,9 @@ It will attempt to locate any output specified by -o and return it as a file or ugit also allows you to extend the input for git. +* [Git Blame Input](docs/Git.Blame.Input-Extension.md) + + * [Git Clone Input](docs/Git.Clone.Input-Extension.md) diff --git a/Types/git.blame/PSTypeName.txt b/Types/git.blame/PSTypeName.txt new file mode 100644 index 00000000..af41d9e4 --- /dev/null +++ b/Types/git.blame/PSTypeName.txt @@ -0,0 +1 @@ +git.blame diff --git a/Types/git.blame/get_Log.ps1 b/Types/git.blame/get_Log.ps1 new file mode 100644 index 00000000..e1307fff --- /dev/null +++ b/Types/git.blame/get_Log.ps1 @@ -0,0 +1,4 @@ + +Push-Location $this.GitRoot +git log $this.CommitHash -NumberOfCommits 1 +Pop-Location \ No newline at end of file diff --git a/Types/git.blame/git.blame.format.ps1 b/Types/git.blame/git.blame.format.ps1 new file mode 100644 index 00000000..98b3deff --- /dev/null +++ b/Types/git.blame/git.blame.format.ps1 @@ -0,0 +1,4 @@ +Write-FormatView -TypeName git.blame -GroupByProperty GitRoot -Property CommitHash, Author, CommitDate, Line, Content -AlignProperty @{ + 'Line' = 'Right' + 'Content' = 'Left' +} diff --git a/Use-Git.ps1 b/Use-Git.ps1 index f0f1f5c8..e23d3403 100644 --- a/Use-Git.ps1 +++ b/Use-Git.ps1 @@ -319,7 +319,7 @@ if (-not $script:RepoRoots[$dir] -and # If we did not have a repo root -not ($gitArgument -match "(?>$($RepoNotRequired -join '|'))") # and we are not doing an operation that does not require one ) { - Write-Warning "'$($dir)' is not a git repository" # warn that there is no repo (#21) + Write-Verbose "'$($dir)' is not a git repository" # write that there is no repo to verbose (#21 , #198, #204) Pop-Location # pop back out of the directory continue nextDirectory # and continue to the next directory. } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 46cf79de..35cbb9cc 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,11 @@ +## 0.4.2: + +* git blame support (#192, #193, #199, #201) +* Use-Git will write to Verbose, not warning, when a directory is not a repository (#198, #204) +* ugit PSA improvements (#189, #205, #206, #207) + +--- + ## 0.4.1: * New Git Command Support: diff --git a/docs/Git.Blame-Extension.md b/docs/Git.Blame-Extension.md new file mode 100644 index 00000000..68ba7b33 --- /dev/null +++ b/docs/Git.Blame-Extension.md @@ -0,0 +1,38 @@ +Extensions/Git.Blame.UGit.extension.ps1 +--------------------------------------- + + + + +### Synopsis +Parses git blame output + + + +--- + + +### Description + +Parses the output of git blame. + + + +--- + + +### Examples +> EXAMPLE 1 + +```PowerShell +git blame ugit.psd1 +``` + + +--- + + +### Syntax +```PowerShell +Extensions/Git.Blame.UGit.extension.ps1 [] +``` diff --git a/docs/Git.Blame.Input-Extension.md b/docs/Git.Blame.Input-Extension.md new file mode 100644 index 00000000..d4377287 --- /dev/null +++ b/docs/Git.Blame.Input-Extension.md @@ -0,0 +1,63 @@ +Extensions/Git.Blame.Input.ugit.extension.ps1 +--------------------------------------------- + + + + +### Synopsis +Extends git blame's parameters + + + +--- + + +### Description + +Extends the parameters for git blame. + + + +--- + + +### Parameters +#### **LineNumber** + +The line number (and relative offset) + + + + + + +|Type |Required|Position|PipelineInput | +|-----------|--------|--------|---------------------| +|`[Int32[]]`|false |named |true (ByPropertyName)| + + + +#### **Pattern** + +The blame pattern to look for. + + + + + + +|Type |Required|Position|PipelineInput | +|------------|--------|--------|---------------------| +|`[String[]]`|false |named |true (ByPropertyName)| + + + + + +--- + + +### Syntax +```PowerShell +Extensions/Git.Blame.Input.ugit.extension.ps1 [-LineNumber ] [-Pattern ] [] +``` diff --git a/docs/README.md b/docs/README.md index 9e1fa661..a0fc3271 100644 --- a/docs/README.md +++ b/docs/README.md @@ -73,6 +73,13 @@ Get-UGitExtension is built using [Piecemeal](https://github.com/StartAutomating/ ugit comes packed with many examples. You might want to try giving some of these a try. +### Git.Blame Example 1 + + +~~~PowerShell + git blame ugit.psd1 +~~~ + ### Git.Branch Example 1 @@ -392,6 +399,9 @@ You might want to try giving some of these a try. Most extensions handle output from a single git command. +* [Git Blame](Git.Blame-Extension.md) + + * [Git Branch](Git.Branch-Extension.md) @@ -472,6 +482,9 @@ It will attempt to locate any output specified by -o and return it as a file or ugit also allows you to extend the input for git. +* [Git Blame Input](Git.Blame.Input-Extension.md) + + * [Git Clone Input](Git.Clone.Input-Extension.md) diff --git a/ugit.ezout.ps1 b/ugit.ezout.ps1 index c4fabcfb..974334f2 100644 --- a/ugit.ezout.ps1 +++ b/ugit.ezout.ps1 @@ -7,7 +7,7 @@ Push-Location $myRoot $formatting = @( # Add your own Write-FormatView here, # or put them in a Formatting or Views directory - foreach ($potentialDirectory in 'Formatting','Views') { + foreach ($potentialDirectory in 'Formatting','Views','Types') { Join-Path $myRoot $potentialDirectory | Get-ChildItem -ea ignore | Import-FormatView -FilePath {$_.Fullname} diff --git a/ugit.format.ps1xml b/ugit.format.ps1xml index 042dc14e..2a46bd69 100644 --- a/ugit.format.ps1xml +++ b/ugit.format.ps1xml @@ -1,5 +1,5 @@ - + @@ -3036,5 +3036,51 @@ $BackgroundColor + + git.blame + + git.blame + + + GitRoot + + + + + + + + + + + Right + + + Left + + + + + + + CommitHash + + + Author + + + CommitDate + + + Line + + + Content + + + + + + diff --git a/ugit.psa.ps1 b/ugit.psa.ps1 index fefeccc3..5331b825 100644 --- a/ugit.psa.ps1 +++ b/ugit.psa.ps1 @@ -29,33 +29,23 @@ $importedModule = Import-Module .\ugit.psd1 -Global -PassThru $importedModule | Out-Host $moduleAndVersion = "$($importedModule.Name) $($importedModule.Version)" -$isManuallyTriggered = $gitHubEvent.psobject.properties["input"] +$isManuallyTriggered = $gitHubEvent.psobject.properties["inputs"] if ($isMergeToMain -or $isManuallyTriggered) { $fullMessage = @(switch ($importedModule.Version) { default { - "I've got to admit it's gitting better, gitting better all the time:", - "Somehow, someway, I keep coming up with funky git nearly every single day:", - "#git in the #PowerShell object pipeline!", - "Get your git together!", - "Put this git in your pipe and smoke it!", - "I promise you, git gets better", - "Git ahead of the game!" | - Get-Random - - "$moduleAndVersion" - - "https://github.com/StartAutomating/ugit" + $importedModule.PrivateData.PSData.Taglines | Get-Random + "$moduleAndVersion" } }) -join ([Environment]::NewLine * 2) Send-AtProto -Text $fullMessage -WebCard @{ - Url = "https://github.com/StartAutomating/ugit" + Url = $importedModule.PrivateData.PSData.ProjectURI } -LinkPattern @{ - "ugit" = "https://github.com/StartAutomating/ugit" + $importedModule.Name = $importedModule.PrivateData.PSData.ProjectURI } return diff --git a/ugit.psd1 b/ugit.psd1 index 1b8849ad..58baf2f3 100644 --- a/ugit.psd1 +++ b/ugit.psd1 @@ -1,5 +1,5 @@ @{ - ModuleVersion = '0.4.1' + ModuleVersion = '0.4.2' RootModule = 'ugit.psm1' FormatsToProcess = 'ugit.format.ps1xml' TypesToProcess = 'ugit.types.ps1xml' @@ -17,17 +17,11 @@ PrivateData = @{ LicenseURI = 'https://github.com/StartAutomating/ugit/blob/main/LICENSE' BuildModule = @('EZOut', 'Piecemeal', 'PipeScript', 'PSSVG') ReleaseNotes = @' -## 0.4.1: +## 0.4.2: -* New Git Command Support: - * git submodule status (#183) -* New Git ScriptMethods: - * git.branch.diff (#187) - * git.branch.rename (#86) -* Easier Input: - * git commit -CommitDate (#184) - * git log -CurrentBranch (fixing forks, #179) -* Announcing Releases with [PSA](https://github.com/StartAutomating/PSA) +* git blame support (#192, #193, #199, #201) +* Use-Git will write to Verbose, not warning, when a directory is not a repository (#198, #204) +* ugit PSA improvements (#189, #205, #206, #207) --- @@ -36,6 +30,15 @@ Like It? Start It. Love It? Support It. https://github.com/StartAutomating/ugit '@ + Taglines = @( + "I've got to admit it's gitting better, gitting better all the time:" + "Somehow, someway, I keep coming up with funky git nearly every single day:" + "#git in the #PowerShell object pipeline!" + "Get your git together!" + "Put this git in your pipe and smoke it!" + "I promise you, git gets better" + "Git ahead of the game!" + ) } } } \ No newline at end of file diff --git a/ugit.types.ps1xml b/ugit.types.ps1xml index 8dd843b3..a4f7cd91 100644 --- a/ugit.types.ps1xml +++ b/ugit.types.ps1xml @@ -1,6 +1,20 @@ - + + + git.blame + + + Log + + +Push-Location $this.GitRoot +git log $this.CommitHash -NumberOfCommits 1 +Pop-Location + + + + git.branch