

#Read-Host -Prompt "`nA fatal error occurred, press enter to close.Now that git-annex is available as a package on OpenBSD I can use it again. #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 From DOS ( cmd.exe): powershell gitr -help.Copy the script to C:\bin and add C:\bin to $PATH.

It only has minimal testing with simple arguments. It was extracted from a larger commit script. It never removes the index.lock, assuming the user should intervene. Here is a PowerShell wrapper around Git named "gitr" that retries until index.lock disappears, using default five tries, three seconds between each. or even default to this when run manually. Perhaps 'git' itself should support a '-retriesWhenLocked 5' argument to support retries. For us, Sourcetree or Visual Studio appear to be be doing some maintenance in the background while we were are running large commit scripts. Each client should wait until the lock is released by the other party to be a good citizen. Multiple Git clients working on the same local repository compete for that lock.
