fix: run.ps1 git clone in windows

This commit is contained in:
zhayujie
2026-04-12 17:52:37 +08:00
parent 907882c0a7
commit 4dd497fb6d

View File

@@ -60,6 +60,7 @@ $PythonCmd = Find-Python
function Assert-Python { function Assert-Python {
if (-not $PythonCmd) { if (-not $PythonCmd) {
Write-Err "Python 3.9-3.13 not found. Please install from https://www.python.org/downloads/" Write-Err "Python 3.9-3.13 not found. Please install from https://www.python.org/downloads/"
Read-Host "Press Enter to exit"
exit 1 exit 1
} }
Write-Cow "Found Python: $PythonCmd" Write-Cow "Found Python: $PythonCmd"
@@ -86,6 +87,7 @@ function Install-Project {
$gitBin = Get-Command git -ErrorAction SilentlyContinue $gitBin = Get-Command git -ErrorAction SilentlyContinue
if (-not $gitBin) { if (-not $gitBin) {
Write-Err "Git not found. Please install from https://git-scm.com/download/win" Write-Err "Git not found. Please install from https://git-scm.com/download/win"
Read-Host "Press Enter to exit"
exit 1 exit 1
} }
@@ -96,30 +98,30 @@ function Install-Project {
try { try {
$null = Invoke-WebRequest -Uri "https://github.com" -UseBasicParsing -TimeoutSec 5 -ErrorAction Stop $null = Invoke-WebRequest -Uri "https://github.com" -UseBasicParsing -TimeoutSec 5 -ErrorAction Stop
Write-Cow "GitHub is reachable, cloning from GitHub..." Write-Cow "GitHub is reachable, cloning from GitHub..."
$proc = Start-Process -FilePath "git" -ArgumentList "clone","--depth","10","--progress","https://github.com/zhayujie/CowAgent.git" ` $prevEAP = $ErrorActionPreference; $ErrorActionPreference = "Continue"
-NoNewWindow -PassThru -RedirectStandardError "$env:TEMP\git_clone_err.txt" git clone --depth 10 --progress "https://github.com/zhayujie/CowAgent.git" 2>&1 | ForEach-Object { Write-Host $_ }
if ($proc.WaitForExit(15000) -and $proc.ExitCode -eq 0) { if ($LASTEXITCODE -eq 0) { $cloneOk = $true }
$cloneOk = $true $ErrorActionPreference = $prevEAP
} else { if (-not $cloneOk) {
if (-not $proc.HasExited) { $proc.Kill() }
if (Test-Path "CowAgent") { Remove-Item -Recurse -Force "CowAgent" } if (Test-Path "CowAgent") { Remove-Item -Recurse -Force "CowAgent" }
} }
} catch {} } catch {}
if (-not $cloneOk) { if (-not $cloneOk) {
Write-Warn "GitHub clone failed or timed out, switching to Gitee mirror..." Write-Warn "GitHub clone failed or timed out, switching to Gitee mirror..."
$proc = Start-Process -FilePath "git" -ArgumentList "clone","--depth","10","--progress","https://gitee.com/zhayujie/CowAgent.git" ` $prevEAP = $ErrorActionPreference; $ErrorActionPreference = "Continue"
-NoNewWindow -PassThru -RedirectStandardError "$env:TEMP\git_clone_err.txt" git clone --depth 10 --progress "https://gitee.com/zhayujie/CowAgent.git" 2>&1 | ForEach-Object { Write-Host $_ }
if ($proc.WaitForExit(30000) -and $proc.ExitCode -eq 0) { if ($LASTEXITCODE -eq 0) { $cloneOk = $true }
$cloneOk = $true $ErrorActionPreference = $prevEAP
} else { if (-not $cloneOk) {
if (-not $proc.HasExited) { $proc.Kill() }
if (Test-Path "CowAgent") { Remove-Item -Recurse -Force "CowAgent" } if (Test-Path "CowAgent") { Remove-Item -Recurse -Force "CowAgent" }
} }
} }
if (-not $cloneOk) { if (-not $cloneOk) {
Write-Err "Clone failed. Check your network." Write-Err "Clone failed from both GitHub and Gitee. Please check your network connection."
Write-Err "You can also manually clone: git clone https://gitee.com/zhayujie/CowAgent.git"
Read-Host "Press Enter to exit"
exit 1 exit 1
} }