150 lines
4.2 KiB
PowerShell
150 lines
4.2 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
<#
|
|
.SYNOPSIS
|
|
Sets up the Module 04 challenge environment for learning about merging.
|
|
|
|
.DESCRIPTION
|
|
This script creates a challenge directory with a Git repository that
|
|
contains two divergent branches ready to merge (three-way merge scenario).
|
|
#>
|
|
|
|
Write-Host "`n=== Setting up Module 04 Challenge ===" -ForegroundColor Cyan
|
|
|
|
# Remove existing challenge directory if it exists
|
|
if (Test-Path "challenge") {
|
|
Write-Host "Removing existing challenge directory..." -ForegroundColor Yellow
|
|
Remove-Item -Recurse -Force "challenge"
|
|
}
|
|
|
|
# Create fresh challenge directory
|
|
Write-Host "Creating challenge directory..." -ForegroundColor Green
|
|
New-Item -ItemType Directory -Path "challenge" | Out-Null
|
|
Set-Location "challenge"
|
|
|
|
# Initialize Git repository
|
|
Write-Host "Initializing Git repository..." -ForegroundColor Green
|
|
git init | Out-Null
|
|
|
|
# Configure git for this repository
|
|
git config user.name "Workshop Student"
|
|
git config user.email "student@example.com"
|
|
|
|
# Commit 1: Initial project structure on main
|
|
Write-Host "Creating initial project structure..." -ForegroundColor Green
|
|
$readmeContent = @"
|
|
# My Project
|
|
|
|
A simple web application project.
|
|
|
|
## Setup
|
|
|
|
Coming soon...
|
|
"@
|
|
Set-Content -Path "README.md" -Value $readmeContent
|
|
|
|
$appContent = @"
|
|
# app.py - Main application file
|
|
|
|
def main():
|
|
print("Welcome to My App!")
|
|
pass
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
"@
|
|
Set-Content -Path "app.py" -Value $appContent
|
|
|
|
git add .
|
|
git commit -m "Initial project structure" | Out-Null
|
|
|
|
# Create feature-login branch
|
|
Write-Host "Creating feature-login branch..." -ForegroundColor Green
|
|
git switch -c feature-login | Out-Null
|
|
|
|
# Commit on feature-login: Add login module
|
|
Write-Host "Adding login functionality on feature-login..." -ForegroundColor Green
|
|
$loginContent = @"
|
|
# login.py - User login module
|
|
|
|
def login(username, password):
|
|
"""Authenticate a user."""
|
|
print(f"Authenticating user: {username}")
|
|
# TODO: Add actual authentication logic
|
|
return True
|
|
|
|
def logout(username):
|
|
"""Log out a user."""
|
|
print(f"Logging out user: {username}")
|
|
return True
|
|
"@
|
|
Set-Content -Path "login.py" -Value $loginContent
|
|
|
|
git add .
|
|
git commit -m "Add login module" | Out-Null
|
|
|
|
# Second commit on feature-login: Integrate login with app
|
|
$appContent = @"
|
|
# app.py - Main application file
|
|
from login import login, logout
|
|
|
|
def main():
|
|
print("Welcome to My App!")
|
|
# Add login integration
|
|
if login("testuser", "password"):
|
|
print("Login successful!")
|
|
pass
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
"@
|
|
Set-Content -Path "app.py" -Value $appContent
|
|
|
|
git add .
|
|
git commit -m "Integrate login with main app" | Out-Null
|
|
|
|
# Switch back to main branch
|
|
Write-Host "Switching back to main branch..." -ForegroundColor Green
|
|
git switch main | Out-Null
|
|
|
|
# Make a commit on main (creates divergence)
|
|
Write-Host "Adding documentation on main (creates divergence)..." -ForegroundColor Green
|
|
$readmeContent = @"
|
|
# My Project
|
|
|
|
A simple web application project.
|
|
|
|
## Setup
|
|
|
|
1. Install Python 3.8 or higher
|
|
2. Run: python app.py
|
|
|
|
## Features
|
|
|
|
- User authentication (coming soon)
|
|
- Data management (coming soon)
|
|
|
|
## Contributing
|
|
|
|
Please follow our coding standards when contributing.
|
|
"@
|
|
Set-Content -Path "README.md" -Value $readmeContent
|
|
|
|
git add .
|
|
git commit -m "Update README with setup instructions" | Out-Null
|
|
|
|
# Return to module directory
|
|
Set-Location ..
|
|
|
|
Write-Host "`n=== Setup Complete! ===" -ForegroundColor Green
|
|
Write-Host "`nYour challenge environment is ready in the 'challenge/' directory." -ForegroundColor Cyan
|
|
Write-Host "`nScenario: You have two divergent branches!" -ForegroundColor Yellow
|
|
Write-Host " - main: Has updated documentation" -ForegroundColor White
|
|
Write-Host " - feature-login: Has new login functionality" -ForegroundColor White
|
|
Write-Host "`nNext steps:" -ForegroundColor Cyan
|
|
Write-Host " 1. cd challenge" -ForegroundColor White
|
|
Write-Host " 2. View the branch structure: git log --oneline --graph --all" -ForegroundColor White
|
|
Write-Host " 3. Merge feature-login into main: git merge feature-login" -ForegroundColor White
|
|
Write-Host " 4. View the merge result: git log --oneline --graph --all" -ForegroundColor White
|
|
Write-Host " 5. Run '..\verify.ps1' to check your solution" -ForegroundColor White
|
|
Write-Host ""
|