git 이 없으면 설치하는 부분 추가
This commit is contained in:
1 parent
d2eb316853
commit
3e2ac25713
2 files changed
+348
-140
No files matched your search
@@ -48,6 +48,8 @@ $ErrorActionPreference = 'Stop'
|
||||
# ────────────────────────────────────────────
|
||||
$REPO = "jesseduffield/lazygit"
|
||||
$API_URL = "https://api.github.com/repos/$REPO/releases"
|
||||
$GIT_REPO = "git-for-windows/git"
|
||||
$GIT_API_URL = "https://api.github.com/repos/$GIT_REPO/releases"
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# Utility functions
|
||||
@@ -62,6 +64,156 @@ function Write-Err { param([string]$msg) Write-Host "[ERROR] $msg" -Foregrou
|
||||
# ────────────────────────────────────────────
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# Check for git (required by lazygit)
|
||||
# ────────────────────────────────────────────
|
||||
function Install-GitPortable {
|
||||
Write-Info "git is not installed. Installing PortableGit..."
|
||||
|
||||
# Detect architecture
|
||||
$envArch = $env:PROCESSOR_ARCHITEW6432
|
||||
if (-not $envArch) { $envArch = $env:PROCESSOR_ARCHITECTURE }
|
||||
|
||||
$gitArch = ""
|
||||
if ($envArch -eq "AMD64") {
|
||||
$gitArch = "64-bit"
|
||||
} elseif ($envArch -eq "ARM64") {
|
||||
$gitArch = "arm64"
|
||||
} else {
|
||||
Write-Err "Unsupported architecture for PortableGit: $envArch"
|
||||
}
|
||||
|
||||
# Find latest Git for Windows release
|
||||
Write-Info "Fetching latest Git for Windows release..."
|
||||
try {
|
||||
$releases = Invoke-RestMethod -Uri $GIT_API_URL -UseBasicParsing `
|
||||
-Headers @{ 'User-Agent' = 'install-lazygit-ps1' }
|
||||
} catch {
|
||||
Write-Err "Failed to call GitHub API for Git: $_"
|
||||
}
|
||||
|
||||
$latestRelease = $releases | Where-Object { $_.prerelease -eq $false } | Select-Object -First 1
|
||||
if (-not $latestRelease) {
|
||||
Write-Err "Could not find latest Git for Windows release."
|
||||
}
|
||||
|
||||
$tagName = $latestRelease.tag_name
|
||||
# Git for Windows tags look like "v2.54.0.windows.1"
|
||||
$gitVersion = $tagName -replace '^v', '' -replace '\.windows\.\d+$', ''
|
||||
Write-Info "Latest Git for Windows: $tagName (version $gitVersion)"
|
||||
|
||||
# Find the PortableGit asset for our architecture
|
||||
$portablePattern = "PortableGit-${gitVersion}-${gitArch}.7z.exe"
|
||||
$asset = $latestRelease.assets | Where-Object { $_.name -eq $portablePattern } | Select-Object -First 1
|
||||
|
||||
if (-not $asset) {
|
||||
Write-Err "Could not find PortableGit asset matching '$portablePattern' in release $tagName."
|
||||
}
|
||||
|
||||
$downloadUrl = $asset.browser_download_url
|
||||
$installPath = Join-Path $env:USERPROFILE "PortableGit"
|
||||
|
||||
# Download
|
||||
$tmpDir = Join-Path $env:TEMP "git_install_$(Get-Random)"
|
||||
New-Item -ItemType Directory -Path $tmpDir -Force | Out-Null
|
||||
$zipPath = Join-Path $tmpDir "$portablePattern"
|
||||
|
||||
try {
|
||||
Write-Info "Downloading: $downloadUrl"
|
||||
$ProgressPreference = 'SilentlyContinue'
|
||||
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath -UseBasicParsing
|
||||
$ProgressPreference = 'Continue'
|
||||
|
||||
# PortableGit .7z.exe is a self-extracting archive
|
||||
# Run it to extract to the install path
|
||||
Write-Info "Extracting PortableGit to $installPath..."
|
||||
|
||||
# Try 7z first, then fall back to running the .7z.exe self-extractor
|
||||
$extracted = $false
|
||||
if (Get-Command 7z -ErrorAction SilentlyContinue) {
|
||||
& 7z x $zipPath -o"$installPath" -y 2>&1 | Out-Null
|
||||
$extracted = $true
|
||||
} else {
|
||||
# The .7z.exe is a self-extracting archive; run it with -y and -o"path"
|
||||
# It needs to be run as an executable
|
||||
try {
|
||||
& $zipPath -y -o"$installPath" 2>&1 | Out-Null
|
||||
$extracted = $true
|
||||
} catch {
|
||||
Write-Warn "Self-extractor failed, trying PowerShell expansion..."
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $extracted) {
|
||||
Write-Err "Cannot extract PortableGit. Install 7-Zip or install git manually from https://git-scm.com/download/win"
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (Test-Path $tmpDir) {
|
||||
Remove-Item -Path $tmpDir -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
# Verify git.exe
|
||||
$gitExe = Join-Path $installPath "cmd\git.exe"
|
||||
if (-not (Test-Path $gitExe)) {
|
||||
# Try bin directory as fallback
|
||||
$gitExe = Join-Path $installPath "bin\git.exe"
|
||||
}
|
||||
if (-not (Test-Path $gitExe)) {
|
||||
# Search recursively
|
||||
$found = Get-ChildItem -Path $installPath -Recurse -Filter "git.exe" -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||
if ($found) { $gitExe = $found.FullName }
|
||||
}
|
||||
|
||||
if (-not (Test-Path $gitExe)) {
|
||||
Write-Err "git.exe not found after extraction. Please install git manually."
|
||||
}
|
||||
|
||||
# Add git's directory to PATH for this session and permanently
|
||||
$gitDir = Split-Path $gitExe
|
||||
if ($env:Path -notlike "*$gitDir*") {
|
||||
$env:Path = "$gitDir;$env:Path"
|
||||
Write-Info "Added $gitDir to PATH for this session"
|
||||
}
|
||||
|
||||
$userPath = [System.Environment]::GetEnvironmentVariable('Path', 'User')
|
||||
if ($userPath -notlike "*$gitDir*") {
|
||||
[System.Environment]::SetEnvironmentVariable('Path', "$gitDir;$userPath", 'User')
|
||||
Write-Success "Added $gitDir to user PATH permanently"
|
||||
} else {
|
||||
Write-Info "$gitDir already in user PATH"
|
||||
}
|
||||
|
||||
# Also add the main bin dir for bash, ssh, etc.
|
||||
$gitBinDir = Join-Path $installPath "bin"
|
||||
if ((Test-Path $gitBinDir) -and ($env:Path -notlike "*$gitBinDir*")) {
|
||||
$env:Path = "$gitBinDir;$env:Path"
|
||||
$userPath = [System.Environment]::GetEnvironmentVariable('Path', 'User')
|
||||
if ($userPath -notlike "*$gitBinDir*") {
|
||||
[System.Environment]::SetEnvironmentVariable('Path', "$gitBinDir;$userPath", 'User')
|
||||
Write-Success "Added $gitBinDir to user PATH permanently"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Success "PortableGit installed to $installPath"
|
||||
}
|
||||
|
||||
# Check if git is available
|
||||
$gitCmd = Get-Command git -ErrorAction SilentlyContinue
|
||||
if (-not $gitCmd) {
|
||||
Install-GitPortable
|
||||
|
||||
# Refresh PATH and re-check
|
||||
$env:Path = [System.Environment]::GetEnvironmentVariable('Path', 'User') + ';' + [System.Environment]::GetEnvironmentVariable('Path', 'Machine')
|
||||
$gitCmd = Get-Command git -ErrorAction SilentlyContinue
|
||||
if (-not $gitCmd) {
|
||||
Write-Err "git installation failed. Please install git manually from https://git-scm.com/download/win and re-run this script."
|
||||
}
|
||||
}
|
||||
|
||||
Write-Success "git is available: $($gitCmd.Source)"
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# Architecture detection
|
||||
# ────────────────────────────────────────────
|
||||
|
||||
Reference in new issue
Block a user