Setup-Profile will update git scripts from git repo

This commit is contained in:
lksz 2020-10-03 16:32:55 -04:00
父節點 f4abdf1a2d
當前提交 306e03874d
共有 1 個文件被更改,包括 11 次插入8 次删除

查看文件

@ -3,7 +3,7 @@
[switch]$RemoveOnly,
[switch]$ShowSkipped,
[switch]$Force,
[switch]$NoGitClone,
[switch]$NoGitAction,
[string]$GitURL = 'https://code.lksz.me/lksz/PowerShell_Scripts',
[Parameter(DontShow)]
[string]$My_PSScriptRoot = $MyPSScriptRoot
@ -15,7 +15,7 @@ function _Setup {
[switch]$RemoveOnly,
[switch]$ShowSkipped,
[switch]$Force,
[switch]$NoGitClone,
[switch]$NoGitAction,
[string]$GitURL = 'https://code.lksz.me/lksz/PowerShell_Scripts',
[Parameter(DontShow)]
[string]$My_PSScriptRoot = $MyPSScriptRoot)
@ -43,12 +43,14 @@ Get-Command Reload-MyScripts -ErrorAction SilentlyContinue | ForEach-Object { .
. ProfileCode_common
if( -not $MyPSScriptRoot ) { throw '$MyPSScriptRoot does NOT exist!' }
if ( -not $NoGitClone -and -not (Test-Path $(Join-Path $MyPSScriptRoot '.git')) ) {
if ( -not $NoGitAction ) {
if ( -not [bool]$(Get-Command git -ErrorAction SilentlyContinue) ) {
throw "No git command found, you may either omit run with the -NoGitClone switch or install git and try again."
throw "No git command found, you may either omit run with the -NoGitAction switch or install git and try again."
}
if ( $PSCmdlet.ShouldProcess("Pull git repo from $GitURL into $MyPSScriptRoot ?") ) {
Push-Location $MyPSScriptRoot
Push-Location $MyPSScriptRoot
if( Test-Path $(Join-Path $MyPSScriptRoot '.git') ) {
git pull
} elseif ( $PSCmdlet.ShouldProcess("Pull git repo from $GitURL into $MyPSScriptRoot ?") ) {
$local:tmpGitDir = New-TemporaryFile
Remove-Item $tmpGitDir
New-Item -Type Directory $tmpGitDir.FullName | Out-Null
@ -61,9 +63,9 @@ Get-Command Reload-MyScripts -ErrorAction SilentlyContinue | ForEach-Object { .
Write-Verbose "Checking out repo..."
$GitOutput = "$(& git checkout --force)"
Write-Verbose $GitOutput
Pop-Location
Write-Verbose "Git clone done."
}
Pop-Location
Write-Verbose "Git operation done."
}
$local:ProfileSignature = [PSCustomObject]([ordered]@{
@ -421,5 +423,6 @@ $SetupFromWeb = [bool]$(@( $SetupFromWeb, $sfw, $LoadCode ) | Where-Object { $_
if ( -not $SetupFromWeb ) {
_setup @PSBoundParameters
Get-Item function:_setup | Remove-Item
Get-Command Reload-MyScripts -ErrorAction SilentlyContinue | ForEach-Object { . $_.Name }
}
Remove-Variable SetupFromWeb -ErrorAction SilentlyContinue