1
0
Fork 0

fixed git checkout script

This commit is contained in:
Christian Kühnel 2019-12-16 09:19:33 +00:00
parent 1a2f1e2108
commit 5b0d53313d
2 changed files with 14 additions and 13 deletions

View file

@ -43,7 +43,7 @@ function Invoke-Call {
[scriptblock]$ScriptBlock, [scriptblock]$ScriptBlock,
[string]$ErrorAction = $ErrorActionPreference [string]$ErrorAction = $ErrorActionPreference
) )
& @ScriptBlock 2>&1 | %{ "$_" } & @ScriptBlock 2>&1 3>&1 4>&1| ForEach-Object { "$_" }
if (($lastexitcode -ne 0) -and $ErrorAction -eq "Stop") { if (($lastexitcode -ne 0) -and $ErrorAction -eq "Stop") {
Write-Error "Command $ScriptBlock exited with $lastexitcode." Write-Error "Command $ScriptBlock exited with $lastexitcode."
exit $lastexitcode exit $lastexitcode

View file

@ -14,25 +14,26 @@
. ${PSScriptRoot}\common.ps1 . ${PSScriptRoot}\common.ps1
Set-PSDebug -Trace 1 #Set-PSDebug -Trace 1
# Wrap git commant in error handling function # Wrap git commant in error handling function
function Invoke-Git function Invoke-Git($cmd) {
{ Invoke-Call -ScriptBlock { git @cmd } -ErrorAction Stop
param (
[scriptblock]$args
)
Invoke-Call -ScriptBlock { git $args } -ErrorAction Stop
} }
if (Test-Path -PathType Container "llvm-project"){ if (Test-Path -PathType Container "llvm-project"){
Set-Location llvm-project Set-Location llvm-project
Write-Output "performing git pull..." Write-Output "performing git pull..."
Invoke-Git checkout master $branch = (git branch) | Out-String
Invoke-Git reset $branch = ($branch -split '\r')[0]
Invoke-Git clean -fdx if ($branch -ne "* master"){
Invoke-Git pull Invoke-Call -ScriptBlock { git checkout master} -ErrorAction Stop
}
Invoke-Call -ScriptBlock { git reset --hard } -ErrorAction Stop
Invoke-Call -ScriptBlock { git clean -fdx } -ErrorAction Stop
Invoke-Call -ScriptBlock { git pull } -ErrorAction Stop
# TODO: in case of errors: delete folder and clone # TODO: in case of errors: delete folder and clone
} else { } else {
Write-Output "performing git clone..." Write-Output "performing git clone..."
Invoke-Git clone -q --depth 1 https://github.com/llvm/llvm-project Invoke-Call -ScriptBlock { git clone -q --depth 1 https://github.com/llvm/llvm-project } -ErrorAction Stop
}