Skip to content

Commit

Permalink
Merge pull request #188 from StartAutomating/ugit-an-update
Browse files Browse the repository at this point in the history
ugit 0.4.1
  • Loading branch information
StartAutomating authored Oct 5, 2023
2 parents 525290d + d81f224 commit 80a4d9c
Show file tree
Hide file tree
Showing 55 changed files with 777 additions and 389 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/SendPSA.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

name: ugit-psa
on:
workflow_dispatch:
jobs:
SendPSA:
runs-on: ubuntu-latest
if: ${{ success() }}
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: PSA
uses: StartAutomating/PSA@main
id: PSA
env:
AT_PROTOCOL_HANDLE: mrpowershell.bsky.social
AT_PROTOCOL_APP_PASSWORD: ${{ secrets.AT_PROTOCOL_APP_PASSWORD }}
7 changes: 6 additions & 1 deletion .github/workflows/TestAndPublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -591,4 +591,9 @@ jobs:
- name: Run HelpOut
uses: StartAutomating/HelpOut@master
id: HelpOut

- name: PSA
uses: StartAutomating/PSA@main
id: PSA
env:
AT_PROTOCOL_HANDLE: mrpowershell.bsky.social
AT_PROTOCOL_APP_PASSWORD: ${{ secrets.AT_PROTOCOL_APP_PASSWORD }}
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 0.4.1:

