Skip to content

Commit 2d8597f

Browse files
committed
win bug fixes
1 parent 682b098 commit 2d8597f

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

win/common-utils.ps1

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,34 +62,33 @@ function Invoke-GitClone {
6262
[string]$LogFile
6363
)
6464

65-
# Build arguments
65+
# Build branch flag
6666
$branchArg = ""
6767
if ($Branch) { $branchArg = "-b `"$Branch`"" }
6868

69-
# Construct the full command as a cmd.exe-safe string
69+
# Command string
7070
$cmd = "git clone $branchArg `"$Url`" `"$Target`""
7171

72-
# Paths for temp logs
73-
$stdoutFile = Join-Path $env:TEMP "git_stdout.txt"
74-
$stderrFile = Join-Path $env:TEMP "git_stderr.txt"
72+
# Always safe: redirect via CMD so PowerShell can't corrupt the cmdline
73+
$tempOut = Join-Path $env:TEMP "git_clone_output.txt"
74+
cmd.exe /c "$cmd > `"$tempOut`" 2>&1"
75+
$exit = $LASTEXITCODE
7576

76-
# Run using cmd.exe (prevents hangs on GH Actions)
77-
cmd /c "$cmd 1> `"$stdoutFile`" 2> `"$stderrFile`""
78-
$exitCode = $LASTEXITCODE
79-
80-
# Read logs
81-
$stdout = ""
82-
$stderr = ""
83-
if (Test-Path $stdoutFile) { $stdout = Get-Content $stdoutFile -Raw }
84-
if (Test-Path $stderrFile) { $stderr = Get-Content $stderrFile -Raw }
77+
# Read output
78+
$output = ""
79+
if (Test-Path $tempOut) {
80+
$output = Get-Content $tempOut -Raw
81+
}
8582

83+
# Write log if needed
8684
if ($LogFile) {
87-
if ($stdout) { Add-Content -Path $LogFile -Value $stdout }
88-
if ($stderr) { Add-Content -Path $LogFile -Value $stderr }
85+
Add-Content $LogFile "[git clone cmd] $cmd"
86+
Add-Content $LogFile $output
8987
}
9088

91-
if ($exitCode -ne 0) {
92-
throw "git clone failed (exit $exitCode): $stderr"
89+
# Throw if git clone failed
90+
if ($exit -ne 0) {
91+
throw "git clone failed with exit code $exit.`n$output"
9392
}
9493
}
9594

0 commit comments

Comments
 (0)