From 5b0d53313de7303c401f0bbe281e82c89ed29569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=BChnel?= Date: Mon, 16 Dec 2019 09:19:33 +0000 Subject: [PATCH] fixed git checkout script --- scripts/common.ps1 | 2 +- scripts/git_checkout.ps1 | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/scripts/common.ps1 b/scripts/common.ps1 index 496f593..61bd53d 100644 --- a/scripts/common.ps1 +++ b/scripts/common.ps1 @@ -43,7 +43,7 @@ function Invoke-Call { [scriptblock]$ScriptBlock, [string]$ErrorAction = $ErrorActionPreference ) - & @ScriptBlock 2>&1 | %{ "$_" } + & @ScriptBlock 2>&1 3>&1 4>&1| ForEach-Object { "$_" } if (($lastexitcode -ne 0) -and $ErrorAction -eq "Stop") { Write-Error "Command $ScriptBlock exited with $lastexitcode." exit $lastexitcode diff --git a/scripts/git_checkout.ps1 b/scripts/git_checkout.ps1 index 6d538ab..a7fd772 100644 --- a/scripts/git_checkout.ps1 +++ b/scripts/git_checkout.ps1 @@ -14,25 +14,26 @@ . ${PSScriptRoot}\common.ps1 -Set-PSDebug -Trace 1 +#Set-PSDebug -Trace 1 # Wrap git commant in error handling function -function Invoke-Git -{ - param ( - [scriptblock]$args - ) - Invoke-Call -ScriptBlock { git $args } -ErrorAction Stop +function Invoke-Git($cmd) { + Invoke-Call -ScriptBlock { git @cmd } -ErrorAction Stop } if (Test-Path -PathType Container "llvm-project"){ Set-Location llvm-project Write-Output "performing git pull..." - Invoke-Git checkout master - Invoke-Git reset - Invoke-Git clean -fdx - Invoke-Git pull + $branch = (git branch) | Out-String + $branch = ($branch -split '\r')[0] + if ($branch -ne "* master"){ + 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 } else { Write-Output "performing git clone..." - Invoke-Git clone -q --depth 1 https://github.com/llvm/llvm-project \ No newline at end of file + Invoke-Call -ScriptBlock { git clone -q --depth 1 https://github.com/llvm/llvm-project } -ErrorAction Stop +} \ No newline at end of file