Skip to content

Commit dac5e39

Browse files
Merge pull request #52 from StartAutomating/ugit-reflog
ugit reflog support
2 parents ddf0b2e + 443351a commit dac5e39

File tree

8 files changed

+281
-1
lines changed

8 files changed

+281
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.0:
2+
* Adding support for git reflog (#51)
3+
---
4+
15
## 0.1.9.1:
26
* Fixing git status duplicate message (#49)
37
---
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<#
2+
.SYNOPSIS
3+
git reflog
4+
.DESCRIPTION
5+
Outputs git reflog as objects.
6+
.EXAMPLE
7+
git reflog
8+
#>
9+
[Management.Automation.Cmdlet("Out","Git")]
10+
[ValidatePattern("^git reflog")]
11+
[OutputType('git.reference.log')]
12+
param()
13+
14+
begin {
15+
$refLogLines = @() # Create a list for all of the lines from a git reflog.
16+
# Declare a regex to match each one.
17+
$refLogRegex = [Regex]::new("^(?<Hash>[a-f0-9]+)\s{0,}(?<Name>[^@]+)@\{(?<Number>\d+)\}:\s{1,}(?<Command>[^:]+)\:(?<Message>.+)$")
18+
}
19+
20+
process {
21+
# Add each line to the list of lines from git reflog.
22+
$refLogLines += $gitOut
23+
}
24+
25+
end {
26+
if (-not $refLogLines) { return }
27+
if ($refLogLines -notmatch $refLogRegex) {
28+
return $refLogLines
29+
}
30+
31+
foreach ($refLogLine in $refLogLines) {
32+
$matched = $refLogLine -match $refLogRegex
33+
$refExtract = [Ordered]@{} + $matches
34+
$refExtract.Remove(0)
35+
$refExtract.PSTypeName = 'Git.Reference.Log'
36+
[PSCustomObject]$refExtract
37+
}
38+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Write-FormatView -TypeName Git.Reference.Log -Property Name, '#', Hash, Command, Message -VirtualProperty @{
2+
'#' = { $_.'Number' + ' '}
3+
Name = { $_.Name }
4+
Command = { $_.Command + ':'}
5+
} -AlignProperty @{
6+
Name = 'Right'
7+
'#' = 'Left'
8+
Command ='Right'
9+
Message = 'Left'
10+
}

docs/CHANGELOG.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## 0.2.0:
2+
* Adding support for git reflog (#51)
3+
---
4+
5+
## 0.1.9.1:
6+
* Fixing git status duplicate message (#49)
7+
---
8+
9+
## 0.1.9:
10+
* Support for eventing (#42)
11+
* Autogeneration of docs (#43)
12+
* Autogeneration of formatting (#44)
13+
* Fixing git status formatting (#45)
14+
---
15+
16+
## 0.1.8:
17+
* Adding Support for git checkout (#38)
18+
* Use-Git: Avoiding unwanted confirmation ( Fixing #39 )
19+
---
20+
21+
## 0.1.7:
22+
* Use-Git: -Verbose no longer infers --verbose (#10)
23+
* Out-Git: Support for extension caching (#35)
24+
* Out-Git: Using -ErrorAction Ignore when -Verbose is not passed (#36)
25+
* Get-UGitExtension: Updating Piecemeal Version [0.2.1]. (Re #32 #36)
26+
---
27+
28+
## 0.1.6
29+
* Adding support / formatting for git pull (#26)
30+
* Out-Git: Extension Improvements (#33)
31+
---
32+
33+
## 0.1.5
34+
* Adding git.log .Checkout() and Revert() (#27, #28)
35+
* Fixing formatting for git diff (#25)
36+
* Out-Git: Adding History (#30)
37+
* Use-Git: SupportsShouldProcess (#29)
38+
---
39+
40+
## 0.1.4
41+
* Adding git.log.reset() (#20)
42+
* Adding git clone extension (#17)
43+
* Use-Git: Running certain git commands when there is no repo (currently clone and init)
44+
* Use-Git: Support for progress bars (#18). Warning when repo not found (#21)
45+
* git branch extension: Adding example
46+
* Highlighting branch name (fixing #19)
47+
---
48+
49+
## 0.1.3:
50+
* Updating git.log extension: Adding .Merged (#16)
51+
* Updating git push extension: Support for first push (#14)
52+
* Adding .output to automatic typenames (Fixing #11)
53+
* Adding .ToString to git.branch and git.branch.detail (#9)
54+
* Updating git branch extension: Fixing --delete behavior (#13)
55+
* Use-Git: Support for -d/-D/-v/-V (#12). -Verbose implies --verbose (#10)
56+
---
57+
## 0.1.2
58+
* Support for git push (#7)
59+
* Adding .Amend/.UpdateMessage to git.commit.info (#6)
60+
---
61+
## 0.1.1
62+
* Support for git commit (#4)
63+
---
64+
## 0.1
65+
* Initial Release of ugit
66+
---

docs/Git.RefLog-Extension.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Extensions/Git.RefLog.UGit.Extension.ps1
3+
----------------------------------------
4+
### Synopsis
5+
git reflog
6+
7+
---
8+
### Description
9+
10+
Outputs git reflog as objects.
11+
12+
---
13+
### Examples
14+
#### EXAMPLE 1
15+
```PowerShell
16+
git reflog
17+
```
18+
19+
---
20+
### Outputs
21+
git.reference.log
22+
23+
24+
---
25+
### Syntax
26+
```PowerShell
27+
Extensions/Git.RefLog.UGit.Extension.ps1 [<CommonParameters>]
28+
```
29+
---
30+
31+

docs/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# ugit
2+
Updated Git: A powerful PowerShell wrapper for git that lets you extend git, automate multiple repos, and output git as objects.
3+
4+
5+
## What is ugit?
6+
7+
ugit is a PowerShell module that gives you an updated git. You can use the object pipeline to pipe folders or files into git.
8+
If you're using one of a number of supported commands, ugit will return your git output as objects.
9+
This enables _a lot_ of interesting scenarios, giving you and updated way to work with git.
10+
11+
## Getting started
12+
13+
### Installing ugit
14+
~~~PowerShell
15+
Install-Module ugit -Scope CurrentUser
16+
Import-Module ugit -Force -PassThru
17+
# Once you've imported ugit, just run git commands normally.
18+
# If ugit has an extension for the command, it will output as an object.
19+
# These objects can be formatted by PowerShell
20+
git log -n 5
21+
22+
# To get a sense of what you can do, pipe a given git command into Get-Member.
23+
git log -n 5 |
24+
Get-Member
25+
~~~
26+
27+
28+
## How ugit works:
29+
30+
ugit only has a few commands:
31+
32+
### Use-Git
33+
34+
After you've imported ugit, Use-Git is what will be called when you run "git".
35+
36+
This happens because Use-Git is aliased to "git", and aliases are resolved first in PowerShell.
37+
38+
Use-Git assumes all positional parameters are arguments to Git, and passes them on directly.
39+
40+
This works in almost every scenario, except with some single character git options. You can pass these in quotes.
41+
42+
When Use-Git outputs, it sets $global:LastGitOutput and then pipes to Out-Git.
43+
44+
### Out-Git
45+
46+
Out-Git will attempt to take git output and return it as a useful object.
47+
48+
This object can then be extended and formatted by PowerShell's Extended Type System.
49+
50+
Out-Git accomplishes this with several extensions. You can list extensions with Get-UGitExtension:
51+
52+
### Get-UGitExtension
53+
54+
Get-UGitExtension enables any file beneath ugit (or a module that tags ugit) named *.ugit.extension.ps1 to be treated as an extension.
55+
56+
In ugit, extensions signal that they apply to a given git command by adding a ```[ValidatePattern]``` attribute to the command.
57+
58+
If this pattern matches the given git command, the extension will run.
59+
60+
Get-UGitExtension is built using [Piecemeal](https://github.com/StartAutomating/Piecemeal)
61+
62+
## Git Commands Extended
63+
64+
* git branch
65+
* git commit
66+
* git clone
67+
* git diff
68+
* git log
69+
* git push
70+
* git status
71+
72+
73+
### Extensions that may apply to any git command:
74+
75+
* git.fileoutput
76+
77+
This applies to an git command that uses the -o flag.
78+
It will attempt to locate any output specified by -o and return it as a file or directory.

ugit.format.ps1xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,55 @@ $BackgroundColor
16381638
</CustomEntries>
16391639
</CustomControl>
16401640
</View>
1641+
<View>
1642+
<Name>Git.Reference.Log</Name>
1643+
<ViewSelectedBy>
1644+
<TypeName>Git.Reference.Log</TypeName>
1645+
</ViewSelectedBy>
1646+
<TableControl>
1647+
<TableHeaders>
1648+
<TableColumnHeader>
1649+
<Label>Name</Label>
1650+
<Alignment>Right</Alignment>
1651+
</TableColumnHeader>
1652+
<TableColumnHeader>
1653+
<Label>#</Label>
1654+
<Alignment>Left</Alignment>
1655+
</TableColumnHeader>
1656+
<TableColumnHeader>
1657+
<Alignment>Left</Alignment>
1658+
</TableColumnHeader>
1659+
<TableColumnHeader>
1660+
<Label>Command</Label>
1661+
<Alignment>Right</Alignment>
1662+
</TableColumnHeader>
1663+
<TableColumnHeader>
1664+
<Alignment>Left</Alignment>
1665+
</TableColumnHeader>
1666+
</TableHeaders>
1667+
<TableRowEntries>
1668+
<TableRowEntry>
1669+
<TableColumnItems>
1670+
<TableColumnItem>
1671+
<ScriptBlock> $_.Name </ScriptBlock>
1672+
</TableColumnItem>
1673+
<TableColumnItem>
1674+
<ScriptBlock> $_.'Number' + ' '</ScriptBlock>
1675+
</TableColumnItem>
1676+
<TableColumnItem>
1677+
<PropertyName>Hash</PropertyName>
1678+
</TableColumnItem>
1679+
<TableColumnItem>
1680+
<ScriptBlock> $_.Command + ':'</ScriptBlock>
1681+
</TableColumnItem>
1682+
<TableColumnItem>
1683+
<PropertyName>Message</PropertyName>
1684+
</TableColumnItem>
1685+
</TableColumnItems>
1686+
</TableRowEntry>
1687+
</TableRowEntries>
1688+
</TableControl>
1689+
</View>
16411690
<View>
16421691
<Name>Git.Status</Name>
16431692
<ViewSelectedBy>

ugit.psd1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '0.1.9.1'
2+
ModuleVersion = '0.2.0'
33
RootModule = 'ugit.psm1'
44
FormatsToProcess = 'ugit.format.ps1xml'
55
TypesToProcess = 'ugit.types.ps1xml'
@@ -16,6 +16,10 @@ PrivateData = @{
1616
ProjectURI = 'https://github.com/StartAutomating/ugit'
1717
LicenseURI = 'https://github.com/StartAutomating/ugit/blob/main/LICENSE'
1818
ReleaseNotes = @'
19+
## 0.2.0:
20+
* Adding support for git reflog (#51)
21+
---
22+
1923
## 0.1.9.1:
2024
* Fixing git status duplicate message (#49)
2125
---

0 commit comments

Comments
 (0)