fix: git clone pre-check

This commit is contained in:
zhayujie
2026-04-12 17:36:45 +08:00
parent d36d5aee3f
commit 907882c0a7
3 changed files with 42 additions and 20 deletions

View File

@@ -898,7 +898,7 @@ FAQs <https://github.com/zhayujie/CowAgent/wiki/FAQs>
# 📌 项目更名说明 # 📌 项目更名说明
本项目原名 `chatgpt-on-wechat`GitHub 原地址https://github.com/zhayujie/chatgpt-on-wechat 本项目原名 `chatgpt-on-wechat`GitHub 原地址https://github.com/zhayujie/chatgpt-on-wechat
于 2026.04.13 正式更名为 **CowAgent**。GitHub 已自动设置重定向,原有链接仍可正常访问。 于 2026.04.13 正式更名为 **CowAgent**。GitHub 已自动设置重定向,原有链接仍可正常访问。
如需更新本地仓库的远程地址(可选): 如需更新本地仓库的远程地址(可选):

17
run.sh
View File

@@ -171,12 +171,17 @@ clone_project() {
mv CowAgent-master CowAgent mv CowAgent-master CowAgent
rm CowAgent.zip rm CowAgent.zip
else else
GIT_HTTP_CONNECT_TIMEOUT=10 GIT_HTTP_LOW_SPEED_LIMIT=1024 GIT_HTTP_LOW_SPEED_TIME=15 \ local clone_ok=false
git clone --depth 10 --progress https://github.com/zhayujie/CowAgent.git || { # Test GitHub connectivity before attempting clone
echo -e "${YELLOW}⚠️ GitHub is slow, switching to Gitee mirror...${NC}" if curl -s --connect-timeout 5 --max-time 10 https://github.com > /dev/null 2>&1; then
git clone --depth 10 --progress https://gitee.com/zhayujie/CowAgent.git echo -e "${YELLOW}🌐 GitHub is reachable, cloning from GitHub...${NC}"
} timeout 15 git clone --depth 10 --progress https://github.com/zhayujie/CowAgent.git && clone_ok=true
if [[ $? -ne 0 ]]; then fi
if [ "$clone_ok" = false ]; then
echo -e "${YELLOW}⚠️ GitHub clone failed or timed out, switching to Gitee mirror...${NC}"
timeout 30 git clone --depth 10 --progress https://gitee.com/zhayujie/CowAgent.git && clone_ok=true
fi
if [ "$clone_ok" = false ]; then
echo -e "${RED}❌ Project clone failed. Please check network connection.${NC}" echo -e "${RED}❌ Project clone failed. Please check network connection.${NC}"
exit 1 exit 1
fi fi

View File

@@ -90,20 +90,37 @@ function Install-Project {
} }
Write-Cow "Cloning CowAgent project..." Write-Cow "Cloning CowAgent project..."
$prevEAP = $ErrorActionPreference; $ErrorActionPreference = "Continue" $cloneOk = $false
git clone https://github.com/zhayujie/CowAgent.git 2>&1 | Out-Null
$cloneExit = $LASTEXITCODE # Test GitHub connectivity before attempting clone
$ErrorActionPreference = $prevEAP try {
if ($cloneExit -ne 0) { $null = Invoke-WebRequest -Uri "https://github.com" -UseBasicParsing -TimeoutSec 5 -ErrorAction Stop
Write-Warn "GitHub failed, trying Gitee..." Write-Cow "GitHub is reachable, cloning from GitHub..."
$ErrorActionPreference = "Continue" $proc = Start-Process -FilePath "git" -ArgumentList "clone","--depth","10","--progress","https://github.com/zhayujie/CowAgent.git" `
git clone https://gitee.com/zhayujie/CowAgent.git 2>&1 | Out-Null -NoNewWindow -PassThru -RedirectStandardError "$env:TEMP\git_clone_err.txt"
$cloneExit = $LASTEXITCODE if ($proc.WaitForExit(15000) -and $proc.ExitCode -eq 0) {
$ErrorActionPreference = $prevEAP $cloneOk = $true
if ($cloneExit -ne 0) { } else {
Write-Err "Clone failed. Check your network." if (-not $proc.HasExited) { $proc.Kill() }
exit 1 if (Test-Path "CowAgent") { Remove-Item -Recurse -Force "CowAgent" }
} }
} catch {}
if (-not $cloneOk) {
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" `
-NoNewWindow -PassThru -RedirectStandardError "$env:TEMP\git_clone_err.txt"
if ($proc.WaitForExit(30000) -and $proc.ExitCode -eq 0) {
$cloneOk = $true
} else {
if (-not $proc.HasExited) { $proc.Kill() }
if (Test-Path "CowAgent") { Remove-Item -Recurse -Force "CowAgent" }
}
}
if (-not $cloneOk) {
Write-Err "Clone failed. Check your network."
exit 1
} }
Set-Location "CowAgent" Set-Location "CowAgent"