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