fix: 改进 Windows SSH PowerShell 错误提示
This commit is contained in:
+21
-8
@@ -657,10 +657,21 @@ Set-Location -LiteralPath ${cwd}
|
||||
$operation=${powerShellSingleQuote(operation)}
|
||||
$paths=@(${pathList})
|
||||
$message=${powerShellSingleQuote(message)}
|
||||
$gitWarnings=[Collections.Generic.List[string]]::new()
|
||||
function Invoke-Git([string[]]$GitArgs) {
|
||||
$output = @(& git @GitArgs 2>&1)
|
||||
if ($LASTEXITCODE -ne 0) { throw (($output | ForEach-Object { $_.ToString() }) -join [Environment]::NewLine) }
|
||||
return (($output | ForEach-Object { $_.ToString() }) -join [Environment]::NewLine).Trim()
|
||||
$previousErrorActionPreference=$ErrorActionPreference
|
||||
try {
|
||||
$ErrorActionPreference='Continue'
|
||||
$records=@(& git @GitArgs 2>&1)
|
||||
$nativeExitCode=$LASTEXITCODE
|
||||
$stderr=(($records | Where-Object { $_ -is [Management.Automation.ErrorRecord] } | ForEach-Object { $_.Exception.Message }) -join [Environment]::NewLine).Trim()
|
||||
$stdout=(($records | Where-Object { $_ -isnot [Management.Automation.ErrorRecord] } | ForEach-Object { $_.ToString() }) -join [Environment]::NewLine).Trim()
|
||||
if($nativeExitCode -ne 0){throw ((@($stdout,$stderr) | Where-Object { $_ }) -join [Environment]::NewLine)}
|
||||
if($stderr){[void]$gitWarnings.Add($stderr)}
|
||||
return $stdout
|
||||
} finally {
|
||||
$ErrorActionPreference=$previousErrorActionPreference
|
||||
}
|
||||
}
|
||||
function Object-Status {
|
||||
$values=@{}
|
||||
@@ -671,13 +682,13 @@ $before=Object-Status
|
||||
$head=Invoke-Git @('rev-parse','--verify','HEAD^{commit}')
|
||||
$branch=Invoke-Git @('symbolic-ref','-q','HEAD')
|
||||
if($operation -eq 'status') {
|
||||
[ordered]@{ok=$true;operation=$operation;head=$head;branch=$branch;objects=$before;safeStop='read-only; no objects were pruned'} | ConvertTo-Json -Depth 8 -Compress
|
||||
[ordered]@{ok=$true;operation=$operation;head=$head;branch=$branch;objects=$before;warnings=@($gitWarnings);safeStop='read-only; no objects were pruned'} | ConvertTo-Json -Depth 8 -Compress
|
||||
exit 0
|
||||
}
|
||||
if($operation -eq 'gc-auto') {
|
||||
$gcOutput=Invoke-Git @('gc','--auto')
|
||||
$after=Object-Status
|
||||
[ordered]@{ok=$true;operation=$operation;head=$head;before=$before;after=$after;gcOutput=$gcOutput;safeStop='git gc --auto only; Git recent-object and reflog retention remain authoritative; no direct prune'} | ConvertTo-Json -Depth 8 -Compress
|
||||
[ordered]@{ok=$true;operation=$operation;head=$head;before=$before;after=$after;gcOutput=$gcOutput;warnings=@($gitWarnings);safeStop='git gc --auto only; Git recent-object and reflog retention remain authoritative; no direct prune'} | ConvertTo-Json -Depth 8 -Compress
|
||||
exit 0
|
||||
}
|
||||
$gitDir=Invoke-Git @('rev-parse','--path-format=absolute','--git-dir')
|
||||
@@ -693,7 +704,7 @@ try {
|
||||
$parentTree=Invoke-Git @('rev-parse',($head+'^{tree}'))
|
||||
if($tree -eq $parentTree){throw 'selected paths do not change the HEAD tree'}
|
||||
if($operation -eq 'plan') {
|
||||
[ordered]@{ok=$true;operation=$operation;head=$head;branch=$branch;tree=$tree;paths=$paths;tempIndex=$tempIndex;objectsBefore=$before;safeStop='plan only; ref and original index unchanged'} | ConvertTo-Json -Depth 8 -Compress
|
||||
[ordered]@{ok=$true;operation=$operation;head=$head;branch=$branch;tree=$tree;paths=$paths;tempIndex=$tempIndex;objectsBefore=$before;warnings=@($gitWarnings);safeStop='plan only; ref and original index unchanged'} | ConvertTo-Json -Depth 8 -Compress
|
||||
exit 0
|
||||
}
|
||||
$commit=($message | & git commit-tree $tree -p $head).Trim()
|
||||
@@ -704,12 +715,13 @@ try {
|
||||
$unrelatedAfter=Invoke-Git (@('status','--porcelain=v2','--')+$unrelatedPathspec)
|
||||
if($unrelatedAfter -ne $unrelatedBefore){throw 'unselected worktree/index fingerprint changed after exact commit'}
|
||||
$after=Object-Status
|
||||
[ordered]@{ok=$true;operation=$operation;oldHead=$head;commit=$commit;tree=$tree;branch=$branch;paths=$paths;tempIndex=$tempIndex;unselectedStateUnchanged=$true;selectedPathsIndexUpdated=$true;objectsBefore=$before;objectsAfter=$after;safeStop='ref updated with old-value CAS; no prune performed'} | ConvertTo-Json -Depth 8 -Compress
|
||||
[ordered]@{ok=$true;operation=$operation;oldHead=$head;commit=$commit;tree=$tree;branch=$branch;paths=$paths;tempIndex=$tempIndex;unselectedStateUnchanged=$true;selectedPathsIndexUpdated=$true;objectsBefore=$before;objectsAfter=$after;warnings=@($gitWarnings);safeStop='ref updated with old-value CAS; no prune performed'} | ConvertTo-Json -Depth 8 -Compress
|
||||
} finally {
|
||||
Remove-Item Env:GIT_INDEX_FILE -ErrorAction SilentlyContinue
|
||||
Remove-Item -LiteralPath $tempIndex -Force -ErrorAction SilentlyContinue
|
||||
Remove-Item -LiteralPath ($tempIndex+'.lock') -Force -ErrorAction SilentlyContinue
|
||||
}`;
|
||||
}
|
||||
exit 0`;
|
||||
}
|
||||
|
||||
function validateWindowsGitCommitArgs(route: ParsedSshRoute, gitArgs: string[]): void {
|
||||
@@ -2058,6 +2070,7 @@ export {
|
||||
sshTcpPoolHint,
|
||||
sshTruncationCompletionSummary,
|
||||
sshWindowsPlaneHint,
|
||||
sshWindowsPowerShellPipelineHint,
|
||||
} from "./ssh-runtime";
|
||||
export type { SshStreamForwarder } from "./ssh-runtime";
|
||||
export { windowsFsReadOnlyScript } from "./ssh-windows-fs";
|
||||
|
||||
Reference in New Issue
Block a user