-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #208 from StartAutomating/ugit-the-blame
ugit 0.4.2
- Loading branch information
Showing
17 changed files
with
346 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = @( | ||
'(?<CommitHash>[0-9a-f]{8})\s' | ||
|
||
# If your filename contains parenthesis, this may not work, and you'll only have yourself to blame. | ||
'(?:(?<FileName>[\S-[\(]]+)\s)?' | ||
|
||
'\((?<WhoWhenWhat>.+?)\)' | ||
) -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 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
git.blame |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
Push-Location $this.GitRoot | ||
git log $this.CommitHash -NumberOfCommits 1 | ||
Pop-Location |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Write-FormatView -TypeName git.blame -GroupByProperty GitRoot -Property CommitHash, Author, CommitDate, Line, Content -AlignProperty @{ | ||
'Line' = 'Right' | ||
'Content' = 'Left' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 [<CommonParameters>] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <Int32[]>] [-Pattern <String[]>] [<CommonParameters>] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.