gimmi
5/6/2019 - 6:50 PM

Powershell Git Batch

Powershell Git Batch

$ErrorActionPreference = "Stop"

function Run-Git() {
    $GitExe = (Get-Command -Name git -CommandType Application).Source
    $GitArgs = @('--no-pager', '-C') + $Args
    & $GitExe $GitArgs
}


$Paths = @(
    'C:\Users\gimmi\source\randomhacking',
    'C:\Users\gimmi\source\RabbitMQ.Async'
)

foreach ($Path in $Paths) {
    Write-Host "Updating $Path"
    Run-Git $Path 'diff' 'HEAD' '--quiet'
    if ($LastExitCode -ne 0) {
        Write-Host -ForegroundColor Red "Repo contains changes"
    } else {
        Run-Git $Path 'fetch' '--all'
        Run-Git $Path 'merge' '--ff-only'
    }
}