Write-Host "修复 Scoop 和 Git 安装..." $scoopDir = "E:\Scoop" $appsDir = "$scoopDir\apps" $shimsDir = "$scoopDir\shims" # 1. 修复 7zip shim Write-Host "1. 修复 7zip shim..." $7zShim = "$shimsDir\7z.shim" $7zPath = "$appsDir\7zip\25.01\7z.exe" if (Test-Path $7zPath) { if (Test-Path $7zShim) { Set-Content $7zShim "path = `"$7zPath`"" Write-Host " 更新 7z.shim 指向: $7zPath" } else { Write-Host " 错误: 7z.shim 不存在" } } else { Write-Host " 错误: 7z.exe 未找到,请先安装 7-zip: scoop install 7zip" exit 1 } # 2. 修复 7zip current 符号链接 Write-Host "2. 修复 7zip current 符号链接..." $7zipCurrent = "$appsDir\7zip\current" if (-not (Test-Path $7zipCurrent)) { cmd /c mklink /J "$7zipCurrent" "$appsDir\7zip\25.01" 2>$null if (Test-Path $7zipCurrent) { Write-Host " 创建 current 符号链接" } else { Write-Host " 警告: 无法创建符号链接,使用绝对路径" } } else { Write-Host " current 符号链接已存在" } # 3. 手动提取 Git Write-Host "3. 手动提取 Git..." $gitDir = "$appsDir\git\2.53.0.2" $dl7z = "$gitDir\dl.7z" if (Test-Path $dl7z) { Write-Host " 找到 dl.7z: $dl7z" # 创建目标目录 if (-not (Test-Path $gitDir)) { New-Item -ItemType Directory -Path $gitDir -Force | Out-Null } # 使用 7z 提取 Write-Host " 正在提取文件..." & $7zPath x "-o$gitDir" "-y" "$dl7z" | Out-Null if (Test-Path "$gitDir\bin\git.exe") { Write-Host " 提取成功: git.exe 已存在" } else { Write-Host " 警告: 提取可能失败,检查目录内容" Get-ChildItem $gitDir -Recurse -File | Select-Object -First 10 | ForEach-Object { Write-Host " $_" } } } else { Write-Host " 错误: dl.7z 未找到,请重新下载" Write-Host " 运行: scoop cache rm git; scoop download git" exit 1 } # 4. 创建 Git shims Write-Host "4. 创建 Git shims..." # git shim $gitShim = "$shimsDir\git.shim" $gitExe = "$gitDir\bin\git.exe" if (Test-Path $gitExe) { Set-Content $gitShim "path = `"$gitExe`"" Write-Host " 创建 git.shim" # 复制 shim 可执行文件 $shimExe = "$shimsDir\git.exe" if (-not (Test-Path $shimExe)) { Copy-Item "$shimsDir\7z.exe" $shimExe -ErrorAction SilentlyContinue if (Test-Path $shimExe) { Write-Host " 创建 git.exe shim" } } } else { Write-Host " 错误: git.exe 未找到" } # sh (bash) shim $shShim = "$shimsDir\sh.shim" $shExe = "$gitDir\bin\sh.exe" if (Test-Path $shExe) { Set-Content $shShim "path = `"$shExe`"" Write-Host " 创建 sh.shim" } else { Write-Host " 警告: sh.exe 未找到" } # git-bash shim $gitBashShim = "$shimsDir\git-bash.shim" $gitBashExe = "$gitDir\git-bash.exe" if (Test-Path $gitBashExe) { Set-Content $gitBashShim "path = `"$gitBashExe`"" Write-Host " 创建 git-bash.shim" } # 5. 更新 PATH 并测试 Write-Host "5. 测试安装..." $env:Path = "$shimsDir;$env:Path" Write-Host "`n测试命令:" try { $gitVersion = git --version 2>$null if ($gitVersion) { Write-Host " ✓ git: $gitVersion" } else { Write-Host " ✗ git: 命令失败" Write-Host " 临时使用: $gitExe" } } catch { Write-Host " ✗ git: 错误: $_" } try { $7zVersion = 7z --help 2>$null | Select-Object -First 1 if ($7zVersion) { Write-Host " ✓ 7z: 可用" } } catch { Write-Host " ✗ 7z: 错误" } Write-Host "`n修复完成!" Write-Host "如果命令仍然不可用,请重启终端或运行:" Write-Host " `$env:Path = `"$shimsDir;`$env:Path`"" Write-Host "`n然后测试: git --version"