Skip to content

Commit 7e7832c

Browse files
Merge pull request #37 from StartAutomating/gittingRidOfErrors
GittingRidOfErrors
2 parents 68b386c + bc9e7a9 commit 7e7832c

File tree

7 files changed

+250
-125
lines changed

7 files changed

+250
-125
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
## 0.1.7:
2+
* Use-Git: -Verbose no longer infers --verbose (#10)
3+
* Out-Git: Support for extension caching (#35)
4+
* Out-Git: Using -ErrorAction Ignore when -Verbose is not passed (#36)
5+
* Get-UGitExtension: Updating Piecemeal Version [0.2.1]. (Re #32 #36)
6+
---
7+
18
## 0.1.6
29
* Adding support / formatting for git pull (#26)
310
* Out-Git: Extension Improvements (#33)
411
---
512

6-
713
## 0.1.5
814
* Adding git.log .Checkout() and Revert() (#27, #28)
915
* Fixing formatting for git diff (#25)

Extensions/Git.Pull.UGit.Extension.ps1

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,19 @@
22
.SYNOPSIS
33
git pull extension
44
.DESCRIPTION
5-
5+
Returns git pull as objects.
66
.EXAMPLE
77
git pull
88
#>
99
[Management.Automation.Cmdlet("Out", "Git")]
10-
[ValidatePattern("^git (?>pull|fetch)")]
10+
[ValidatePattern("^git pull")]
1111
[OutputType('git.pull.fastforward', 'git.pull.nochange')]
1212
param(
1313
[Parameter(ValueFromPipeline)]
1414
[string]
1515
$GitOut
1616
)
1717

18-
<#
19-
From https://github.com/StartAutomating/RoughDraft
20-
432138e..9df4f8d main -> origin/main
21-
* [new tag] v0.3.1 -> v0.3.1
22-
Updating 432138e..9df4f8d
23-
Fast-forward
24-
CHANGELOG.md | 13 ++-
25-
Convert-Media.ps1 | 37 +++++++--
26-
Edit-Media.ps1 | 95 ++++++++++++++-------
27-
Extension/DrawSubtitle.RoughDraft.Extension.ps1 | 78 ++++++++++++++++++
28-
Extension/Resize.RoughDraft.Extension.ps1 | 11 ++-
29-
Extension/Subtitler.RoughDraft.Extension.ps1 | 105 ++++++++++++++++++++++++
30-
RoughDraft.psd1 | 13 ++-
31-
Show-Media.ps1 | 2 +-
32-
8 files changed, 309 insertions(+), 45 deletions(-)
33-
create mode 100644 Extension/DrawSubtitle.RoughDraft.Extension.ps1
34-
create mode 100644 Extension/Subtitler.RoughDraft.Extension.ps1
35-
#>
36-
3718
begin {
3819
$pullLines = @()
3920
}

Get-UGitExtension.ps1

Lines changed: 192 additions & 81 deletions
Large diffs are not rendered by default.

Out-Git.ps1

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,48 @@
5454
# First, we need to determine what the combined git command was.
5555
# Luckily, this is easy: just combine "git" with the list of git argument
5656
$gitCommand = @('git') + $GitArgument[0..$GitArgument.Length] -join ' '
57-
# Now that we have that, let's initialize an empty variable to keep any extension validation errors.
58-
$extensionValidationErrors = $null
59-
# Then we create a hashtable containing the parameters to Get-UGitExtension:
60-
$uGitExtensionParams = @{
61-
CommandName = $MyInvocation.MyCommand # We want extensions for this command
62-
ValidateInput = $gitCommand # that are valid, given $GitCommand.
63-
ErrorAction = 'SilentlyContinue' # We do not want to display errors
64-
ErrorVariable = 'extensionValidationErrors' # we want to redirect them into $extensionValidationErrros.
57+
58+
# Now we need to see if we have have a cached for extension mapping.
59+
if (-not $script:GitExtensionMappingCache) {
60+
$script:GitExtensionMappingCache = @{} # If we don't, create one.
6561
}
66-
# Now we get a list of git output extensions
67-
$gitOutputExtensions = @(Get-UGitExtension @uGitExtensionParams)
68-
# If any of them had errors, and we want to see the -Verbose channel
69-
if ($extensionValidationErrors -and $VerbosePreference -ne 'silentlyContinue') {
70-
foreach ($validationError in $extensionValidationErrors) {
71-
Write-Verbose "$validationError" # write the validation errors to verbose.
72-
# It should be noted that there will almost always be validation errors,
73-
# since most extensions will not apply to a given $GitCommand
62+
63+
if (-not $script:GitExtensionMappingCache[$gitCommand]) { # If we don't have a cached extension list
64+
65+
# let's initialize an empty variable to keep any extension validation errors.
66+
$extensionValidationErrors = $null
67+
# Then we create a hashtable containing the parameters to Get-UGitExtension:
68+
$uGitExtensionParams = @{
69+
CommandName = $MyInvocation.MyCommand # We want extensions for this command
70+
ValidateInput = $gitCommand # that are valid, given $GitCommand.
71+
7472
}
75-
}
73+
74+
# If -Verbose is -Debug is set, we will want to populate extensionValidationErrors
75+
if ($VerbosePreference -ne 'silentlyContinue' -or
76+
$DebugPreference -ne 'silentlyContinue') {
77+
$uGitExtensionParams.ErrorAction = 'SilentlyContinue' # We do not want to display errors
78+
$uGitExtensionParams.ErrorVariable = 'extensionValidationErrors' # we want to redirect them into $extensionValidationErrors.
79+
$uGitExtensionParams.AllValid = $true # and we want to see that all of the validation attributes are correct.
80+
} else {
81+
$uGitExtensionParams.ErrorAction = 'Ignore'
82+
}
83+
84+
# Now we get a list of git output extensions and store it in the cache.
85+
$script:GitExtensionMappingCache[$gitCommand] = $gitOutputExtensions = @(Get-UGitExtension @uGitExtensionParams)
86+
87+
# If any of them had errors, and we want to see the -Verbose channel
88+
if ($extensionValidationErrors -and $VerbosePreference -ne 'silentlyContinue') {
89+
foreach ($validationError in $extensionValidationErrors) {
90+
Write-Verbose "$validationError" # write the validation errors to verbose.
91+
# It should be noted that there will almost always be validation errors,
92+
# since most extensions will not apply to a given $GitCommand
93+
}
94+
}
95+
} else {
96+
# If there was already an extension cached, we can skip the previous steps and just reuse the cached extensions.
97+
$gitOutputExtensions = $script:GitExtensionMappingCache[$gitCommand]
98+
}
7699

77100
# Next we want to create a collection of SteppablePipelines.
78101
# These allow us to run the begin/process/end blocks of each Extension.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Get-UGitExtension is built using [Piecemeal](https://github.com/StartAutomating/
6767
* git diff
6868
* git log
6969
* git push
70+
* git pull
7071
* git status
7172

7273

Use-Git.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@
8787
$argumentNumber++
8888
}
8989

90-
if ($VerbosePreference -ne 'silentlyContinue' -and -not ($GitArgument -eq '-v'))
91-
{
92-
$GitArgument += '--verbose' # they probably want --verbose (and enough git commands support it to try).
93-
}
9490
$progId = Get-Random
9591
$dirCount = 0
9692
$RepoNotRequired = 'clone','init' # A small number of git operations do not require a repo. List them here.

ugit.psd1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '0.1.6'
2+
ModuleVersion = '0.1.7'
33
RootModule = 'ugit.psm1'
44
FormatsToProcess = 'ugit.format.ps1xml'
55
TypesToProcess = 'ugit.types.ps1xml'
@@ -16,6 +16,13 @@ PrivateData = @{
1616
ProjectURI = 'https://github.com/StartAutomating/ugit'
1717
LicenseURI = 'https://github.com/StartAutomating/ugit/blob/main/LICENSE'
1818
ReleaseNotes = @'
19+
## 0.1.7:
20+
* Use-Git: -Verbose no longer infers --verbose (#10)
21+
* Out-Git: Support for extension caching (#35)
22+
* Out-Git: Using -ErrorAction Ignore when -Verbose is not passed (#36)
23+
* Get-UGitExtension: Updating Piecemeal Version [0.2.1]. (Re #32 #36)
24+
---
25+
1926
## 0.1.6
2027
* Adding support / formatting for git pull (#26)
2128
* Out-Git: Extension Improvements (#33)

0 commit comments

Comments
 (0)