git related improvements and implementations

+ Get-GitRepo - Clone or update a repo, with tag support
+ Get-GitHubReleaseTag - Grab tag from latest release page
+ Refresh-GitRepo - Stage all possible changes, discarding any
previously stageds changes
= GitHub repo is now git repo - as some code isn't GitHub specific
+ cat Alias for Get-Content
= Get-PossiblArguments improvement
= Invoke-WebDownload fix
= dcedit fixing bad argument processing
This commit is contained in:
lksz 2021-04-04 14:42:29 -04:00
parent aa44d120e4
commit 8a93a0f123
11 changed files with 85 additions and 11 deletions

2
git/Edit-GitIgnore.ps1 Normal file
View file

@ -0,0 +1,2 @@
$local:workTree = git worktree list --porcelain | Select-String worktree | ForEach-Object { $_ -split 'worktree ' } | Where-Object { $_ }
Edit-TextFile $(Join-Path $workTree .gitignore)

View file

@ -0,0 +1,18 @@
[CmdletBinding()]param(
[Parameter(Mandatory)]
[string]$GitHubProject,
[string]$tag='latest',
[Alias("Match")]
[string]$MatchPattern
)
filter Out-Matched { $_ | Where-Object { $_ -match $MatchPattern } }
Set-Alias FinalOutput Out-Default
if( $MatchPattern ) { Set-Alias FinalOutput Out-Matched }
Invoke-WebRequest https://github.com/$GitHubProject/releases/$tag -ErrorAction Stop |
Select-Object -ExpandProperty Links |
Where-Object href -match 'download/.*' |
Select-Object -ExpandProperty href |
ForEach-Object { "https://github.com$_" } |
FinalOutput

View file

@ -0,0 +1,11 @@
[CmdletBinding()]param(
[Parameter(Mandatory)]
[string]$GitHubProject,
[string]$tag='latest'
)
Invoke-WebRequest https://github.com/$GitHubProject/releases/$tag -ErrorAction Stop |
Select-Object -ExpandProperty Links |
Where-Object title |
Where-Object href -match 'tree/[^/]+$' |
Select-Object -ExpandProperty title -First 1

29
git/Get-GitRepo.ps1 Normal file
View file

@ -0,0 +1,29 @@
[CmdletBinding(SupportsShouldProcess)]param(
[Parameter(Mandatory)]
[string]$LocalPath,
[Parameter(Mandatory)]
[string]$GitOrigin,
[string]$Branch='HEAD'
)
$local:gitPath = Join-Path 'themes' 'plextheme' | Get-Path
function doGit { git "--git-dir=`"$(Join-Path $LocalPath '.git')`"" "--work-tree=`"$LocalPath`"" $args }
$local:savedErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'Stop'
$local:exists = Test-Path $LocalPath
try {
if( $exists ) {
# Update code from git repo
Write-Verbose "Pulling from [$GitOrigin] into [$LocalPath] on branch/tag '$Branch'..."
doGit fetch --quiet
} else {
git clone $GitOrigin $LocalPath
}
doGit checkout $Branch --quiet
if( $exists ) {
doGit status
}
} catch {
throw $_
} finally {
$ErrorActionPreference = $savedErrorActionPreference
}

7
git/Refresh-GitRepo.ps1 Normal file
View file

@ -0,0 +1,7 @@
$local:workTree = git worktree list --porcelain | Select-String worktree | ForEach-Object { $_ -split 'worktree ' } | Where-Object { $_ }
Push-Location $workTree
$null = git reset HEAD
$null = git rm --cached -r .
$null = git add .
git status
Pop-Location

14
git/_.package.json Normal file
View file

@ -0,0 +1,14 @@
{
"package": {
"Condition": [
{
"custom": "Get-Command git -Type Application",
"System": null,
"Hostname": null,
"Username": null,
"Logic": 0
}
],
"Name": "git"
}
}