2021-04-04 18:42:29 +00:00
|
|
|
[CmdletBinding(SupportsShouldProcess)]param(
|
|
|
|
[Parameter(Mandatory)]
|
|
|
|
[string]$LocalPath,
|
|
|
|
[Parameter(Mandatory)]
|
|
|
|
[string]$GitOrigin,
|
2021-09-10 05:20:12 +00:00
|
|
|
[string]$Branch='HEAD',
|
|
|
|
[switch]$sudo
|
2021-04-04 18:42:29 +00:00
|
|
|
)
|
|
|
|
$local:gitPath = Join-Path 'themes' 'plextheme' | Get-Path
|
2021-09-10 05:20:12 +00:00
|
|
|
function doGit { & $(if($sudo){"sudo"}) git "--git-dir=`"$(Join-Path $LocalPath '.git')`"" "--work-tree=`"$LocalPath`"" $args }
|
2021-04-04 18:42:29 +00:00
|
|
|
$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
|
|
|
|
}
|