This commit is contained in:
Ivan Fontosh
2026-05-18 09:48:09 +08:00
parent d07dcae626
commit 0ae3c39333
+29 -2
View File
@@ -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) { function Write-GitLines($lines) {
foreach ($line in $lines) { foreach ($line in $lines) {
if ($line -is [System.Management.Automation.ErrorRecord]) { if ($line -is [System.Management.Automation.ErrorRecord]) {
@@ -141,7 +168,7 @@ function Invoke-GitPush {
} }
function Push-Git([string]$ProjectRoot, [string]$Remote, [string]$McpConfigPath) { 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" Write-Host " > git push $Remote $branch"
$exitCode = Invoke-GitPush $ProjectRoot @($Remote, $branch) $exitCode = Invoke-GitPush $ProjectRoot @($Remote, $branch)
if ($exitCode -eq 0) { if ($exitCode -eq 0) {
@@ -332,7 +359,7 @@ if ($SkipGit) {
Invoke-Git $projectRoot @('add', 'package-lock.json') Invoke-Git $projectRoot @('add', 'package-lock.json')
} }
$commitMsg = "chore: release v$newVersion" $commitMsg = "chore: release v$newVersion"
$status = (git -C $projectRoot status --porcelain).Trim() $status = Get-GitTextOutput $projectRoot @('status', '--porcelain')
if ($status) { if ($status) {
Invoke-Git $projectRoot @('commit', '-m', $commitMsg) Invoke-Git $projectRoot @('commit', '-m', $commitMsg)
Write-Ok "committed: $commitMsg" Write-Ok "committed: $commitMsg"