-
-
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 #5 from StartAutomating/MoreGitUpdates
More git updates
- Loading branch information
Showing
8 changed files
with
333 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## 0.1.1 | ||
* Support for git commit (#4) | ||
--- | ||
## 0.1 | ||
* Initial Release of ugit | ||
--- |
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,74 @@ | ||
<# | ||
.SYNOPSIS | ||
git commit extension | ||
.DESCRIPTION | ||
Returns output from succesful git commits as objects. | ||
#> | ||
[Management.Automation.Cmdlet("Out","Git")] | ||
[ValidatePattern("^git commit")] | ||
[OutputType('git.commit.info')] | ||
param() | ||
|
||
begin { | ||
$commitLines = @() | ||
} | ||
|
||
process { | ||
$commitLines += $gitOut | ||
} | ||
|
||
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 | ||
{ | ||
# Otherwise initialize commit information | ||
$commitInfo = [Ordered]@{ | ||
FilesChanged = 0 | ||
Insertions = 0 | ||
Deletions = 0 | ||
GitRoot = $GitRoot | ||
PSTypeName = 'git.commit.info' | ||
} | ||
# 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 '^\[(?<n>\S+)\s(?<h>[a-f0-9]+)\]') { | ||
$commitInfo.BranchName = $matches.n # set .BranchName, | ||
$commitInfo.CommitHash = $matches.h # set .CommitHash | ||
$commitInfo.CommitMessage = # and set .CommitMessage to the rest of the line. | ||
$commitLines[$cln] -replace '^\[[^\]]+\]\s+' | ||
} | ||
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 the part contains +, it's insertions. | ||
$commitInfo.Insertions = $commitLinePart -replace '\+' -as [int] | ||
} | ||
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. | ||
$commitInfo.CommitMessage += [Environment]::NewLine + $commitLines[$cln] | ||
} | ||
} | ||
# After we have walked thru all lines, output the commit info. | ||
[PSCustomObject]$commitInfo | ||
} | ||
} |
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,20 @@ | ||
Write-FormatView -TypeName Git.Commit.Info -Action { | ||
Write-FormatViewExpression -ScriptBlock { | ||
"[$($_.BranchName) $($_.CommitHash)] " | ||
} -ForegroundColor verbose | ||
Write-FormatViewExpression -Property CommitMessage | ||
Write-FormatViewExpression -Newline | ||
Write-FormatViewExpression -ScriptBlock { | ||
" $($_.FilesChanged) files changed" | ||
} -ForegroundColor verbose | ||
Write-FormatViewExpression -If { | ||
$_.Insertions | ||
} -ScriptBlock { | ||
", $($_.Insertions) insertions(+)" | ||
} -ForegroundColor Success | ||
Write-FormatViewExpression -If { | ||
$_.Deletions | ||
} -ScriptBlock { | ||
", $($_.Deletions) deletions(-)" | ||
} -ForegroundColor Error | ||
} |
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,74 @@ | ||
# ugit | ||
Updated Git: A powerful PowerShell wrapper for git that lets you extend git, automate multiple repos, and output git as objects. | ||
|
||
|
||
## What is ugit? | ||
|
||
ugit is a PowerShell module that gives you an updated git. You can use the object pipeline to pipe folders or files into git. | ||
If you're using one of a number of supported commands, ugit will return your git output as objects. | ||
This enables _a lot_ of interesting scenarios, giving you and updated way to work with git. | ||
|
||
## Getting started | ||
|
||
### Installing ugit | ||
~~~PowerShell | ||
Install-Module ugit -Scope CurrentUser | ||
Import-Module ugit -Force -PassThru | ||
# Once you've imported ugit, just run git commands normally. | ||
# If ugit has an extension for the command, it will output as an object. | ||
# These objects can be formatted by PowerShell | ||
git log -n 5 | ||
|
||
# To get a sense of what you can do, pipe a given git command into Get-Member. | ||
git log -n 5 | | ||
Get-Member | ||
~~~ | ||
|
||
|
||
## How ugit works: | ||
|
||
ugit only has a few commands: | ||
|
||
### Use-Git | ||
|
||
After you've imported ugit, Use-Git is what will be called when you run "git". | ||
|
||
This happens because Use-Git is aliased to "git", and aliases are resolved first in PowerShell. | ||
|
||
Use-Git assumes all positional parameters are arguments to Git, and passes them on directly. | ||
|
||
This works in almost every scenario, except with some single character git options. You can pass these in quotes. | ||
|
||
When Use-Git outputs, it sets $global:LastGitOutput and then pipes to Out-Git. | ||
|
||
### Out-Git | ||
|
||
Out-Git will attempt to take git output and return it as a useful object. | ||
|
||
This object can then be extended and formatted by PowerShell's Extended Type System. | ||
|
||
Out-Git accomplishes this with several extensions. You can list extensions with Get-UGitExtension: | ||
|
||
### Get-UGitExtension | ||
|
||
Get-UGitExtension enables any file beneath ugit (or a module that tags ugit) named *.ugit.extension.ps1 to be treated as an extension. | ||
|
||
In ugit, extensions signal that they apply to a given git command by adding a ```[ValidatePattern]``` attribute to the command. | ||
|
||
If this pattern matches the given git command, the extension will run. | ||
|
||
Get-UGitExtension is built using [Piecemeal](https://github.com/StartAutomating/Piecemeal) | ||
|
||
## Git Commands Extended | ||
|
||
* git branch | ||
* git diff | ||
* git log | ||
* git status | ||
|
||
### Extensions that may apply to any git command: | ||
|
||
* git.fileoutput extension. | ||
|
||
This applies to an git command that uses the -o flag. | ||
It will attempt to locate any output specified by -o and return it as a file or directory. |
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