30 lines
888 B
PowerShell
30 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
|
|
}
|