Modules/businessdev.ALbuild.Core/Private/Invoke-BcGit.ps1
|
function Invoke-BcGit { <# .SYNOPSIS Runs a git command against a repository and returns the process result. .DESCRIPTION Internal single git surface for the module so callers never shell out to git directly and tests can mock one function. Wraps Invoke-ALbuildProcess (no retry) with '-C <root>'. By default a non-zero exit throws a descriptive error; pass -AllowFailure to return the result object instead (used by callers that must inspect the exit code/stderr, e.g. the build-branch compare-and-swap claim). .PARAMETER RepositoryRoot The git working tree to operate on. .PARAMETER Arguments The git arguments (no leading 'git', no '-C <root>'). .PARAMETER AllowFailure Return the result object on failure instead of throwing. .OUTPUTS PSCustomObject with ExitCode, StdOut, StdErr, Success, Attempts. #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'Arguments is a list passed verbatim to git; plural is intentional and the function is private.')] [CmdletBinding()] [OutputType([PSCustomObject])] param( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $RepositoryRoot, [Parameter(Mandatory)] [string[]] $Arguments, [switch] $AllowFailure ) $result = Invoke-ALbuildProcess -FilePath 'git' -Arguments (@('-C', $RepositoryRoot) + $Arguments) -PassThru -RetryCount 0 if (-not $result.Success -and -not $AllowFailure) { $detail = if ([string]::IsNullOrWhiteSpace($result.StdErr)) { $result.StdOut } else { $result.StdErr } throw "git $($Arguments -join ' ') failed (exit $($result.ExitCode)): $($detail.Trim())" } return $result } |