refactor: 更新Git仓库检查逻辑,避免直接访问GitHub并使用镜像站进行pull操作

This commit is contained in:
2025-09-25 22:40:00 +08:00
parent 2101ae9908
commit 29bd8a4aff
2 changed files with 40 additions and 75 deletions

View File

@@ -207,7 +207,7 @@ export async function cloneBackend(
// ==== 下面是关键逻辑 ====
if (isGitRepository(backendPath)) {
// 已是 git 仓库,直接 pull
// 已是 git 仓库,先更新远程URL为镜像站然后 pull
if (mainWindow) {
mainWindow.webContents.send('download-progress', {
type: 'backend',
@@ -216,6 +216,24 @@ export async function cloneBackend(
message: '正在更新后端代码...',
})
}
// 更新远程URL为镜像站URL避免直接访问GitHub
console.log(`更新远程URL为镜像站: ${repoUrl}`)
await new Promise<void>((resolve, reject) => {
const proc = spawn(gitPath, ['remote', 'set-url', 'origin', repoUrl], {
stdio: 'pipe',
env: gitEnv,
cwd: backendPath
})
proc.stdout?.on('data', d => console.log('git remote set-url:', d.toString()))
proc.stderr?.on('data', d => console.log('git remote set-url err:', d.toString()))
proc.on('close', code =>
code === 0 ? resolve() : reject(new Error(`git remote set-url失败退出码: ${code}`))
)
proc.on('error', reject)
})
// 执行pull操作
await new Promise<void>((resolve, reject) => {
const proc = spawn(gitPath, ['pull'], { stdio: 'pipe', env: gitEnv, cwd: backendPath })
proc.stdout?.on('data', d => console.log('git pull:', d.toString()))