Add repository cloning and VSCode opening to install.ps1
- Ask user if they want to clone workshop to Documents/git-workshop - Automatically clone repository to Documents folder for convenience - Open VSCode in the workshop directory after cloning - Handle existing repositories (update if already cloned) - Provide quick start commands for VSCode terminal - Fallback to manual instructions if user declines or cloning fails - Complete end-to-end setup experience
This commit is contained in:
74
install.ps1
74
install.ps1
@@ -593,10 +593,78 @@ if ($allRequired) {
|
||||
Write-Host ""
|
||||
|
||||
Write-Host "You're ready to start the workshop!" -ForegroundColor Green
|
||||
Write-Host " cd path\to\git-workshop" -ForegroundColor White
|
||||
Write-Host " cd 01-essentials\01-basics" -ForegroundColor White
|
||||
Write-Host " .\setup.ps1" -ForegroundColor White
|
||||
Write-Host ""
|
||||
|
||||
# Ask user if they want to clone the workshop repository
|
||||
Write-Step "Workshop Setup"
|
||||
|
||||
if (Get-UserConfirmation "Clone the Git Workshop repository to Documents\git-workshop and open in VSCode?") {
|
||||
try {
|
||||
$documentsPath = [System.Environment]::GetFolderPath("MyDocuments")
|
||||
$workshopPath = Join-Path $documentsPath "git-workshop"
|
||||
|
||||
Write-Host " Cloning to: $workshopPath" -ForegroundColor Gray
|
||||
|
||||
# Create directory if it doesn't exist
|
||||
$documentsDir = Split-Path $workshopPath -Parent
|
||||
if (-not (Test-Path $documentsDir)) {
|
||||
New-Item -Path $documentsDir -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
|
||||
# Clone or update the repository
|
||||
if (Test-Path $workshopPath) {
|
||||
Write-Host " Directory already exists. Checking if it's a git repository..." -ForegroundColor Yellow
|
||||
Push-Location $workshopPath
|
||||
if (Get-Command git -ErrorAction SilentlyContinue) {
|
||||
$remoteResult = git remote get-url origin 2>$null
|
||||
if ($LASTEXITCODE -eq 0 -and $remoteResult -like "*git-workshop*") {
|
||||
Write-Host " Repository already exists. Updating..." -ForegroundColor Cyan
|
||||
git pull origin main
|
||||
} else {
|
||||
Write-Warning " Directory exists but is not the git-workshop repository"
|
||||
Write-Host " Please remove the directory manually and run again" -ForegroundColor Yellow
|
||||
Pop-Location
|
||||
return
|
||||
}
|
||||
}
|
||||
Pop-Location
|
||||
} else {
|
||||
git clone "https://git.frod.dk/floppydiscen/git-workshop.git" $workshopPath
|
||||
Write-Success "Repository cloned successfully!"
|
||||
}
|
||||
|
||||
# Open in VSCode
|
||||
Write-Host " Opening in VSCode..." -ForegroundColor Cyan
|
||||
if (Get-Command code -ErrorAction SilentlyContinue) {
|
||||
& code $workshopPath
|
||||
Write-Success "VSCode opened with the workshop repository"
|
||||
} else {
|
||||
Write-Warning "VSCode command not found. Please open manually:"
|
||||
Write-Host " code '$workshopPath'" -ForegroundColor White
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Quick start commands (run in VSCode terminal):" -ForegroundColor Cyan
|
||||
Write-Host " cd 01-essentials\01-basics" -ForegroundColor White
|
||||
Write-Host " .\setup.ps1" -ForegroundColor White
|
||||
Write-Host ""
|
||||
|
||||
} catch {
|
||||
Write-Error "Failed to clone repository: $_"
|
||||
Write-Host ""
|
||||
Write-Host "You can clone manually:" -ForegroundColor Yellow
|
||||
Write-Host " git clone https://git.frod.dk/floppydiscen/git-workshop.git ~/Documents/git-workshop" -ForegroundColor White
|
||||
Write-Host " code ~/Documents/git-workshop" -ForegroundColor White
|
||||
}
|
||||
} else {
|
||||
Write-Host " Skipping repository clone." -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Write-Host "Manual setup:" -ForegroundColor Cyan
|
||||
Write-Host " cd path\to\git-workshop" -ForegroundColor White
|
||||
Write-Host " cd 01-essentials\01-basics" -ForegroundColor White
|
||||
Write-Host " .\setup.ps1" -ForegroundColor White
|
||||
Write-Host ""
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Host ""
|
||||
|
||||
Reference in New Issue
Block a user