Skip to content

Commit 974d192

Browse files
Merge pull request #89 from StartAutomating/ugit-improvements
Ugit improvements
2 parents f34ba0e + 82e20c8 commit 974d192

18 files changed

+240
-40
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## 0.3.1:
2+
3+
* git help --all now returns as objects (Fixes #88)
4+
* (git log .\filename).Diff() now only diffs the selected files (Fixes #87)
5+
* git -C is permitted in any direectory (Fixes #85)
6+
7+
---
8+
9+
## 0.3:
10+
11+
* Adding git version and git help to list of commands that do not require a repo (Fixes #79) (Thanks @charltonstanley!)
12+
13+
--
14+
115
## 0.2.9:
216
* Adding support for git init (Fixes #75)
317

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<#
2+
.Synopsis
3+
git help all
4+
.Description
5+
Returns git help --all as objects.
6+
.Example
7+
git help -a
8+
.EXAMPLE
9+
git help --all
10+
#>
11+
[Management.Automation.Cmdlet("Out","Git")]
12+
[ValidatePattern('^git help -(?>a|-all)')]
13+
[OutputType('git.command')]
14+
param()
15+
16+
begin {
17+
$category = ''
18+
}
19+
20+
process {
21+
if ($gitOut -match '^\S' -and $gitOut -notmatch '^See') {
22+
$category = "$gitOut"
23+
return
24+
}
25+
26+
if ($gitOut -match '^See') { return }
27+
if ($gitOut -match '^\s{0,}$') { return }
28+
$null, $name, $description = "$gitOut" -split "\s+", 3
29+
30+
[PSCustomObject][Ordered]@{
31+
PSTypeName = 'git.command'
32+
Name = $name
33+
Description = $description
34+
Category = $category
35+
}
36+
}
37+
38+
end {
39+
40+
}

Extensions/Git.Log.UGit.Extension.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ begin {
7272
$gitLogMatch = $Git_Log.Match($OutputLines -join [Environment]::NewLine)
7373
if (-not $gitLogMatch.Success) { return }
7474

75-
$gitLogOut = [Ordered]@{PSTypeName='git.log'}
75+
$gitLogOut = [Ordered]@{PSTypeName='git.log';GitArgument=$gitArgument}
7676
if ($gitCommand -like '*--merges*') {
7777
$gitLogOut.PSTypeName = 'git.merge.log'
7878
}

Formatting/Git.Command.format.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write-FormatView -TypeName git.command -GroupByProperty Category -Property Name, Description -AutoSize

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ Get-UGitExtension is built using [Piecemeal](https://github.com/StartAutomating/
8080
* [Git Diff](docs/Git.Diff-Extension.md)
8181

8282

83+
* [Git Help All](docs/Git.Help.All-Extension.md)
84+
85+
8386
* [Git Init](docs/Git.Init-Extension.md)
8487

8588

@@ -189,6 +192,20 @@ It will attempt to locate any output specified by -o and return it as a file or
189192
git archive -o My.zip
190193
~~~
191194

195+
### Git.Help.All Example 1
196+
197+
198+
~~~PowerShell
199+
git help -a
200+
~~~
201+
202+
### Git.Help.All Example 2
203+
204+
205+
~~~PowerShell
206+
git help --all
207+
~~~
208+
192209
### Git.Init Example 1
193210

194211

Types/git.log/Diff.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
Push-Location $this.GitRoot
2-
git diff $this.CommitHash @args
2+
$logPaths = @($this.GitArgument -ne 'log' -notmatch '^\-')
3+
foreach ($logPath in $logPaths) {
4+
if (Test-Path $logPath) {
5+
$relativeArgs = @("--relative", $logPath)
6+
git diff $this.CommitHash @relativeArgs @args
7+
}
8+
}
9+
if (-not $logPaths) {
10+
git diff $this.CommitHash @args
11+
}
312
Pop-Location

Use-Git.ps1

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,32 @@
7777
}
7878

7979
$argumentNumber = 0
80+
81+
$gitArgsArray = [Collections.ArrayList]::new($GitArgument)
82+
8083
foreach ($commandElement in $callingContext.CommandElements) {
81-
if ($commandElement.parameterName -in 'd', 'v') {
82-
# If they passed -d/-D or -v/-V, they probably don't mean -Debug/-Verbose
83-
$beforeArgs = @(if ($argumentNumber) { $GitArgument[0..$argumentNumber]})
84-
$afterArgs = @(if ($argumentNumber + 1 -le $gitArgument.Length) {
85-
$GitArgument[($argumentNumber + 1)..($GitArgument.Length - 1)]
86-
})
87-
$GitArgument = @($beforeArgs) + @("$($commandElement.Extent)") + @($afterArgs)
88-
if ($commandElement.parameterName -eq 'd') { # Also, if they passed -d/-D, they probably don't want to be confirmed
84+
if ($commandElement.parameterName -in 'd', 'v', 'c') {
85+
# Insert the argument into the list
86+
$gitArgsArray.Insert(
87+
$argumentNumber - 1, # ( don't forget to subtract one, because the command is an element)
88+
$commandElement.Extent.ToString()
89+
)
90+
if ($commandElement.parameterName -in 'd', 'c') {
8991
$ConfirmPreference ='none' # so set confirm impact to none
90-
}
92+
}
9193
}
9294
$argumentNumber++
9395
}
9496

97+
$GitArgument = $gitArgsArray.ToArray()
98+
9599
$progId = Get-Random
96100
$dirCount = 0
97-
$RepoNotRequired = 'clone','init','version','help' # A small number of git operations do not require a repo. List them here.
101+
# A small number of git operations do not require a repo. List them here.
102+
$RepoNotRequired = 'clone','init','version','help','-C'
98103
}
99-
process {
104+
105+
process {
100106
# First, we need to take any input and figure out what directories we are going into.
101107
$directories = @()
102108
$inputObject =
@@ -122,17 +128,25 @@
122128

123129
# Before we process each directory, make a copy of the bound parameters.
124130
$paramCopy = ([Ordered]@{} + $PSBoundParameters)
125-
131+
if ($GitArgument -contains '-c' -or $GitArgument -contains '-C') {
132+
$paramCopy.Remove('Confirm')
133+
}
126134

127135
# Now, we will force there to be at least one directory (the current path).
128136
# This makes the code simpler, because we are always going thru a loop.
129-
if (-not $directories) {
130-
$directories = @($pwd)
137+
if (-not $directories) {
138+
if ($GitArgument -ccontains '-C') {
139+
$directories = $gitArgument[$GitArgument.IndexOf('-C') + 1]
140+
} else {
141+
$directories = @($pwd)
142+
}
131143
} else {
132144
# It also gives us a change to normalize the directories into their full paths.
133145
$directories = @(foreach ($dir in $directories) { $dir.Fullname })
134146
}
135147

148+
149+
136150

137151
# For each directory we know of, we
138152
foreach ($dir in $directories) {
@@ -163,7 +177,8 @@
163177
Write-Progress -PercentComplete (($dirCount * 5) % 100) -Status "git $allGitArgs " -Activity "$($dir) " -Id $progId
164178
}
165179

166-
if (($ConfirmPreference -eq 'None' -and -not $paramCopy.Confirm) -or # If we have indicated we do not care about -Confirmation, don't prompt
180+
# If we have indicated we do not care about -Confirmation, don't prompt
181+
if (($ConfirmPreference -eq 'None' -and (-not $paramCopy.Confirm)) -or
167182
$PSCmdlet.ShouldProcess("$pwd : git $allGitArgs") # otherwise, as for confirmation to run.
168183
) {
169184
$eventSourceIds = @("Use-Git","Use-Git $allGitArgs")

docs/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## 0.3.1:
2+
3+
* git help --all now returns as objects (Fixes #88)
4+
* (git log .\filename).Diff() now only diffs the selected files (Fixes #87)
5+
* git -C is permitted in any direectory (Fixes #85)
6+
7+
---
8+
9+
## 0.3:
10+
11+
* Adding git version and git help to list of commands that do not require a repo (Fixes #79) (Thanks @charltonstanley!)
12+
13+
--
14+
115
## 0.2.9:
216
* Adding support for git init (Fixes #75)
317

docs/Get-UGitExtension.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
Get-UGitExtension
32
-----------------
43
### Synopsis
@@ -409,5 +408,3 @@ If set, will output the help for the extensions
409408
Get-UGitExtension [[-UGitExtensionPath] <String>] [-Force] [[-CommandName] <String[]>] [[-UGitExtensionName] <String[]>] [-Like] [-Match] [-DynamicParameter] [-CouldRun] [[-CouldPipe] <PSObject>] [-Run] [-Stream] [[-DynamicParameterSetName] <String>] [[-DynamicParameterPositionOffset] <Int32>] [-NoMandatoryDynamicParameter] [-RequireUGitExtensionAttribute] [[-ValidateInput] <PSObject>] [-AllValid] [[-ParameterSetName] <String>] [[-Parameter] <IDictionary>] [-SteppablePipeline] [-Help] [<CommonParameters>]
410409
```
411410
---
412-
413-

docs/Git.Help.All-Extension.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
Extensions/Git.Help.All.UGit.Extension.ps1
3+
------------------------------------------
4+
### Synopsis
5+
git help all
6+
7+
---
8+
### Description
9+
10+
Returns git help --all as objects.
11+
12+
---
13+
### Examples
14+
#### EXAMPLE 1
15+
```PowerShell
16+
git help -a
17+
```
18+
19+
#### EXAMPLE 2
20+
```PowerShell
21+
git help --all
22+
```
23+
24+
---
25+
### Outputs
26+
* git.command
27+
28+
29+
30+
31+
---
32+
### Syntax
33+
```PowerShell
34+
Extensions/Git.Help.All.UGit.Extension.ps1 [<CommonParameters>]
35+
```
36+
---
37+
38+
39+
40+

0 commit comments

Comments
 (0)