* New Git Command Support:
* git submodule status (#183)
* New Git ScriptMethods:
* git.branch.diff (#187)
* git.branch.rename (#86)
* Easier Input:
* git commit -CommitDate (#184)
* git log -CurrentBranch (fixing forks, #179)
* Announcing Releases with [PSA](https://github.com/StartAutomating/PSA)

---

## 0.4:

* Adding Sponsorship! (#174)
Expand Down
13 changes: 12 additions & 1 deletion Extensions/Git.Commit.Input.UGit.Extension.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ $Trailers,

# If set, will amend an existing commit.
[switch]
$Amend
$Amend,

# The commit date.
[Parameter(ValueFromPipelineByPropertyName)]
[Alias('Date','Time','DateTime','Timestamp')]
[datetime]
$CommitDate
)


Expand Down Expand Up @@ -63,4 +69,9 @@ if ($Trailers) {

if ($amend) {
"--amend"
}

if ($CommitDate) {
"--date"
$CommitDate.ToString("o")
}
2 changes: 1 addition & 1 deletion Extensions/Git.Log.Input.UGit.Extension.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ foreach ($dashToDoubleDash in 'after', 'before', 'author') {
}

if ($CurrentBranch) {
$headbranch = git remote | git remote show | Select-Object -ExpandProperty HeadBranch
$headbranch = git remote | git remote show | Select-Object -ExpandProperty HeadBranch -First 1
$currentBranchName = git branch | Where-Object IsCurrentBranch
if ($currentBranchName -ne $headbranch) {
"$headbranch..$currentBranchName"
Expand Down
37 changes: 37 additions & 0 deletions Extensions/Git.SubModule.Status.ugit.extension.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<#
.Synopsis
Git Submodule Extension
.Description
Git Submodule as objects.
.EXAMPLE
git submodule
#>
[Management.Automation.Cmdlet("Out","Git")] # It's an extension for Out-Git
[ValidatePattern("^(?:git)\s(?:submodule)\s(?:status)?$")] # that is run when git submodule is run (with no other options (except for status)).
param()

begin {
$submoduleLines = @()
}

process {
$submoduleLines += $gitOut
}

end {
if ($gitArgument -match '--(?>n|dry-run)') {
return $submoduleLines
}

foreach ($line in $submoduleLines) {
if ($line -match '^\s{0,}[\+]?(?<CommitHash>[0-9a-f]{10,})\s(?<SubModule>\S+)\s\((?<Reference>[^\)]+)\)') {
$Matches.Remove(0)
$toObject = [Ordered]@{
PSTypeName = 'git.submodule.status'
GitOutputLines = $submoduleLines
GitRoot = $gitRoot
} + $Matches
[PSCustomObject]$toObject
}
}
}
1 change: 1 addition & 0 deletions Formatting/Git.Submodule.format.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-FormatView -TypeName git.submodule.status -Property Submodule, Reference, CommitHash
82 changes: 74 additions & 8 deletions Get-UGitExtension.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Piecemeal [ 0.3.10 ] : Easy Extensible Plugins for PowerShell
#region Piecemeal [ 0.4.1 ] : Easy Extensible Plugins for PowerShell
# Install-Module Piecemeal -Scope CurrentUser
# Import-Module Piecemeal -Force
# Install-Piecemeal -ExtensionModule 'ugit' -ExtensionModuleAlias 'git' -ExtensionNoun 'UGitExtension' -ExtensionTypeName 'ugit.extension' -OutputPath '.\Get-UGitExtension.ps1'
Expand Down Expand Up @@ -614,6 +614,8 @@ function Get-UGitExtension

$ExtensionDynamicParameters = [Management.Automation.RuntimeDefinedParameterDictionary]::new()
$Extension = $this
$ExtensionMetadata = $Extension -as [Management.Automation.CommandMetaData]
if (-not $ExtensionMetadata) { return $ExtensionDynamicParameters }

:nextDynamicParameter foreach ($in in @(($Extension -as [Management.Automation.CommandMetaData]).Parameters.Keys)) {
$attrList = [Collections.Generic.List[Attribute]]::new()
Expand Down Expand Up @@ -1042,12 +1044,16 @@ function Get-UGitExtension

if ($Force) {
$script:UGitExtensions = $null
$script:UGitExtensionsByName = $null
$script:AllCommands = @()
}
if (-not $script:UGitExtensions)
{
$script:UGitExtensionsFromFiles = [Ordered]@{}
$script:UGitExtensionsFileTimes = [Ordered]@{}
$script:UGitExtensionsFromFiles = [Ordered]@{}
$script:UGitExtensionsFileTimes = [Ordered]@{}
$script:UGitExtensionsByName = [Ordered]@{}
$script:UGitExtensionsByDisplayName = [Ordered]@{}
$script:UGitExtensionsByPattern = [Ordered]@{}
$script:UGitExtensions =
@(@(
#region Find UGitExtension in Loaded Modules
Expand Down Expand Up @@ -1093,14 +1099,54 @@ function Get-UGitExtension
$ExecutionContext.SessionState.InvokeCommand.GetCommands('*', 'Function,Alias',$true) -match $extensionFullRegex
#endregion Find UGitExtension in Loaded Commands
) | Select-Object -Unique | Sort-Object Rank, Name)

foreach ($extCmd in $script:UGitExtensions) {
if (-not $script:UGitExtensionsByName[$extCmd.Name]) {
$script:UGitExtensionsByName[$extCmd.Name] = $extCmd
}
else {
$script:UGitExtensionsByName[$extCmd.Name] = @($script:UGitExtensionsByName[$extCmd.Name]) + $extCmd
}
if ($extCmd.DisplayName) {
if (-not $script:UGitExtensionsByDisplayName[$extCmd.DisplayName]) {
$script:UGitExtensionsByDisplayName[$extCmd.DisplayName] = $extCmd
}
else {
$script:UGitExtensionsByDisplayName[$extCmd.DisplayName] = @($script:UGitExtensionsByDisplayName[$extCmd.DisplayName]) + $extCmd
}
}
$ExtensionCommandAliases = @($extCmd.Attributes.AliasNames)
$ExtensionCommandAliasRegexes = @($ExtensionCommandAliases -match '^/' -match '/$')
$ExtensionCommandNormalAliases = @($ExtensionCommandAliases -notmatch '^/')
if ($ExtensionCommandAliasRegexes) {
foreach ($extensionAliasRegex in $ExtensionCommandAliasRegexes) {
$regex = [Regex]::New($extensionAliasRegex -replace '^/' -replace '/$', 'IgnoreCase,IgnorePatternWhitespace')
if (-not $script:UGitExtensionsByPattern[$regex]) {
$script:UGitExtensionsByPattern[$regex] = $extCmd
} else {
$script:UGitExtensionsByPattern[$regex] = @($script:UGitExtensionsByPattern[$regex]) + $extCmd
}
}
}
if ($ExtensionCommandNormalAliases) {
foreach ($extensionAlias in $ExtensionCommandNormalAliases) {
if (-not $script:UGitExtensionsByName[$extensionAlias]) {
$script:UGitExtensionsByName[$extensionAlias] = $extCmd
} else {
$script:UGitExtensionsByName[$extensionAlias] = @($script:UGitExtensionsByName[$extensionAlias]) + $extCmd
}
}
}

}
}
#endregion Find Extensions
}

process {

if ($UGitExtensionPath) {
@(foreach ($_ in Get-ChildItem -Recurse -Path $UGitExtensionPath -File) {
@(foreach ($_ in Get-ChildItem -Recurse:$($UGitExtensionPath -notmatch '^\.[\\/]') -Path $UGitExtensionPath -File) {
if ($_.Name -notmatch $extensionFullRegex) { continue }
if ($CommandName -or $UGitExtensionName) {
ConvertToExtension $_ |
Expand All @@ -1118,14 +1164,34 @@ function Get-UGitExtension
# This section can be updated by using Install-Piecemeal -ForeachObject
#endregion Install-Piecemeal -ForeachObject
} elseif ($CommandName -or $UGitExtensionName) {
$script:UGitExtensions |
. WhereExtends $CommandName |
OutputExtension
if (-not $CommandName -and -not $like -and -not $Match) {
foreach ($exn in $UGitExtensionName) {
if ($script:UGitExtensionsByName[$exn]) {
$script:UGitExtensionsByName[$exn] | OutputExtension
}
if ($script:UGitExtensionsByDisplayName[$exn]) {
$script:UGitExtensionsByDisplayName[$exn] | OutputExtension
}
if ($script:UGitExtensionsByPattern.Count) {
foreach ($patternAndValue in $script:UGitExtensionsByPattern.GetEnumerator()) {
if ($patternAndValue.Key.IsMatch($exn)) {
$patternAndValue.Value | OutputExtension
}
}
$script:UGitExtensionsByDisplayName[$exn]
}
}
} else {
$script:UGitExtensions |
. WhereExtends $CommandName |
OutputExtension
}

} else {
$script:UGitExtensions |
OutputExtension
}
}
}
#endregion Piecemeal [ 0.3.10 ] : Easy Extensible Plugins for PowerShell
#endregion Piecemeal [ 0.4.1 ] : Easy Extensible Plugins for PowerShell

15 changes: 15 additions & 0 deletions GitHub/Jobs/SendPSA.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@{
"runs-on" = "ubuntu-latest"
if = '${{ success() }}'
steps = @(
@{
name = 'Check out repository'
uses = 'actions/checkout@v2'
},
@{
name = 'PSA'
uses = 'StartAutomating/PSA@main'
id = 'PSA'
}
)
}
18 changes: 16 additions & 2 deletions GitHub/Jobs/buildugit.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,28 @@
name = 'Check out repository'
uses = 'actions/checkout@v2'
},
@{
name = 'GitLogger'
uses = 'GitLogging/GitLoggerAction@main'
id = 'GitLogger'
},
@{
name = 'Use PSSVG Action'
uses = 'StartAutomating/PSSVG@main'
id = 'PSSVG'
},
'RunPipeScript',
'RunPiecemeal',
'RunEZOut',
'RunHelpOut'
'RunEZOut',
@{
name = 'Run HelpOut'
uses = 'StartAutomating/HelpOut@master'
id = 'HelpOut'
},
@{
name = 'PSA'
uses = 'StartAutomating/PSA@main'
id = 'PSA'
}
)
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,13 @@ You might want to try giving some of these a try.
git status | Select-Object -ExpandProperty Untracked
~~~

### Git.SubModule.Status Example 1


~~~PowerShell
git submodule
~~~

## Out-Git Extensions

### Git Commands
Expand Down Expand Up @@ -441,6 +448,9 @@ Most extensions handle output from a single git command.

* [Git Status](docs/Git.Status-Extension.md)


* [Git SubModule Status](docs/Git.SubModule.Status-Extension.md)



### Additional Output Extensions
Expand Down
1 change: 1 addition & 0 deletions Types/git.branch/Alias.psd1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@{
HasUpstream = 'IsTracked'
Compare = 'Diff'
}
15 changes: 15 additions & 0 deletions Types/git.branch/Diff.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
param()

$firstArg, $restOfArgs =
if (-not $args) {
git remote | git remote show | Select-Object -ExpandProperty HeadBranch -First 1
} else {
$args | Select-Object -First 1
$args | Select-Object -Skip 1
}

$restOfArgs = @($restOfArgs)

Push-Location $this.GitRoot
git diff "$($firstArg)..$($this.BranchName)" @restOfArgs
Pop-Location
6 changes: 6 additions & 0 deletions Types/git.branch/Rename.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if (-not $args) {
throw "Must provide a new branch name"
}
Push-Location $this.GitRoot
git branch '-m' $this.BranchName @args
Pop-Location
1 change: 1 addition & 0 deletions assets/ugit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 0.4.1:

* New Git Command Support:
* git submodule status (#183)
* New Git ScriptMethods:
* git.branch.diff (#187)
* git.branch.rename (#86)
* Easier Input:
* git commit -CommitDate (#184)
* git log -CurrentBranch (fixing forks, #179)
* Announcing Releases with [PSA](https://github.com/StartAutomating/PSA)

---

## 0.4:

* Adding Sponsorship! (#174)
Expand Down
4 changes: 2 additions & 2 deletions docs/Get-UGitExtension.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ UGitExtension can be found in:


### Examples
#### EXAMPLE 1
> EXAMPLE 1
```PowerShell
Get-UGitExtension
```



---


Expand Down
Loading

0 comments on commit 80a4d9c

Please sign in to comment.