diff --git a/scripts/git-push.ps1 b/scripts/git-push.ps1 index d2c9db2..dcdd195 100644 --- a/scripts/git-push.ps1 +++ b/scripts/git-push.ps1 @@ -76,9 +76,10 @@ function Write-Ok($text) { Write-Host " $text" -ForegroundColor Green } function Write-Warn2($text){ Write-Host " $text" -ForegroundColor Yellow } # 推送失败时读取错误输出,用于识别「远程有本地没有的提交」这类情况 +# 注意:参数名不能叫 Args —— 那是 PowerShell 的自动变量,会吞掉传入的数组 function Invoke-GitCapture { - param([string[]]$Args) - $out = & git @Args 2>&1 + param([string[]]$GitArgs) + $out = & git @GitArgs 2>&1 return @{ Output = ($out | Out-String).Trim(); Code = $LASTEXITCODE } } @@ -182,7 +183,7 @@ $pushArgs = @("push") if ($Force) { $pushArgs += "--force-with-lease" } $pushArgs += @($pushUrl, $branch) -$result = Invoke-GitCapture -Args $pushArgs +$result = Invoke-GitCapture -GitArgs $pushArgs # 输出里若回显了带凭据的地址,遮蔽掉 $shown = $result.Output if ($tempCred) { @@ -204,7 +205,7 @@ if ($result.Code -eq 0) { $pushArgs = @("push") if ($Force) { $pushArgs += "--force-with-lease" } $pushArgs += @($pushUrl, $branch) - $result = Invoke-GitCapture -Args $pushArgs + $result = Invoke-GitCapture -GitArgs $pushArgs if ($result.Code -ne 0) { Write-Warn2 $result.Output throw "推送仍然失败"