Modules/businessdev.ALbuild.Core/Private/Test-BcGitPushConflict.ps1

function Test-BcGitPushConflict {
    <#
    .SYNOPSIS
        Decides whether a failed git push failed because the ref was already claimed.
    .DESCRIPTION
        Internal, pure helper. Inspects git push stderr and returns $true when the failure is a
        ref-already-exists / non-fast-forward rejection (the signal used as the build-branch /
        build-tag compare-and-swap lock), and $false for any other failure (auth, missing remote,
        network) which the caller should treat as a hard error.
    .PARAMETER StdErr
        The standard error captured from the git push.
    .OUTPUTS
        System.Boolean
    #>

    [CmdletBinding()]
    [OutputType([bool])]
    param(
        [AllowNull()] [AllowEmptyString()] [string] $StdErr
    )

    if ([string]::IsNullOrWhiteSpace($StdErr)) { return $false }

    $patterns = @(
        '\[rejected\]',
        'non-fast-forward',
        'fetch first',
        'failed to push some refs',
        'already exists',
        'stale info',
        'cannot lock ref',
        'Updates were rejected'
    )
    foreach ($p in $patterns) {
        if ($StdErr -match $p) { return $true }
    }
    return $false
}