diff --git a/scripts/ttrpg-release/prepare-release.ps1 b/scripts/ttrpg-release/prepare-release.ps1 index 0065c90..c16e0ee 100644 --- a/scripts/ttrpg-release/prepare-release.ps1 +++ b/scripts/ttrpg-release/prepare-release.ps1 @@ -114,6 +114,33 @@ function Invoke-Git { } } +function Get-GitTextOutput { + param( + [string]$ProjectRoot, + [string[]]$GitArgs + ) + $prevEap = $ErrorActionPreference + $ErrorActionPreference = 'Continue' + try { + $output = & git -C $ProjectRoot @GitArgs 2>&1 + if ($LASTEXITCODE -ne 0) { + throw "git $($GitArgs -join ' ') failed (exit $LASTEXITCODE)" + } + if ($null -eq $output) { + return '' + } + return (@($output | ForEach-Object { + if ($_ -is [System.Management.Automation.ErrorRecord]) { + $_.ToString() + } else { + [string]$_ + } + }) -join "`n").Trim() + } finally { + $ErrorActionPreference = $prevEap + } +} + function Write-GitLines($lines) { foreach ($line in $lines) { if ($line -is [System.Management.Automation.ErrorRecord]) { @@ -141,7 +168,7 @@ function Invoke-GitPush { } function Push-Git([string]$ProjectRoot, [string]$Remote, [string]$McpConfigPath) { - $branch = (git -C $ProjectRoot rev-parse --abbrev-ref HEAD).Trim() + $branch = Get-GitTextOutput $ProjectRoot @('rev-parse', '--abbrev-ref', 'HEAD') Write-Host " > git push $Remote $branch" $exitCode = Invoke-GitPush $ProjectRoot @($Remote, $branch) if ($exitCode -eq 0) { @@ -332,7 +359,7 @@ if ($SkipGit) { Invoke-Git $projectRoot @('add', 'package-lock.json') } $commitMsg = "chore: release v$newVersion" - $status = (git -C $projectRoot status --porcelain).Trim() + $status = Get-GitTextOutput $projectRoot @('status', '--porcelain') if ($status) { Invoke-Git $projectRoot @('commit', '-m', $commitMsg) Write-Ok "committed: $commitMsg"