PowerShell_Scripts/git/Get-GitRepo.ps1
lksz 8a93a0f123 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
2021-04-04 14:42:29 -04:00

29 lines
888 B
PowerShell

[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
}