Add Git install step before OpenClaw (fixes npm ENOENT spawn git)

OpenClaw npm dependencies require git. Add check/install via
winget or choco, with fallback to git-scm.com manual download.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Rick Mu
2026-02-13 19:01:15 +11:00
parent 5e9d63ae1a
commit 1a84adb97b
2 changed files with 78 additions and 2 deletions

View File

@@ -85,7 +85,45 @@ if ($needsNode) {
}
# ─────────────────────────────────────────────
# 步骤 2: 安装 OpenClaw
# 步骤 2: 检查 / 安装 Git
# ─────────────────────────────────────────────
Write-Info "正在检查 Git..."
if (Get-Command git -ErrorAction SilentlyContinue) {
Write-Ok "已找到 Git。"
} else {
Write-Info "正在安装 GitOpenClaw 依赖需要)..."
$gitInstalled = $false
if (-not $gitInstalled -and (Get-Command winget -ErrorAction SilentlyContinue)) {
Write-Info "使用 winget 安装 Git..."
winget install Git.Git --accept-package-agreements --accept-source-agreements 2>$null
if ($LASTEXITCODE -eq 0) {
$gitInstalled = $true
Write-Ok "Git 已通过 winget 安装"
}
}
if (-not $gitInstalled -and (Get-Command choco -ErrorAction SilentlyContinue)) {
Write-Info "使用 Chocolatey 安装 Git..."
choco install git -y 2>$null
if ($LASTEXITCODE -eq 0) {
$gitInstalled = $true
Write-Ok "Git 已通过 Chocolatey 安装"
}
}
if (-not $gitInstalled) {
Write-Err "无法自动安装 Git。请手动下载安装`n`n 下载地址https://git-scm.com/download/win`n`n 安装完成后重新打开 PowerShell 运行此脚本。"
}
# 刷新 PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
}
# ─────────────────────────────────────────────
# 步骤 3: 安装 OpenClaw
# ─────────────────────────────────────────────
Write-Info "正在检查 OpenClaw..."