

#Log "*** A fatal error occured: $($_.Exception)" Throw "Unable to successfully exec '$($exe)' within $($maxRetries) attempts."įunction GitWithRetry(]$arguments, $echo=$true)ĮxecWithRetry "git" $arguments $echo -exceptionMustContain "Another git process seems to be running" Log "Last Error from $($exe) is retryable ($($i + 1) of $($maxRetries))" $true

If (-not ::IsNullOrEmpty($exceptionMustContain) -and $_.Exception.ToString().Contains($exceptionMustContain))
#Git annex unlock .exe
$maxRetries = 5, $msDelay = 3000, $exceptionMustContain = $null)Įxec $exe $arguments $echo $stopOnNonZeroExitCode Log $output $false # don't echo to screen as the pipe above didįunction ExecWithRetry($exe, ]$arguments, $echo=$true, $stopOnNonZeroExitCode=$true, $ErrorActionPreference = $orgErrorActionPreference
#Git annex unlock code
Throw "Exit code ($($LASTEXITCODE)) was non-zero. If ($stopOnNonZeroExitCode -and !$LASTEXITCODE -eq 0) & $exe $arguments 2>&1 | tee -variable output | out-null & $exe $arguments 2>&1 | tee -variable output | Write-Host | out-null # This is simplest but has some issues with stderr/stdout (stderr caught as exception below) #& cmd /c "`"" $exe $arguments "`"" | Tee-Object -variable output | Write-Host | out-null # but unfortuantely cmd has some bizarre de-quoting rules that weren't working for all cases. # line (and stops capturing additional lines). When a command such as "git" writes to stderr, powershell was terminating on the first stderr # Using "cmd.exe" allows the stderr -> stdout redirection to work properly. $ErrorActionPreference = "Continue" # required in order to catch more than 1 stderr line in the exception
#Git annex unlock windows
# - works when calling both console and windows executables. # - echoes the output live as it is streamed to the current window, # - merges stdout/stderr line by line properly, # This way some advantages over Invoke-Expressions or Start-Process for some cases: If ($false -and $exe -eq 'git') # todo make this a generic flag $error.clear() # this apparently catches all the stderr pipe lines $orgErrorActionPreference = $ErrorActionPreference # Passing $args (list) as a single parameter is the most flexible, it supports spaces and double quotes Return Exec $command $args $echo $stopOnNonZeroExitCodeįunction Exec($exe, ]$arguments, $echo=$true, $stopOnNonZeroExitCode=$true) $fullmsg = $msg -replace '(?ms)^', $timestamp # the (?ms) enables multiline modeįunction ExecSimple($command, $echo=$true, $stopOnNonZeroExitCode=$true) $timestamp = "$(get-date -Format 'yyyy/MM/dd HH:mm:ss'): "

# If (Test-Path $logFile) įunction Log($msg, $echo = $true) $scriptDir = Split-Path $script:MyInvocation.M圜ommand.Path

